Repository navigation
refactor(core): Account domain newtype (refs #1163) - #1171
Merged
Merged
Conversation
Second slice of #1163 — wraps the account: InternedStr field on Open, Close, Balance, Pad (account + source_account), Note, Document, and Posting behind the existing Account newtype. Pattern matches the Currency slice in #1169: - AST field types switch to Account - HashMap/BTreeMap keys migrated in tandem to avoid hot-loop conversions (BookingEngine.inventories, BookingEngine.account_methods, LedgerState.accounts/inventories/pending_pads/late_close_processed, query executor balance maps, report builders) - Loader dedup pass uses account.as_interned_mut() to feed the workspace-wide interner without unwrapping the newtype - Constructors take impl Into<Account> so bare-string call sites continue to compile - BookingError, InterpolationError, CapitalGain, PadError, and AccountedBookingError carry Account instead of InternedStr What is deferred (next slices): - Tag migration (Transaction.tags, Document.tags, pushtag/poptag) - Link migration (Transaction.links, Document.links) - MetaValue::{Account, Currency, Tag, Link} still String — design decision deferred Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the domain-typed identifier refactor (refs #1163) by plumbing the Account newtype through the AST and hot-path data structures, replacing prior InternedStr-typed account fields/keys to make account-vs-currency mixups a compile-time error.
Changes:
- Migrates core directive/account-bearing AST fields (
Posting/Open/Close/Balance/Pad/Note/Document) fromInternedStrtoAccount, updating constructors accordingly. - Updates downstream booking/validation/query/reporting code to use
Accountin maps, errors, and processing logic (avoiding per-lookup conversions in hot paths). - Adjusts parser and loader dedup/reintern logic to produce and canonicalize
Accountwithout allocation.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger/src/cmd/report_cmd/income.rs | Switch income/expense aggregation maps to Account keys. |
| crates/rustledger/src/cmd/report_cmd/holdings.rs | Switch holdings map to Account keys. |
| crates/rustledger/src/cmd/report_cmd/balsheet.rs | Switch balance-sheet section maps to Account keys. |
| crates/rustledger/src/cmd/report_cmd/balances.rs | Switch balances report map to Account keys. |
| crates/rustledger/src/cmd/extract_cmd/suggest.rs | Update ML suggestion rewrite to assign Posting.account as Account. |
| crates/rustledger/src/cmd/doctor/missing_open.rs | Track opened/used accounts with Account in sets/maps. |
| crates/rustledger/src/cmd/doctor/directories.rs | Track discovered accounts with Account in a BTreeSet. |
| crates/rustledger-validate/src/validators/balance.rs | Update subaccount summation helper to use Account-keyed inventories. |
| crates/rustledger-validate/src/lib.rs | Migrate validator ledger state/pending pads/maps/sets to Account keys. |
| crates/rustledger-query/src/executor/mod.rs | Migrate executor balance maps and running per-account balances to Account. |
| crates/rustledger-parser/src/parser.rs | Make parse_account return Account instead of InternedStr. |
| crates/rustledger-loader/src/lib.rs | Update loader reintern test to validate Account sharing via underlying interned ptr equality. |
| crates/rustledger-loader/src/dedup.rs | Reintern directive pass now mutates Account via as_interned_mut() to dedup across files. |
| crates/rustledger-core/src/inventory/mod.rs | Update booking error context to carry Account (and with_account signature). |
| crates/rustledger-core/src/identifiers.rs | Update identifier module docs to reflect Account is now fully plumbed. |
| crates/rustledger-core/src/directive.rs | Convert directive structs’ account fields to Account; constructors now accept Into<Account>. |
| crates/rustledger-booking/src/pad.rs | Use Account-keyed inventories/pending pad maps and PadError.account: Option<Account>. |
| crates/rustledger-booking/src/interpolate.rs | Update interpolation error variant to store Account for better typed context. |
| crates/rustledger-booking/src/book.rs | Migrate booking engine inventories/account-method maps and gain/error context to Account. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-05-20)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Addresses Copilot review on #1171. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second slice of #1163. After #1169 plumbed `Currency`, this PR does the same for `Account` — the 8 `account: InternedStr` fields on Open / Close / Balance / Pad / Note / Document / Posting now use the typed newtype.
What changed
AST field types (rustledger-core/src/directive.rs):
All now `crate::Account` instead of `InternedStr`. Constructors take `impl Into` so bare-string call sites continue to compile.
Hot maps migrated in tandem to avoid per-lookup conversions:
Error types that previously carried bare `InternedStr`:
Parser (one-line change): `parse_account` returns `Account` instead of `InternedStr`. Everything downstream just compiles.
Loader dedup pass uses `account.as_interned_mut()` to feed the workspace-wide interner without unwrapping the newtype. No allocation, same dedup behaviour.
Why
The compiler can now distinguish accounts from currencies, tags, and arbitrary interned strings at the type level — passing a `Currency` where an `Account` is expected (or vice versa) is now a type error, not a runtime bug.
Performance
What's deferred
Test plan
🤖 Generated with Claude Code