Repository navigation
refactor(query): single-source source-location columns; fix unchecked lineno cast (BR8 step 2) - #1556
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR refactors rustledger-query’s executor to single-source the synthetic source-location columns (filename, lineno, location) and fixes an unchecked usize -> i64 cast that could wrap to a negative line number on overflow.
Changes:
- Added shared helpers on
Executorfor computingfilename/lineno/locationcolumnValues, with overflow-checkedlinenoconversion. - Routed
#postingstable construction and posting-function column evaluation through the shared helpers (removing duplicated logic). - Added unit tests covering basic behavior,
Nonehandling, and 64-bit overflow saturation forlineno.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger-query/src/executor/system_tables.rs | Routes synthetic source-location columns in #entries/#postings through shared helpers. |
| crates/rustledger-query/src/executor/functions/util.rs | Introduces shared source_*_value helpers and adds unit tests (including overflow saturation for lineno). |
| crates/rustledger-query/src/executor/evaluation.rs | Routes filename/lineno/location posting-function arms through the shared helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Benchmark Results
vs main branch (2026-06-23)
What do these numbers mean?
|
|
Good catch — fixed: extracted |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…cked lineno cast (BR8 step 2) The filename/lineno/location synthetic columns were built ~3 ways, two using an unchecked loc.lineno as i64 cast (lineno is usize) -- bug #4. Add three shared helpers (source_filename_value/source_lineno_value/source_location_value) next to source_location_meta_key; source_lineno_value is the single overflow-checked conversion (try_from, saturating to i64::MAX). Route the evaluation.rs posting functions and the system_tables.rs standalone pair + #postings tuple through them. Behavior unchanged for real ledgers; the pathological overflow now saturates instead of wrapping negative. Adds unit tests pinning the saturation.
…he lineno column Copilot: source_location_value formatted the raw usize while source_lineno_value saturates to i64::MAX, so on overflow location could disagree with the lineno column. Extract lineno_i64 (the saturating conversion) and use it for both.
0459d6f to
2c8eab6
Compare
What
Architecture-roadmap [XL/BR8] — step 2 of the PostingContext-stream unification. Single-sources the source-location column leaf (
filename/lineno/location), and fixes bug #4 along the way.These three synthetic columns were built in ~3 places, two of which used an unchecked
loc.lineno as i64cast (linenoisusize) — bug #4: on a hypothetical line number exceedingi64, the cast wraps to a negativelineno. The META path already guarded this (source_location_meta_keyusestry_from); the column paths did not.How
Adds three shared helpers next to the existing
source_location_meta_key:source_filename_value,source_lineno_value,source_location_value— eachOption<&SourceLocation> -> Value.source_lineno_valueis the single overflow-checked conversion (i64::try_from(...).unwrap_or(i64::MAX)), replacing everyas i64cast.Routes all column sites through them:
executor/evaluation.rs— thefilename/lineno/locationposting-function armsexecutor/system_tables.rs— the standalonefilename/linenopair and the(filename, lineno, location)#postingstupleBehavior is unchanged for every real ledger (linenos fit in
i64); only the pathological overflow now saturates instead of wrapping.Tests
Added unit tests:
source_lineno_valuesaturatesusize::MAXtoi64::MAXon 64-bit (bug #4 pin), basic lineno/filename/location values, andNonehandling. Fullrustledger-querysuite passes; clippy--all-features --all-targets -D warnings+ fmt clean.Follow-up (step 3): fold these leaves + the cost-resolve (step 1, #1555) into one posting-source iterator consumed by
build_postings_table,build_balances_with_filter, and aggregation.🤖 Generated with Claude Code