Skip to content

Collapse the checked-arithmetic macros into one integer body - #9248

Merged
connortsui20 merged 1 commit into
developfrom
claude/collapse-checked-arith-macros
Aug 7, 2026
Merged

Collapse the checked-arithmetic macros into one integer body#9248
connortsui20 merged 1 commit into
developfrom
claude/collapse-checked-arith-macros

Conversation

@connortsui20

@connortsui20 connortsui20 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Follow-up to #9210. The four CheckedArithmetic macro arms are near-identical copies of the same ~55-line impl, and only mul_failure varies between them, so that becomes the parameter of one impl_checked_integer!. Both overflowing_mul arms existed only to specialize the 64-bit widths and fold into the general form, and deriving the shift from $ty retires the const { assert!(<$ty>::BITS == 64) } that guarded the hardcoded >> 64. Pure refactor, no API change: the expanded impls differ from the previous ones only by an alpha-rename of self to lhs, and the optimized IR of the checked kernels is identical.

Refactor evidence and checks

Expanded impls compared per type with cargo +nightly rustc --lib -- -Zunpretty=expanded at both revisions. Optimized LLVM IR at -C target-cpu=x86-64-v3, comparing every define touching the checked kernels by vector width, reduction count, and overflow intrinsics:

102 distinct kernel profiles, identical at both revisions
umul.with.overflow: 309 before, 309 after
smul.with.overflow: 109 before, 109 after
cargo test -p vortex-array                                  # 3354 passed, 0 failed
cargo clippy -p vortex-array --all-targets --all-features
cargo +nightly fmt -p vortex-array -- --check

connortsui20 added a commit that referenced this pull request Aug 6, 2026
…ngs (#9245)

Progress towards #9128. Cleanup from a review of the `RowFn` API, the
execution logic, and the scalar function implementations: deletes the
`InputElement::decode_null_tolerant` overrides that only restated the
default, shares `resolve_validity` between `execute_filtered` and the
forced-strategy test seam, corrects the dense-retry comment,
de-duplicates `l2_norm_row` into `vortex-tensor/src/utils.rs`, drops the
now-callerless `map_checked_into`, and pins `geo` to `=0.31.0` because
`contains_route` transcribes its `impl_contains_from_relate!` dispatch
table and a patch can reshuffle that with no API change. The
author-facing API is unchanged: every proposal that would have altered
it was backed out, and `SCALAR_FN_HANDOFF.md` records which ones and
why.

The checked-arithmetic macro collapse this review also found is #9248
against `develop` instead, since `develop` carries the same duplication.

<details>
<summary>Checks</summary>

```
cargo test  -p vortex-array -p vortex-compute -p vortex-geo -p vortex-tensor   # 3838 passed, 0 failed
cargo clippy -p vortex-array -p vortex-compute -p vortex-geo -p vortex-tensor --all-targets --all-features
cargo +nightly fmt --all -- --check
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p vortex-array -p vortex-compute -p vortex-geo -p vortex-tensor
```

The optimized IR of every `visit_prepared_into` monomorph is unchanged
from the pre-review commit. Runtime benchmarks were not usable as a gate
on this host, where repeated pinned runs of the same binary disagreed by
up to 4x.
</details>

Signed-off-by: Connor Tsui <connor@spiraldb.com>
Co-authored-by: Claude <noreply@anthropic.com>
@connortsui20
connortsui20 enabled auto-merge (squash) August 6, 2026 20:38
@connortsui20 connortsui20 added changelog/chore A trivial change and removed changelog/chore A trivial change labels Aug 7, 2026
The four `CheckedArithmetic` macro arms were near-identical copies of the
same ~55-line trait impl. Only `mul_failure` genuinely varies per width, so
that is now the parameter of a single `impl_checked_integer!` and everything
else is written once.

The `overflowing_mul` arms existed only to specialize the 64-bit widths, and
both fold into the general form: `impl_checked_unsigned!(u64, widening_mul:
u128)` produces the same body the u64 arm spelled out, and `high_half_mul`
generalizes the signed one. Deriving the shift from `$ty` also retires the
`const { assert!(<$ty>::BITS == 64) }` that guarded the hardcoded `>> 64`,
so instantiating a width cannot silently keep another width's constants.

Pure refactor. The expanded impls differ from the previous ones only by an
alpha-rename of `self` to `lhs`, and the optimized LLVM IR of the checked
kernels at `-C target-cpu=x86-64-v3` is identical: same vector widths, same
reduction counts, and the same 309 `umul.with.overflow` / 109
`smul.with.overflow` sites crate-wide.

Also fixes a stale doc reference to `tests::test_i64_multiply_overflow_boundaries`,
which is named `test_multiply_overflow_boundaries`.

Signed-off-by: Connor Tsui <connor@spiraldb.com>
@connortsui20
connortsui20 force-pushed the claude/collapse-checked-arith-macros branch from 7c0fc40 to 50e9c1d Compare August 7, 2026 14:59
@codspeed-hq

codspeed-hq Bot commented Aug 7, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 82.5%

⚡ 1 improved benchmark
✅ 1933 untouched benchmarks
⏩ 51 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation decompress[u64, (1000, 16)] 134.9 µs 73.9 µs +82.5%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/collapse-checked-arith-macros (50e9c1d) with develop (0f0390a)2

Open in CodSpeed

Footnotes

  1. 51 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on develop (74a2b86) during the generation of this report, so 0f0390a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@connortsui20
connortsui20 merged commit ad5de22 into develop Aug 7, 2026
102 of 103 checks passed
@connortsui20
connortsui20 deleted the claude/collapse-checked-arith-macros branch August 7, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants