Skip to content

feat(parser): keep one BOM diagnostic per line where beancount reads a BOM into an account - #3065

Merged
robcohen merged 1 commit into
mainfrom
fix/bom-quiet-overlay
Nov 27, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/bom-quiet-overlay

Conversation

@robcohen

@robcohen robcohen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What

beancount's lexer reads a word holding a BOM, with a : in it, as an account. Its parser reports nothing on such a line. (Its builder's Invalid account name is a load-time error in rledger's terms, so the parity harness filters it out.) rledger reports the mid-file BOM (P0026) once per line, however many BOMs or accounts the line holds.

Until now that rule lived in convert.rs's hand-modeled quiet_after_invalid_tokens. This PR makes it a named deviation overlay, bom-in-account, documented in docs/reference/compatibility.md as P11. With the overlay in place, the pass can be deleted (a later PR in this stack).

  • New slot kind, SlotKind::StandIn. The overlay puts one on the first account the reference's parser reads (shifts, not discards) that holds a BOM, on a line the reference reports nothing on and does not recover over.
    • The reconciler fills a stand-in only with rledger's own diagnostic on its token. It never synthesizes one, and the line's other syntax diagnostics are dropped.
    • Stand-ins are no beancount errors, so overlaid_slots, which the drift check reads, leaves them out.
  • Tests: overlay unit tests (where a stand-in is placed and where it is not), a reconciler unit test (a stand-in is never synthesized), and an end-to-end one-error-per-line test.

Measurements (beancount 3.2.3)

  • Parity: 122,378 of 123,394 inputs match, unchanged.
    • One input that still mismatches loses an extra rledger error: impl:P0006+P0012 becomes impl:P0006, so that one category key is re-pinned.
    • No regressions.
  • Unchanged: the BOM combination matrix, STRICT_BASELINE and the parser suite all pass with no changes.
  • Other suites: workspace clippy with -D warnings is clean; the validate, loader, lsp, wasm and rustledger tests pass.

Caches

WASM cache v151. The loader cache is unchanged, since it is never saved for a source with a parse error.

Merge order

This is the first of five follow-up PRs, plus a perf fix. Merge order and cache numbers:

  1. perf(parser): keep the error oracle linear on many rebuilt entries #3069, the oracle perf fix: no cache bump. Merging it first stops the coverage-run timing flake.
  2. this PR (v151)
  3. refactor(parser): delete drop_errors_inside_a_line_error; the oracle names the invalid token #3067, delete drop_errors_inside_a_line_error (v152), stacked on this PR
  4. refactor(parser): place an error at a multi-line string in the reconciler #3068, report_at_multi_line_string_ends in the reconciler (v153)
  5. fix(validate): a transaction beancount's grammar discards moves no inventory #3066, casc3 (v154)
  6. refactor(parser): delete quiet_after_invalid_tokens #3070, delete quiet_after_invalid_tokens (v155), stacked on refactor(parser): delete drop_errors_inside_a_line_error; the oracle names the invalid token #3067

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner November 27, 2026 14:16
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 40.4ms ± 0.5ms 563.0ms ± 4.5ms 13.9x 43.1 MB / 51.0 MB
investment 62.2ms ± 0.4ms 2123.8ms ± 5.2ms 34.1x 47.1 MB / 59.0 MB
fifo 61.2ms ± 3.0ms 11730.1ms ± 55.6ms 191.5x 49.1 MB / 59.0 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 40.2ms ± 0.4ms 40.4ms ± 0.5ms +0.4% ✅ within noise 43.3 MB → 43.1 MB (-0.7%)
investment 61.7ms ± 0.7ms 62.2ms ± 0.4ms +0.7% ✅ within noise 47.2 MB → 47.1 MB (-0.4%)
fifo 59.5ms ± 0.4ms 61.2ms ± 3.0ms +3.0% ✅ within noise 49.2 MB → 49.1 MB (-0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.3ms, investment 0.4ms, fifo 1.4ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.32143% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../rustledger-parser/src/cst/oracle/beancount/mod.rs 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 828
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

…a BOM into an account

beancount's lexer reads a word holding a BOM, with a `:` in it, as an
account, so its parser reports nothing there (its `Invalid account name`
is a load-time error in rledger's terms). rledger reports the mid-file
BOM once per such line. That rule lived in convert.rs's
quiet_after_invalid_tokens; it is now a named deviation overlay,
`bom-in-account` (compatibility.md P11), so the pass can go.

The overlay keeps a stand-in slot (new SlotKind::StandIn) on the first
account the reference's parser reads holding a BOM, on a line it reports
nothing on and does not recover over. The reconciler fills a stand-in
only with rledger's own diagnostic on its token, never a synthesized
one, and the line's other syntax diagnostics go. Stand-ins are no
beancount errors, so the drift check's overlaid slots leave them out.

Parity: 122,378 of 123,394 inputs match, unchanged; one mismatching
input loses an extra error (a category key re-pinned). BOM matrix and
corpus baselines unchanged. WASM cache v151.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the fix/bom-quiet-overlay branch from 02c26cd to ab75364 Compare November 27, 2026 17:05
@robcohen
robcohen merged commit c9ee781 into main Nov 27, 2026
66 of 67 checks passed
@robcohen
robcohen deleted the fix/bom-quiet-overlay branch November 27, 2026 21:17
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.

1 participant