What happens
Every length-contract panic in lance-linalg's distance module reports the same source location, rust/lance-linalg/src/distance.rs:31, because that is where the shared assert_equal_lengths helper lives:
#[inline]
fn assert_equal_lengths(left_len: usize, right_len: usize) {
assert_eq!(
left_len, right_len,
"distance inputs must have equal lengths: left={left_len}, right={right_len}"
);
}
It has 16 call sites, across l2.rs, dot.rs, dot_u8.rs, and l2_u8.rs. assert_batch_layout next to it has 4 more and the same property.
So a release-mode panic tells the reader the two lengths, which is genuinely useful, but not which metric raised it. Without RUST_BACKTRACE there is nothing in the output that distinguishes a dot_u8 call from an l2_batch one.
Why it is not just cosmetic
These asserts are the always-on kind, promoted from debug_assert! in #8593, #8594, and #8639 precisely so they fire in the profile that ships. They are the diagnostic a user gets when a dimension mismatch reaches a distance kernel, and a panic that names a shared helper sends the reader to a file that has nothing to do with their query.
Suggested fix
Add #[track_caller] to both helpers. That moves the reported location one frame out, to the distance function that was called, at no cost on the success path. Going further, to the user's own call site, would mean putting the attribute on every public distance function, which is a much larger change and can inhibit inlining, so it is not worth doing for this.
The behaviour is testable: install a panic hook, capture PanicHookInfo::location(), and assert the file is the distance function rather than distance.rs. That has to live in an integration test binary, because replacing the global hook races with any other test that panics in the same process, and lance-linalg currently has no tests/ directory.
What happens
Every length-contract panic in
lance-linalg's distance module reports the same source location,rust/lance-linalg/src/distance.rs:31, because that is where the sharedassert_equal_lengthshelper lives:It has 16 call sites, across
l2.rs,dot.rs,dot_u8.rs, andl2_u8.rs.assert_batch_layoutnext to it has 4 more and the same property.So a release-mode panic tells the reader the two lengths, which is genuinely useful, but not which metric raised it. Without
RUST_BACKTRACEthere is nothing in the output that distinguishes adot_u8call from anl2_batchone.Why it is not just cosmetic
These asserts are the always-on kind, promoted from
debug_assert!in #8593, #8594, and #8639 precisely so they fire in the profile that ships. They are the diagnostic a user gets when a dimension mismatch reaches a distance kernel, and a panic that names a shared helper sends the reader to a file that has nothing to do with their query.Suggested fix
Add
#[track_caller]to both helpers. That moves the reported location one frame out, to the distance function that was called, at no cost on the success path. Going further, to the user's own call site, would mean putting the attribute on every public distance function, which is a much larger change and can inhibit inlining, so it is not worth doing for this.The behaviour is testable: install a panic hook, capture
PanicHookInfo::location(), and assert the file is the distance function rather thandistance.rs. That has to live in an integration test binary, because replacing the global hook races with any other test that panics in the same process, andlance-linalgcurrently has notests/directory.