Skip to content

refactor(query): route all directive walks through resolved_directives - #1535

Merged
robcohen merged 2 commits into
mainfrom
refactor/executor-source-selection
Jun 23, 2026
Merged

robcohen merged 2 commits into
mainfrom
refactor/executor-source-selection

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

Architecture-roadmap item [M/BR5]. The executor walked directives via ~10 copy-pasted if let Some(spanned) = self.spanned_directives { … } else { self.directives … } blocks — the exact pattern that produced the JOURNAL regression (#1531): a directive-walking site forgetting the spanned_directives fallback returns empty under new_with_sources (CLI/LSP). #1531 fixed JOURNAL/SELECT/PRINT with the resolved_directives() accessor; this PR collapses the remaining copies onto it.

How

Routed the 9 remaining sites through Executor::resolved_directives():

  • the 5 system-table builders (#balances, #commodities, #events, #notes, #documents)
  • the #accounts builder, the two transaction collectors, and the #entries row walk

The #entries walk previously passed get_source_location(idx) on the spanned branch and None on the unspanned branch — get_source_location already returns None when there's no source map, so the single loop is behavior-identical.

resolved_directives() now returns impl Iterator<Item = &'a Directive> (the directive slices are themselves &'a and Copy, so the iterator carries the data lifetime and can be collect()ed into Vec<&'a …>, not just iterated).

Tests

Behavior-preserving — the full rustledger-query suite passes unchanged. Added test_system_table_via_source_mapped_executor: runs BALANCES over a new_with_sources executor and asserts it isn't empty, directly guarding the collapsed builders against the JOURNAL bug class.

Verification: query suite green; clippy --all-features --all-targets -D warnings + fmt clean.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 23, 2026 02:30
@robcohen
robcohen requested a review from a team as a code owner June 23, 2026 02:30
@codecov

codecov Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-query/src/executor/mod.rs 97.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 23.2ms ± 0.5ms 24 MB
beancount 419.1ms ± 12.5ms 50.6 MB
Comparison 18.1x faster 2.1x less

vs main branch (2026-06-22)

Metric main this PR Change
Time 34.9ms 23.2ms -33.5% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

Copilot AI 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.

Pull request overview

Refactors rustledger-query’s Executor to ensure all directive iteration paths consistently use Executor::resolved_directives(), preventing regressions under new_with_sources where directives is intentionally empty and data lives in spanned_directives.

Changes:

  • Updated resolved_directives() to return an iterator of &'a Directive, enabling callers to collect() references without tying them to the &self borrow.
  • Routed remaining directive-walking sites (system-table builders, transaction collectors, and #entries walk) through resolved_directives() to eliminate duplicated fallback logic.
  • Added a regression test intended to guard system-table/directive-walk behavior under new_with_sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

The executor had ~10 copy-pasted spanned/unspanned dispatch blocks — the pattern
that caused the JOURNAL regression (a walk forgetting the spanned_directives
fallback returns empty under new_with_sources). #1531 fixed 3; collapse the rest
(5 system-table builders, #accounts, 2 transaction collectors, #entries) onto
resolved_directives, which now yields &\x27a Directive so callers can collect.
Add a source-mapped system-table test. Architecture-roadmap item [M/BR5].

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen force-pushed the refactor/executor-source-selection branch from cc36625 to 307be8d Compare June 23, 2026 02:37
Copilot on #1535: BALANCES is a statement on a different path; query #entries (a
system-table builder collapsed onto resolved_directives in this PR) so the test
actually guards the refactored builders under new_with_sources.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen merged commit 64184c2 into main Jun 23, 2026
50 checks passed
@robcohen
robcohen deleted the refactor/executor-source-selection branch June 23, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants