Skip to content

feat(compiler): guarantee mounted package parity (BEP-066 slice 6a, PR 5 — capstone) - #4333

Merged
antoniosarosi merged 1 commit into
antonio/s6a-call-consumptionfrom
antonio/s6a-parity-capstone
Aug 7, 2026
Merged

antoniosarosi merged 1 commit into
antonio/s6a-call-consumptionfrom
antonio/s6a-parity-capstone

Conversation

@antoniosarosi

@antoniosarosi antoniosarosi commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

BEP-066 slice-6a stack, PR 5 of 5 — the capstone. Chained on #4332. With this green, the slice-6a stack is complete: a package consumed as an interface blob is provably indistinguishable from the same package consumed as source.

The parity oracle (mounted_package_parity.rs)

  • Source-vs-blob runtime parity across the full surface: interfaces + requires + assoc defaults + default methods, attrs, generics/bounds, enums, aliases, in-body/out-of-body/blanket impls, user impls of mounted interfaces, caught-throw behavior.
  • Byte-identical diagnostic fingerprints (code/message/severity/phase/user range) for the misuse variants: wrong arity, unsatisfied bound, non-exhaustive match, missing impl members.
  • Byte-identical artifacts: dependency units, package metadata, consumer import tables raw-identical; consumer units + whole programs identical after normalizing database-local debug FileIds — the sole legitimate difference (the known B-693 §9b wart), with paths/ranges/symbols/executable bytes identical.

What the oracle caught (fixed in the implementation, never weakened in the oracle)

  1. Source auxiliary packages didn't participate in user dependency resolution the way mounted ones do.
  2. Mounted interface defaults/assoc-defaults/fields/method tables seeded emission differently from source interfaces.
  3. Impl-method exports mishandled synthetic callback-effect parameters vs enclosing impl generics.

Also in this PR

  • Coherence-fails-open hole closed and proven: user-vs-blob impl overlap yields exactly one primary-only E0132 attributed at the user's impl, dep side rendered structurally.
  • Public link seam: the two-DB compile-and-link harness promoted from test scaffolding to a documented API — slice 6's Package.compile consumes this.
  • Residue ledger documented adjacent to the public API (E0158 builtin residue, span-dependent LSP ops, re-aliasing/transitive re-export, live $stream loading, artifact versioning, dispatcher synthesis) — slice 6 starts from a ledger, not archaeology.

Gates

Full baml_tests green · all-features mounted call/parity suites 26/26 · HIR/TIR/project · bytecode_cache 43/43 · fmt/clippy/rustdoc all-features -D warnings · zero snapshot churn.

Implemented by a Codex (gpt-5.6-sol) worker under stack-manager review.

Summary by CodeRabbit

  • New Features

    • Added support for compiling applications against mounted, source-less packages, including their default methods, type defaults, and field definitions.
    • Added dependency linking for precompiled package artifacts before consumer compilation.
  • Bug Fixes

    • Improved handling of generic callback-effect metadata in exported functions and implementation methods.
    • Improved package discovery and dependency resolution for auxiliary and mounted source packages.
  • Tests

    • Added comprehensive parity coverage for source-based and serialized mounted packages, including runtime behavior, diagnostics, imports, and linking.

@antoniosarosi

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@vercel

vercel Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview Aug 6, 2026 6:00am
promptfiddle2 Ready Ready Preview Aug 6, 2026 6:00am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Mounted package interfaces and compilation units now participate in runtime linking and consumer compilation. Exported impl-method metadata preserves synthetic callback-effect parameters. New parity tests compare source and mounted builds across runtime, diagnostics, artifacts, and link errors.

Changes

Mounted package linking

Layer / File(s) Summary
Package metadata and exported generics
baml_language/crates/baml_compiler2_hir/src/package.rs, baml_language/crates/baml_compiler2_tir/src/inference.rs, baml_language/crates/baml_compiler2_tir/src/package_interface.rs
Dependency discovery includes eligible source packages. Impl-method exports preserve synthetic callback-effect parameters and apply bounds only to user-declared parameters.
Mounted interface registry and unit linking
baml_language/crates/baml_compiler2_emit/src/lib.rs
Mounted interfaces populate declaration registries for defaults, associated types, and fields. generate_project_bytecode_with_mounted_units links dependency units before compiling the consumer and reports link or lowering errors separately.
Mounted call integration harness
baml_language/crates/baml_tests/tests/mounted_package_calls.rs, baml_language/crates/baml_tests/src/compiler2_tir/package_interface.rs
Library tests emit CompilationUnit artifacts and compile consumers through the mounted-unit API. Integration documentation reflects source-less call and runtime coverage.
Source and mounted parity validation
baml_language/crates/baml_tests/tests/mounted_package_parity.rs
Tests compare runtime results, diagnostics, normalized artifacts, callback-effect metadata, dependency-link failures, and implementation-overlap diagnostics between source and mounted builds.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LibraryCompiler
  participant UnitLinker
  participant DeclarationRegistry
  participant ConsumerCompiler
  LibraryCompiler->>UnitLinker: emit dependency CompilationUnit artifacts
  UnitLinker->>DeclarationRegistry: load mounted interfaces and defaults
  UnitLinker->>ConsumerCompiler: provide linked dependency image
  ConsumerCompiler->>DeclarationRegistry: resolve mounted declarations
  ConsumerCompiler-->>UnitLinker: return consumer Program or link error
Loading

Possibly related PRs

  • BoundaryML/baml#3896: Extends per-package interface and runtime registry work to mounted-package interfaces and defaults.
  • BoundaryML/baml#4099: Shares compiler package-interface and runtime function metadata changes, including associated-type defaults and exported effect information.
  • BoundaryML/baml#4326: Provides enriched PackageInterface data consumed for mounted-package runtime registries.

Suggested reviewers: 2kai2kai2, codeshaunted

Poem

A rabbit links units through the code,
Mounted defaults share the load.
Effects hop in generic lines,
Parity tests check matching signs.
“Thump!” says Bun, “the builds now agree.”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the compiler feature and the main change: guaranteeing parity for mounted packages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch antonio/s6a-parity-capstone

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@vercel
vercel Bot temporarily deployed to Preview – beps August 6, 2026 05:52 Inactive

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (3)
baml_language/crates/baml_tests/tests/mounted_package_calls.rs (1)

165-177: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update the stale "spliced" wording in the doc comment.

Line 166 still describes the old splice path. The function now links mounted CompilationUnits through generate_project_bytecode_with_mounted_units. The module header at lines 12-22 was already updated, so this line is the only remaining stale description.

Note also that compile_library() runs on every call, so each test rebuilds the library database and re-emits units. That cost is acceptable for a test harness, but a OnceLock cache would remove it if the suite grows.

♻️ Proposed doc fix
 /// Phase 2: a fresh consumer database — blob mounted as `app`, NO `app`
-/// source — checked clean, then spliced against the library image.
+/// source — checked clean, then linked against the library's mounted units.
 fn consumer_program(user_src: &str) -> Program {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_tests/tests/mounted_package_calls.rs` around lines
165 - 177, Update the doc comment above consumer_program to replace the stale
“spliced against the library image” wording with wording that accurately
describes linking mounted CompilationUnits through
generate_project_bytecode_with_mounted_units. Do not change the test behavior or
introduce caching.
baml_language/crates/baml_tests/tests/mounted_package_parity.rs (2)

558-564: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document why the library unit compares raw, without normalization.

This assertion compares source_app and independent_app byte-for-byte with no FileId normalization, while every other comparison in this test normalizes first. That works only because source_db builds on library_db() and registers <builtin>/app/lib.baml before main.baml, so the builtin file receives the same FileId in both databases.

The dependency is real but implicit. If someone reorders source_db at lines 187-191, this assertion fails for a non-obvious reason. Add a short comment recording the ordering requirement.

♻️ Proposed comment
+    // No normalization here: `source_db` registers the builtin app file before
+    // `main.baml`, so `<builtin>/app/lib.baml` holds the same `FileId` in the
+    // source database and in the standalone library database.
     let source_app = unit(&source_units, "<builtin>/app/lib.baml");
     let independent_app = unit(&artifacts.units, "<builtin>/app/lib.baml");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_tests/tests/mounted_package_parity.rs` around lines
558 - 564, Add a short comment immediately before the raw byte comparison of
source_app and independent_app explaining that FileId normalization is
intentionally omitted because source_db must register <builtin>/app/lib.baml via
library_db() before main.baml, preserving the same FileId in both databases;
note that reordering that setup breaks this assertion.

341-367: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Sort the diagnostic rows before joining them.

diagnostic_bytes joins rows in collect_diagnostics order. The comparison is therefore order-sensitive. The source database holds an extra file (<builtin>/app/lib.baml) that the blob database does not, so the two databases can in principle order diagnostics differently. The four current fixtures each yield a single error, so the ordering is not exercised today. If a future fixture yields two or more errors, this oracle can fail for a reason unrelated to parity.

Sort the rows to make the record order-independent.

♻️ Proposed fix
-    let rows: Vec<String> = collect_diagnostics(db)
+    let mut rows: Vec<String> = collect_diagnostics(db)
         .into_iter()
@@
         .collect();
+    rows.sort_unstable();
     rows.join("\n").into_bytes()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_tests/tests/mounted_package_parity.rs` around lines
341 - 367, Update diagnostic_bytes to sort the collected rows before joining
them into bytes. Preserve the existing diagnostic formatting and filtering, but
make the final output order-independent for multiple diagnostics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@baml_language/crates/baml_tests/tests/mounted_package_calls.rs`:
- Around line 165-177: Update the doc comment above consumer_program to replace
the stale “spliced against the library image” wording with wording that
accurately describes linking mounted CompilationUnits through
generate_project_bytecode_with_mounted_units. Do not change the test behavior or
introduce caching.

In `@baml_language/crates/baml_tests/tests/mounted_package_parity.rs`:
- Around line 558-564: Add a short comment immediately before the raw byte
comparison of source_app and independent_app explaining that FileId
normalization is intentionally omitted because source_db must register
<builtin>/app/lib.baml via library_db() before main.baml, preserving the same
FileId in both databases; note that reordering that setup breaks this assertion.
- Around line 341-367: Update diagnostic_bytes to sort the collected rows before
joining them into bytes. Preserve the existing diagnostic formatting and
filtering, but make the final output order-independent for multiple diagnostics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cbb5da7d-a1ae-45ab-89ae-c28a9e185f99

📥 Commits

Reviewing files that changed from the base of the PR and between c0d18e4 and b4fb0f0.

📒 Files selected for processing (7)
  • baml_language/crates/baml_compiler2_emit/src/lib.rs
  • baml_language/crates/baml_compiler2_hir/src/package.rs
  • baml_language/crates/baml_compiler2_tir/src/inference.rs
  • baml_language/crates/baml_compiler2_tir/src/package_interface.rs
  • baml_language/crates/baml_tests/src/compiler2_tir/package_interface.rs
  • baml_language/crates/baml_tests/tests/mounted_package_calls.rs
  • baml_language/crates/baml_tests/tests/mounted_package_parity.rs

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 August 6, 2026 06:00 Inactive
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 28.0 MB 11.9 MB file 27.4 MB +621.0 KB (+2.3%) OK
✅ packed-program Linux 🔒 18.2 MB 7.5 MB file 17.7 MB +494.6 KB (+2.8%) OK
✅ baml-cli macOS 🔒 21.8 MB 10.4 MB file 21.3 MB +478.5 KB (+2.2%) OK
✅ packed-program macOS 🔒 14.2 MB 6.6 MB file 13.8 MB +376.6 KB (+2.7%) OK
✅ baml-cli Windows 🔒 23.4 MB 10.6 MB file 23.0 MB +477.1 KB (+2.1%) OK
✅ packed-program Windows 🔒 15.2 MB 6.7 MB file 14.8 MB +394.2 KB (+2.7%) OK
✅ bridge_wasm WASM 17.3 MB 🔒 4.7 MB gzip 4.6 MB +104.4 KB (+2.3%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@antoniosarosi
antoniosarosi merged commit 91e0d4b into antonio/s6a-call-consumption Aug 7, 2026
73 checks passed
@antoniosarosi
antoniosarosi deleted the antonio/s6a-parity-capstone branch August 7, 2026 05:27

This branch was previously deployed

2 inactive deployments
Preview – promptfiddle2 — b4fb0f0a Deployed Aug 6, 2026 by vercel[bot]
Preview – beps — b4fb0f0a Deployed Aug 6, 2026 by vercel[bot]
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