Skip to content

refactor(core): Link domain newtype (refs #1163 — AST complete) - #1173

Merged
robcohen merged 1 commit into
mainfrom
feat/link-newtype
May 21, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/link-newtype

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

Fourth and final newtype slice for #1163. Wraps the `links: Vec` fields on `Transaction` and `Document` behind the existing `Link` newtype.

Issue #1163 AST coverage is now complete (Currency in #1169, Account in #1171, Tag in #1172, Link here). The remaining `MetaValue::{Account, Currency, Tag, Link}` String variants are a separate design call and stay deferred.

What changed

AST fields:

  • `Transaction.links: Veccrate::Link` (was `Vec`)
  • `Document.links: Veccrate::Link`
  • `with_link` constructors take `impl Into`

Parser:

  • `parse_link` returns `Link` (was `InternedStr`)

Loader dedup:

  • `intern_typed_vec(&mut txn.links, ..., Link::as_interned_mut)` for both Transaction and Document link slices
  • Dropped the now-unused `intern_vec` helper — all four `Vec` fields it served (tags, links on Transaction and Document) now go through the typed variant
  • Renamed and re-documented the surviving `intern_typed_vec` helper to mention all four newtypes

Cleanup:

  • Removed the unused `AsVecInternedStr` import from `directive.rs` (no remaining `Vec` field needs the rkyv wrapper)

Performance

  • `Link` is `#[repr(transparent)]` over `InternedStr`; `Hash` / `Eq` delegate
  • Loader dedup still hits the `Arc::ptr_eq` fast path via `as_interned_mut()`
  • No new allocations

#1163 status after this PR

Newtype Status
Currency ✅ #1169
Account ✅ #1171
Tag ✅ #1172
Link ✅ this PR
`MetaValue::*` String variants deferred — separate design

The architectural goal of #1163 (compiler distinguishes the four identifier kinds at AST positions) is now met.

Test plan

  • `cargo check --workspace --all-features --all-targets` — clean
  • `cargo clippy --workspace --all-features --all-targets -- -D warnings` — clean
  • `cargo test -p rustledger-core -p rustledger-parser -p rustledger-loader -p rustledger-validate --all-features` — pass
  • CI full workspace + compat suite

🤖 Generated with Claude Code

Fourth and final newtype slice. Wraps Transaction.links and
Document.links behind the Link newtype — same shape as the Tag
migration in #1172.

Changes:
- AST: Transaction.links and Document.links switch to Vec<Link>
- with_link constructors take impl Into<Link>
- Parser parse_link returns Link
- Loader dedup pass uses intern_typed_vec(Link::as_interned_mut)
- Dropped the now-unused intern_vec helper (all four Vec<InternedStr>
  fields are typed); intern_typed_vec docs updated to cover all four
  newtypes
- Dropped the now-unused AsVecInternedStr import

Issue #1163 AST coverage is now complete (Currency/Account/Tag/Link).
MetaValue::{Account,Currency,Tag,Link} variants still carry String —
that crossing-the-typed-boundary question is a separate decision and
remains deferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner May 21, 2026 03:05
Copilot AI review requested due to automatic review settings May 21, 2026 03:05
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Completes issue #1163’s AST newtype migration by wiring the existing Link domain newtype through the core AST, parser, and loader dedup pass so link identifiers are type-distinguished from other interned strings.

Changes:

  • Core AST: Transaction.links and Document.links migrated from Vec<InternedStr> to Vec<Link>, and with_link constructors now accept impl Into<Link>.
  • Parser: parse_link now returns Link, and transaction/document parsing now accumulates Vec<Link>.
  • Loader: cross-file dedup now interns transaction/document link slices via intern_typed_vec(..., Link::as_interned_mut) and removes the now-unused intern_vec helper; docs updated accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/rustledger-parser/src/parser.rs Returns/threads Link from parse_link and stores parsed links in typed vectors.
crates/rustledger-loader/src/dedup.rs Uses typed interning helper for link slices and removes obsolete Vec<InternedStr> helper.
crates/rustledger-core/src/identifiers.rs Updates identifier-module docs to reflect Link being fully plumbed through the AST.
crates/rustledger-core/src/directive.rs Migrates Transaction.links / Document.links to Vec<Link> and updates with_link APIs; removes unused rkyv wrapper import.

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

@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 37.7ms ± 3.7ms 25.2 MB
beancount 911.2ms ± 9.9ms 50.7 MB
Comparison 24.2x faster 2.0x less

vs main branch (2026-05-20)

Metric main this PR Change
Time 40.2ms 37.7ms -6.2% 🟢
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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 786
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

@robcohen
robcohen merged commit d31c9e7 into main May 21, 2026
41 checks passed
@robcohen
robcohen deleted the feat/link-newtype branch May 21, 2026 03:15
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