Repository navigation
refactor(core): MetaValue::{Account,Currency,Tag,Link} typed (closes #1163) - #1174
Merged
Merged
Conversation
…1163) Final slice of #1163. Migrates the four typed MetaValue variants from String to the corresponding domain newtypes, matching the typing already in place on the rest of the AST. Changes: - core: MetaValue::{Account,Currency,Tag,Link} carry their respective newtypes - parser: drop .to_string() at MetaValue construction sites; also align parse_currency and parse_link to return their newtypes (parse_account and parse_tag already returned newtypes), then delete the no-longer-needed .into() bridges at downstream construction sites - with_link constructors take impl Into<Link> (already done for with_tag in #1172; this catches the missed half) - plugin convert layer: from_wrapper re-interns from String into the workspace interner via the newtype From<&str> impl; to_wrapper lowers via Display. MetaValueData itself stays String-typed — plugin-types is intentionally minimal and does not depend on rustledger-core (the host re-interns at the convert boundary). - ffi-wasi: typed variants lowered via Display at the JSON boundary - query: typed variants lowered to BQL Value::String at the SQL boundary (matches bean-query semantics; no first-class typed values in the SQL surface) - discovery: or-pattern split — MetaValue::String(s) | Currency(s) bound s to two different types; now separate arms #1163 is fully closed for the AST layer. The MetaValue typing was the last asymmetry: every identifier kind in the AST (including inside metadata) now has a compiler-enforced type. 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 completes the #1163 AST typing effort by migrating the remaining MetaValue::{Account,Currency,Tag,Link} variants from String payloads to the corresponding domain newtypes, and updates parser + boundary layers (query, plugin convert, FFI, CLI) to construct/lower these typed variants appropriately.
Changes:
- Refactors
rustledger-core::MetaValue::{Account,Currency,Tag,Link}to carry domain newtypes instead ofString. - Updates the parser to return/propagate typed
Currency/Link(and to stop redundant.to_string()/.into()conversions at construction sites). - Updates plugin/query/FFI/CLI lowering paths to convert typed meta values back to
Stringat their respective boundaries.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-core/src/directive.rs | Changes MetaValue typed variants to store Account/Currency/Tag/Link newtypes. |
| crates/rustledger-parser/src/parser.rs | Makes parse_currency return Currency and updates meta/custom/open construction sites accordingly. |
| crates/rustledger-core/src/identifiers.rs | Updates docs to reflect typed MetaValue coverage and plugin boundary story. |
| crates/rustledger-plugin/src/convert/from_wrapper.rs | Converts string-typed plugin wire values into typed MetaValue variants. |
| crates/rustledger-plugin/src/convert/to_wrapper.rs | Lowers typed MetaValue variants back to string-typed MetaValueData. |
| crates/rustledger-query/src/executor/functions/util.rs | Lowers typed MetaValue variants to BQL Value::String at query boundary. |
| crates/rustledger-ffi-wasi/src/types/output.rs | Lowers typed MetaValue variants to JSON strings at FFI boundary. |
| crates/rustledger/src/cmd/price/discovery.rs | Fixes matching/lowering of MetaValue::Currency in metadata parsing helpers. |
| crates/rustledger-core/src/format/helpers.rs | Updates formatting helpers to render typed Account/Currency via Display. |
| crates/rustledger-core/src/format/mod.rs | Updates format tests to construct typed MetaValue variants via .into(). |
| crates/rustledger-core/src/extract.rs | Updates extract tests to construct typed MetaValue::Currency via .into(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-05-21)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…orrect docs Addresses Copilot review on #1174. Two related findings: 1. The convert-boundary docstring claimed `From<&str>` re-interns into the workspace interner. That was wrong: `InternedStr::from(&str)` just wraps the string in a fresh `Arc<str>`. The actual dedup happens later via `StringInterner::intern` in the loader pass. 2. The dedup pass (`reintern_directives`) walked every AST identifier field but never touched `Metadata` maps — so cross-file (and plugin-emitted) MetaValue::{Account, Currency, Tag, Link, Amount} payloads silently retained distinct `Arc<str>` allocations even when they referenced identical strings. Changes: - Add `intern_meta` helper in `rustledger-loader::dedup` that walks every `MetaValue` payload type containing an interned string (Account, Currency, Tag, Link, and the currency on Amount) and re-interns through the shared workspace interner. - Call `intern_meta` for the `meta` field on every directive variant (Transaction, Balance, Open, Close, Commodity, Pad, Note, Document, Price, Event, Query, Custom) AND on every posting (transactions carry posting-level meta separately). - Rewrite the docstrings on both `from_wrapper.rs` and `identifiers.rs` to accurately describe where dedup happens: at the loader pass, not at the convert boundary or the From impl. - Add `test_fresh_parse_deduplicates_metavalue_across_files` regression test pinning that two cross-file Transactions with identical `counterparty: Assets:Bank` meta land on a single shared `Arc<str>`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Three of four review-followup items addressed: 1. **CACHE_VERSION bump 5 → 6**: the #1163 newtype slices (Currency/ Account/Tag/Link/MetaValue) changed rkyv archive wrappers for the typed variants. Bumping the version short-circuits old cache files at the header check instead of risking rkyv reading old bytes into a structurally-different ArchivedMetaValue. Same pattern as the v5 bump for the Spanned<Posting> change in #1151. 2. **Regression test variant coverage**: the original Copilot-driven regression test only exercised MetaValue::Account. Expanded to cover all five interned-payload variants (Account, Currency, Tag, Link, Amount.currency) in a single multi-file fixture. 3. **Posting-level meta dedup test**: added a per-posting MetaValue::Account assertion to verify the per-posting intern_meta call (not just the directive-level one). Catches silent regressions if someone removes the per-posting call later. The fourth item (recovering ) is not achievable: Arc::deref is not const in stable Rust, so neither InternedStr::as_str nor by extension Currency::as_str can be const. Added an inline comment explaining the constraint. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
enabled auto-merge (squash)
May 21, 2026 04:41
3 of 4 tasks
robcohen
added a commit
that referenced
this pull request
May 21, 2026
PriceAnnotation was a 6-variant enum flattening two orthogonal axes:
- kind (Unit `@` vs Total `@@`)
- completeness (Complete amount / IncompleteAmount / no amount)
Refactor into:
pub enum PriceKind { Unit, Total }
pub struct PriceAnnotation {
pub kind: PriceKind,
pub amount: Option<IncompleteAmount>,
}
The five non-empty old variants collapse to (kind, Some(amount));
the two empty variants collapse to (kind, None).
Wins:
- 6-arm match boilerplate at 20+ consumers collapses to one match
on `amount` and/or one check on `kind`. Most sites lose 15-30
lines each (booking residual logic, validator tolerances, LSP
currency extraction, query BQL price accessor, plugin convert,
wasm convert, loader dedup).
- The orthogonal axes become orthogonal in the code.
- `is_unit()` / `amount()` helpers become trivial field accesses.
New constructors (`PriceAnnotation::unit`/`total` for complete,
`unit_incomplete`/`total_incomplete`, `unit_empty`/`total_empty`)
preserve the readability of the old variant names at construction
sites — only match arms had to change shape.
New shared helper in booking: `price_residual_contribution` factors
the (kind=Unit vs kind=Total) signed-amount math so it lives in
one place instead of duplicated across the precise and non-precise
residual calculators.
CACHE_VERSION bumps 5 to 6: the PriceAnnotation archive layout
changed (enum discriminants vs struct fields), so old caches would
rkyv-deserialize as nonsense. Same precedent as #1151 / #1174.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
added a commit
that referenced
this pull request
May 21, 2026
…#1176) PriceAnnotation was a 6-variant enum flattening two orthogonal axes: - kind (Unit `@` vs Total `@@`) - completeness (Complete amount / IncompleteAmount / no amount) Refactor into: pub enum PriceKind { Unit, Total } pub struct PriceAnnotation { pub kind: PriceKind, pub amount: Option<IncompleteAmount>, } The five non-empty old variants collapse to (kind, Some(amount)); the two empty variants collapse to (kind, None). Wins: - 6-arm match boilerplate at 20+ consumers collapses to one match on `amount` and/or one check on `kind`. Most sites lose 15-30 lines each (booking residual logic, validator tolerances, LSP currency extraction, query BQL price accessor, plugin convert, wasm convert, loader dedup). - The orthogonal axes become orthogonal in the code. - `is_unit()` / `amount()` helpers become trivial field accesses. New constructors (`PriceAnnotation::unit`/`total` for complete, `unit_incomplete`/`total_incomplete`, `unit_empty`/`total_empty`) preserve the readability of the old variant names at construction sites — only match arms had to change shape. New shared helper in booking: `price_residual_contribution` factors the (kind=Unit vs kind=Total) signed-amount math so it lives in one place instead of duplicated across the precise and non-precise residual calculators. CACHE_VERSION bumps 5 to 6: the PriceAnnotation archive layout changed (enum discriminants vs struct fields), so old caches would rkyv-deserialize as nonsense. Same precedent as #1151 / #1174. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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
Final slice of #1163. Migrates the four typed `MetaValue` variants from `String` to the corresponding domain newtypes, matching the typing already in place on the rest of the AST.
This closes #1163 for the AST layer. Every identifier kind in the AST — including inside metadata — now has a compiler-enforced type.
What changed
Core enum (`rustledger-core/src/directive.rs`):
Parser (`rustledger-parser/src/parser.rs`):
Core constructors:
Plugin convert layer:
FFI / Query / CLI:
Wire-format compatibility
#1163 status after this PR
The architectural goal of #1163 — compiler distinguishes the four identifier kinds at every AST position, including metadata — is now fully met.
Test plan
🤖 Generated with Claude Code