Skip to content

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

Open
connortsui20 wants to merge 1 commit into
developfrom
claude/collapse-checked-arith-macros
Open

Collapse the checked-arithmetic macros into one integer body#9248
connortsui20 wants to merge 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

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 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
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