Skip to content

Generate boundary's native dispatch from its .baml - #4116

Merged
codeshaunted merged 1 commit into
canaryfrom
avery/native-dispatch-boundary
Jul 22, 2026
Merged

codeshaunted merged 1 commit into
canaryfrom
avery/native-dispatch-boundary

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4099, which made baml_builtins2_codegen package-generic and moved reflect onto it. boundary was the last package still hand-wiring its natives.

What it was

pub fn get_native_fn(path: &str) -> Option<NativeFunction> {
    match path.strip_prefix("boundary.")? {
        "id" => Some(id::new),
        "id.current" => Some(id::current),
        "LocalId.capture" => Some(id::capture),
        _ => None,
    }
}

Nothing kept that in sync with the .baml declarations: adding a $rust_function and forgetting an arm gave a runtime lookup miss, not a build error. Each native also hand-rolled the boilerplate the generated glue already writes: arity checks, argument conversion, and the Result -> NativeCallResult match.

What it is now

boundary generates its BamlPackageBoundary / BamlNamespaceId / BamlClassLocalId hierarchy like baml and reflect (three lines in bex_vm/build.rs), so:

  • the three natives are required trait methods, and a declared $rust_function without an implementation is a compile error;
  • arguments arrive converted, so LocalId.capture takes Option<bool> triples instead of unpacking raw Values, and the hand-written optional_bool helper is deleted;
  • the LocalId constructor builds through the generated copy::LocalId struct instead of a positional alloc_instance(vec![...]);
  • VM_NATIVE_PACKAGES now points every package at a generated dispatcher, so no entry in it can drift.

Scope

I checked the other stdlib packages: log is entirely $compiler_intrinsic (no natives), and assert and testing declare none, so boundary was the only remaining offender.

Net +10 lines (the generation loop entry and trait scaffolding, minus the deleted dispatch and glue). Verified: bex_vm + baml_tests 2929 passing, baml_cli + bex_engine 976 passing, clippy clean.

Summary by CodeRabbit

  • Refactor
    • Updated the Boundary runtime package to use the same generated native-function dispatch as other standard-library packages.
    • Improved handling of Boundary IDs and local ID capture through typed interfaces.
    • Preserved local ID capture behavior while simplifying argument handling and state management.
    • Added generated Boundary native-function support to the build process.

boundary was the last package still hand-wiring its natives: a match over
string paths that nothing kept in sync with the .baml declarations, plus
per-native arity checks, argument conversion, and result-to-NativeCallResult
boilerplate the generated glue already writes.

It now goes through the generated BamlPackageBoundary hierarchy like baml
and reflect: the three natives become required trait methods that receive
converted arguments (LocalId.capture takes Option<bool> triples instead of
unpacking raw Values), the LocalId constructor builds through the generated
copy:: struct, and the hand-written optional_bool helper is gone.

log, assert, and testing declare no natives (log is all compiler
intrinsics), so no other package is affected.
@vercel

vercel Bot commented Jul 22, 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, Comment Jul 22, 2026 1:42am
promptfiddle Ready Ready Preview, Comment Jul 22, 2026 1:42am
promptfiddle2 Ready Ready Preview, Comment Jul 22, 2026 1:42am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 89c516f6-9632-4d48-92ac-5bff2e36dbb7

📥 Commits

Reviewing files that changed from the base of the PR and between 2c888e4 and ff00f57.

📒 Files selected for processing (4)
  • baml_language/crates/bex_vm/build.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/bex_vm/src/package_boundary/id.rs
  • baml_language/crates/bex_vm/src/package_boundary/mod.rs

📝 Walkthrough

Walkthrough

Boundary native functions are added to build-time generation, exposed through a generated module, and registered through the trait-based VM dispatcher. Boundary ID and LocalId entrypoints now use typed trait implementations and direct state/value conversions.

Changes

Boundary dispatcher migration

Layer / File(s) Summary
Generate and expose boundary dispatch
baml_language/crates/bex_vm/build.rs, baml_language/crates/bex_vm/src/package_boundary/mod.rs
Build generation now produces boundaryfunctions_generated.rs, which the boundary module includes and re-exports through PackageBoundaryImpl.
Implement typed boundary operations
baml_language/crates/bex_vm/src/package_boundary/id.rs
Boundary ID and LocalId operations now use generated traits, typed optional booleans, and direct LocalId state/value conversion.
Register the boundary resolver
baml_language/crates/bex_vm/src/package_baml/mod.rs
The VM registry routes boundary. calls through the generated BamlPackageBoundary resolver.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: rossirpaulo, hellovai

Poem

A rabbit hops through generated code,
Boundary paths now share the road.
Typed IDs and LocalIds align,
With trait-bound dispatch in a neat design.
“No hand-wired trails!” the bunny sings,
As build-time magic grows new wings.

🚥 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 matches the main change: generating boundary's native dispatch from its .baml declarations.
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 avery/native-dispatch-boundary

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.

@github-actions

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 July 22, 2026 01:21 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 22, 2026 01:29 Inactive
@codeshaunted
codeshaunted added this pull request to the merge queue Jul 22, 2026
@github-actions

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 25.6 MB 10.8 MB file 25.3 MB +275.0 KB (+1.1%) OK
✅ packed-program Linux 🔒 17.2 MB 7.1 MB file 17.0 MB +153.1 KB (+0.9%) OK
✅ baml-cli macOS 🔒 19.8 MB 9.4 MB file 19.6 MB +231.5 KB (+1.2%) OK
✅ packed-program macOS 🔒 13.4 MB 6.2 MB file 13.2 MB +198.3 KB (+1.5%) OK
✅ baml-cli Windows 🔒 21.3 MB 9.7 MB file 21.1 MB +230.9 KB (+1.1%) OK
✅ packed-program Windows 🔒 14.3 MB 6.3 MB file 14.2 MB +150.5 KB (+1.1%) OK
✅ bridge_wasm WASM 16.3 MB 🔒 4.4 MB gzip 4.4 MB +19.2 KB (+0.4%) 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

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle July 22, 2026 01:42 Inactive
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 22, 2026
@codeshaunted
codeshaunted added this pull request to the merge queue Jul 22, 2026
Merged via the queue into canary with commit 6951c86 Jul 22, 2026
66 checks passed
@codeshaunted
codeshaunted deleted the avery/native-dispatch-boundary branch July 22, 2026 01:52

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — ff00f572 Deployed Jul 22, 2026 by vercel[bot]
Preview – promptfiddle2 — ff00f572 Deployed Jul 22, 2026 by vercel[bot]
Preview – beps — ff00f572 Deployed Jul 22, 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