Repository navigation
refactor(query): route posting cost-resolve through Position::from_posting (BR8 step 1) - #1555
Conversation
…sting (BR8 step 1) The cost-resolve idiom (cost_spec.resolve -> with_cost else simple, plus the no-cost guard) was hand-written at 5 Position-building sites in the query executor. Route them all through the canonical rustledger_core::Position::from_posting (build_balances_with_filter + resolve_position closure in mod.rs, the #postings running balance + position column in system_tables.rs, the position function in evaluation.rs). Byte-for-byte equivalent, so query results are unchanged; removes the convention-only must-match invariant. First slice of the PostingContext-stream unification.
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
Refactors rustledger-query’s executor to single-source posting cost→Position resolution by routing several inlined CostSpec::resolve blocks through rustledger_core::Position::from_posting, reducing duplication and the risk of cost-handling drift across query result paths.
Changes:
- Replaced multiple hand-rolled “resolve cost spec → build
Position” blocks withPosition::from_posting(...)in query execution paths. - Updated the shared
resolve_positionclosure used for running-balance computations to delegate toPosition::from_posting. - Adjusted nearby explanatory comments to reflect the new single-source approach.
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/mod.rs | Uses Position::from_posting for BALANCES accumulation and for the shared resolve_position closure used by running balance/account_balance state. |
| crates/rustledger-query/src/executor/system_tables.rs | Uses Position::from_posting for #postings running balances and the position column value. |
| crates/rustledger-query/src/executor/evaluation.rs | Uses Position::from_posting for the position column evaluation in expression evaluation. |
💡 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?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…sition::from_posting Copilot: execution.rs still had an inlined cost_spec.resolve -> with_cost/simple for the JOURNAL running balance/position; route it too so all Position-building cost-resolves in the executor share one path.
|
Good catch — fixed rather than reworded: routed the JOURNAL running-balance/position cost-resolve in |
What
Architecture-roadmap [XL/BR8] — step 1 of unifying the four copies of "iterate postings, resolve cost→Position, accumulate Inventory, derive columns" onto one stream. This first slice single-sources the cost-resolve leaf, the most-duplicated piece.
The idiom
if cost_spec.resolve(units, date) { Position::with_cost } else { Position::simple }(also guarding the no-cost case) was hand-written at 5 Position-building sites across the query executor. The canonical version already exists asrustledger_core::Position::from_posting(extracted in the L/7 work) — these sites just hadn't been routed through it.How
Routes all 6 query-executor Position-building cost-resolves through
Position::from_posting(units, posting.cost.as_ref(), date):executor/mod.rs—build_balances_with_filteraccumulator + theresolve_positionclosure (runningbalance/account_balance)executor/system_tables.rs—#postingsrunning-balancepos+ thepositioncolumnexecutor/evaluation.rs— thepositionposting-functionPosition::from_postingis byte-for-byte equivalent to each replaced block (cs.resolve(...)→with_cost, elsesimple; outerNone→simple), so query results are unchanged. The cost-field-extraction at system_tables (which reads the resolved cost's number/currency/date/label) and the units×cost weight in mod.rs are different idioms and are left alone.Why
Removes the "running balance / account_balance need to match so lot details aren't dropped" convention-only invariant (its comment is replaced by the shared call). A future
CostNumbervariant or cost-resolve fix now lands in one place.Tests
Full
rustledger-querysuite passes (these are result-producing paths); clippy--all-features --all-targets -D warnings+ fmt clean. Follow-ups: the source-location-columns leaf (fixes bug #4's uncheckedas i64), then the unified posting iterator.🤖 Generated with Claude Code