Repository navigation
feat(compiler): guarantee mounted package parity (BEP-066 slice 6a, PR 5 — capstone) - #4333
Conversation
|
@coderabbitai review |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughMounted 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. ChangesMounted package linking
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
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
✅ Action performedReview finished.
|
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
There was a problem hiding this comment.
🧹 Nitpick comments (3)
baml_language/crates/baml_tests/tests/mounted_package_calls.rs (1)
165-177: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUpdate the stale "spliced" wording in the doc comment.
Line 166 still describes the old splice path. The function now links mounted
CompilationUnits throughgenerate_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 aOnceLockcache 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 valueDocument why the library unit compares raw, without normalization.
This assertion compares
source_appandindependent_appbyte-for-byte with noFileIdnormalization, while every other comparison in this test normalizes first. That works only becausesource_dbbuilds onlibrary_db()and registers<builtin>/app/lib.bamlbeforemain.baml, so the builtin file receives the sameFileIdin both databases.The dependency is real but implicit. If someone reorders
source_dbat 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 winSort the diagnostic rows before joining them.
diagnostic_bytesjoins rows incollect_diagnosticsorder. 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
📒 Files selected for processing (7)
baml_language/crates/baml_compiler2_emit/src/lib.rsbaml_language/crates/baml_compiler2_hir/src/package.rsbaml_language/crates/baml_compiler2_tir/src/inference.rsbaml_language/crates/baml_compiler2_tir/src/package_interface.rsbaml_language/crates/baml_tests/src/compiler2_tir/package_interface.rsbaml_language/crates/baml_tests/tests/mounted_package_calls.rsbaml_language/crates/baml_tests/tests/mounted_package_parity.rs
Binary size checks passed✅ 7 passed
Generated by |
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)What the oracle caught (fixed in the implementation, never weakened in the oracle)
Also in this PR
Package.compileconsumes this.$streamloading, 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
Bug Fixes
Tests