Skip to content

bcu: add BcuModule (.bcu), parallel baml_mir_linker, and Salsa-free emit pipeline - #5846

Open
hellovai wants to merge 9 commits into
claude/bcu-meta-rebasedfrom
claude/bcu-module-rebased
Open

hellovai wants to merge 9 commits into
claude/bcu-meta-rebasedfrom
claude/bcu-module-rebased

Conversation

@hellovai

@hellovai hellovai commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack (on top of kai/mir-stack-rebased)

  1. bcu: add baml_bcu crate and move PackageInterface/BcuMeta out of TIR #5845 (claude/bcu-meta-rebased): baml_bcu crate + .bmeta (replaces bcu: add baml_bcu crate and move PackageInterface/BcuMeta out of TIR #5827)
  2. bcu: add BcuModule (.bcu), parallel baml_mir_linker, and Salsa-free emit pipeline #5846 (claude/bcu-module-rebased): BcuModule (.bcu) + parallel baml_mir_linker + Salsa-free emit (replaces bcu: add BcuModule (.bcu), parallel baml_mir_linker, and Salsa-free emit pipeline #5830) (this PR)
  3. feat(cranelift): vendor cranelift-codegen 0.138 with AArch64 LSE2 + x86_64 AVX 128-bit atomics #5849 (claude/cranelift-vendor-rebased): Vendor cranelift-codegen 0.138 + LSE2/AVX 128-bit atomics (from feat(cranelift): vendor cranelift-codegen 0.138 and add AArch64 LSE2 + x86_64 AVX 128-bit atomics #5844)
  4. feat(cranelift,bex2): add Cranelift AOT backend, bex2 M:N runtime, and baml pack --native #5850 (claude/cranelift-bex2-rebased): Cranelift AOT backend + bex2 M:N runtime + baml pack --native (squashes feat(cranelift): add clean-room Cranelift AOT backend, runtime, and baml pack --native #5839, perf(cranelift): pinned mutator register, CallConv::Tail, TCO, scalar call ABI, and can_throw elision #5842, feat(cranelift): native 128-bit atomic Value slots across ABI, runtime, and Cranelift (no BUSY_BIT, unvendored) #5843, feat(cranelift): vendor cranelift-codegen 0.138 and add AArch64 LSE2 + x86_64 AVX 128-bit atomics #5844, feat(bex2): M:N work-stealing runtime, shared-heap GC, wait-free containers, direct-poll Tokio I/O, and two-tier package init #5847)

Rebased replacement for #5830 stacked on top of #5845 (claude/bcu-meta-rebased -> kai/mir-stack-rebased). Adapted for upstream changes in kai/mir-stack-rebased (Rvalue::LoadType { template, scoped_ty }, LocalClassDecl.rust_type / bex_vm_types::ClassBody, ClassCrossing::HostValue, WellKnownHead::item, array/map spread lowering, removed RustType variants, and deleted baml_compiler2_rust).

Why

  • Previously MirFunction<'db> carried Salsa lifetimes (FunctionLoc<'db>, ClassRef<'db>, EnumRef<'db>, InterfaceRef<'db>, GlobalRef<'db>, baml_base::Span) and forced MIR lowering, O2 optimization, escape analysis, and bytecode emission to execute through per-function Salsa queries (lower_function, impl_rule, runtime_signature, escape_summary).
  • That coupled the frontend to the VM emitter, prevented serializing per-package MIR compilation units (.bcu) to disk, blocked target-independent backends (such as Cranelift), and added Salsa query / DeclName allocation overhead on large projects.

What changes

Introduces the complete, end-to-end .bcu (BcuModule) compilation pipeline on top of baml_bcu (.bmeta from #5845), including full Salsa-free O2 optimization parity:

  1. Concrete 'static BcuModule + baml_bcu::mir + ArtifactKind::BcuModule (baml_bcu, baml_artifact): zero-cost Id<K> (TypeDefId, GlobalId, FuncId), WireRef<K>, SymbolTable<K, Local, Import>, BcuFileId/BcuSpan, file_line_starts, FuncKey, LocalTypeDef/LocalTypeDecl (including rust_type: Option<RustPayloadKind>), MirFunction, ImplRule, InlineScope, deterministic Borsh encoding, validate(), semantic_digest(), and a sigil-free .bcu text printer.
  2. 1-to-1 MIR swap & parallel package lowering (baml_compiler2_mir, baml_compiler2_emit, baml_db, baml_cli, baml_tests): deletes MirFunction<'db>, MirFunctionId<'db>, ImplRule<'db>, and InlineScope<'db>; lowers each package in parallel into Arc<BcuModule> with byte-identical deterministic merge across workers.
  3. Pure Salsa-free parallel baml_mir_linker with full O2 parity (crates/baml_mir_linker): binds Locator::{Prelude, Direct, Transitive}, verifies .bmeta digests, computes $init order (tolerating prelude cycles), assigns global IDs via prefix sums, relocates all packages in parallel into LinkedMirProgram, and runs the complete parallel Salsa-free O2 pass suite (devirtualize, cross-package inline + stdlib loop_form + closures, values constant folding / dead stores / operand-prefix materialization, scalar_replace, effects interval/bounds drop elimination, cleanup copy propagation / dead locals / RPO, redundancy CSE / negated branches / return threading, and loops LICM with local Steensgaard escape analysis + loop rotation).
  4. Salsa-free parallel bytecode emission & E2E wiring (baml_compiler2_emit, baml_db): extracts a shared zero-lifetime EmitTarget trait in emit.rs, adds emit_linked_program(&LinkedMirProgram, opt) -> Program (with Salsa-free interprocedural escape analysis and BEP-085 package-isolated compilation_unit_hash), and wires CheckedWorld::compile through pure per-package O0 .bmeta+.bcu -> baml_mir_linker -> emit_linked_program.

Observable checks

  • cargo run --profile fasttest -p cargo-stow -- stow --check: 0 violations.
  • cargo fmt --all -- --check: clean.
  • Unit tests (fasttest):
    • baml_bcu: 9/9 passed
    • baml_mir_linker: 32/32 passed
    • baml_compiler2_mir: 79/79 passed
    • baml_compiler2_emit: 57/57 passed
    • baml_db: 70/70 passed
  • Integration tests (fasttest):
    • baml_tests --test bcu_e2e: 2/2 passed
    • baml_tests --test inliner: 48/48 passed
    • baml_tests --test package_identity: 11/11 passed
  • cargo clippy --profile fasttest --no-deps --tests -p baml_artifact -p baml_bcu -p baml_mir_linker -p baml_compiler2_hir -p baml_compiler2_hir_ty -p baml_compiler2_mir -p baml_compiler2_emit -p baml_db -p baml_cli -- -D warnings: 0 warnings.

@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
developer-docs Ready Ready Preview Dec 3, 2026 5:57am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 223b2ee5-dfac-47de-9571-ea5d8243f05e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@blacksmith-sh

This comment has been minimized.

@blacksmith-sh

blacksmith-sh Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Found 18 test failures on Blacksmith runners:

Failures

Test View Logs
Anthropic Provider/Anthropic Provider should support anthropic shorthand View Logs
Anthropic Provider/
Anthropic Provider Streaming should support anthropic shorthand streaming
View Logs
AWS Provider/
AWS Provider Dynamic Client Registry Credential Resolution should handle session creden
tials correctly
View Logs
AWS Provider/
AWS Provider Dynamic Client Registry should throw error when using temporary credential
s without session token
View Logs
Azure Provider/
Azure Provider should support o1 model with explicit max_completion_tokens
View Logs
Collector Tests/Collector Tests should track cached input tokens for Anthropic caching View Logs
Experimental OnTick/
Experimental OnTick should fire onTick callbacks for async non-streaming function
View Logs
Experimental OnTick/
Experimental OnTick should fire onTick callbacks for streaming function
View Logs
Experimental OnTick/Experimental OnTick should handle onTick callback errors View Logs
Experimental OnTick/Experimental OnTick should not significantly impact performance View Logs

...and 8 more test failures. View all on Blacksmith

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

This branch was successfully deployed

1 active deployment
Preview – developer-docs — d16e5176 Deployed Dec 3, 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