Skip to content

fix(linalg): point length-contract panics at the distance function - #8864

Open
LuciferYang wants to merge 1 commit into
lance-format:mainfrom
LuciferYang:fix/track-caller-length-asserts
Open

fix(linalg): point length-contract panics at the distance function#8864
LuciferYang wants to merge 1 commit into
lance-format:mainfrom
LuciferYang:fix/track-caller-length-asserts

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

What this changes

assert_equal_lengths and assert_batch_layout in rust/lance-linalg/src/distance.rs get #[track_caller], so a length-contract panic reports the distance function that was called instead of the helper. Closes #8863.

Before, every such panic reported distance.rs:31. That helper has 16 call sites across l2.rs, dot.rs, dot_u8.rs and l2_u8.rs, and assert_batch_layout has 4 more, so the panic told you the two lengths but not which metric raised them. These are the always-on asserts promoted in #8593, #8594 and #8639 precisely so they fire in release, which is where a backtrace is least likely to be available.

The attribute moves the location one frame out, to the distance function. Going further, to the user's own call site, would mean putting it on every public distance function, so I left that alone.

Test plan

rust/lance-linalg/tests/panic_location.rs is new. It captures the panic location and message through a hook and asserts, for dot_u8 and for l2_distance_batch, that the file is dot_u8.rs and l2.rs rather than distance.rs, and that the message is the length-contract one rather than any other panic in the same file. It has to be an integration binary rather than a unit test, because replacing the global hook races with any other test that panics in the same process, and distance/dot_f16.rs already swaps the hook inside the lib test binary.

Measured, one attribute at a time, since each is independently load-bearing:

  • removing it from assert_equal_lengths: expected dot_u8.rs, got rust/lance-linalg/src/distance.rs:34

  • removing it from assert_batch_layout: expected l2.rs, got rust/lance-linalg/src/distance.rs:52

  • cargo test -p lance-linalg: 389 passed and 1 ignored in the lib, 1 passed in the new binary

  • cargo fmt --all -- --check and cargo clippy -p lance-linalg --all-targets -- -D warnings: clean

Two limits worth stating. The location moves one frame, to the distance function, not to the caller's own line: for the batch path that is the trait-impl override body in l2.rs, not the l2_distance_batch the caller wrote. Reaching the caller would mean putting the attribute on every public wrapper and trait method, and rustc's MIR inliner declines #[track_caller] callees, so that is a separate cost to weigh. And because the new tests/ directory is the crate's first, --tests now builds an integration target where it previously resolved to the lib alone; qemu-pre-haswell passes --lib and so will not run this test, which is correct, since that job exists to catch AVX2 leaking into the x86-64-v2 baseline and panic locations are not SIMD-dependent.

Scope note: these two helpers are called from the l2 and dot families only. cosine asserts its length contract inline with debug_assert_eq! and hamming has no production length assert, so neither is covered here.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer bug Something isn't working labels Aug 29, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026
@LuciferYang
LuciferYang force-pushed the fix/track-caller-length-asserts branch from f5ed9a7 to 17d1f73 Compare August 29, 2026 15:18
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026
@LuciferYang
LuciferYang force-pushed the fix/track-caller-length-asserts branch from 17d1f73 to 8ba6428 Compare August 29, 2026 16:18
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026
@LuciferYang
LuciferYang force-pushed the fix/track-caller-length-asserts branch from 8ba6428 to e5b2b4f Compare August 29, 2026 16:28
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate recommendation: approve.

The revision accurately narrows the documented scope to the l2 and dot families and makes the regression’s panic-payload expectation explicit. Both helpers remain covered centrally without changing accepted inputs, panic messages, or public APIs.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: length-contract panics in lance-linalg name the shared helper, not the caller

1 participant