Skip to content

Type algebra unification and runtime interface objects - #3896

Merged
2kai2kai2 merged 9 commits into
canaryfrom
kai/unified-type-algebra
Jul 1, 2026
Merged

2kai2kai2 merged 9 commits into
canaryfrom
kai/unified-type-algebra

Conversation

@2kai2kai2

@2kai2kai2 2kai2kai2 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor
  • Adds Object::Interface, Object::ImplRule, and Object::Package as new heap object types. Like Class, these are not user values but instead allow program elements to be addressable by heap pointer.
  • Object::Package is now the unified way to lookup items by name.
  • Partial fix to associated type projection subtyping
  • The runtime now partially uses the canonical type algebra logic

This PR is part of an ongoing process so further PRs will be forthcoming.

Summary by CodeRabbit

  • New Features

    • Improved runtime support for interfaces, including interface metadata and package-aware implementation loading.
    • Enhanced associated-type bound handling to make symbolic projections participate correctly in subtype checks.
  • Bug Fixes

    • Fixed type conversion/union resolution and VM value handling for interface-, package-, and implementation-rule objects.
    • Improved subtype/equality/reflection behavior for complex and symbolic type cases.
  • Tests

    • Added a CSV regression test to ensure user-defined enum fields decode correctly.

@vercel

vercel Bot commented Jul 1, 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 1, 2026 9:54pm
promptfiddle Ready Ready Preview, Comment Jul 1, 2026 9:54pm
promptfiddle2 Ready Ready Preview, Comment Jul 1, 2026 9:54pm

Request Review

@github-actions

github-actions Bot commented Jul 1, 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.

@coderabbitai

coderabbitai Bot commented Jul 1, 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: 3c549bc9-1ab6-477b-b94d-b0a41bb9ad30

📥 Commits

Reviewing files that changed from the base of the PR and between f0e9b4d and 8c9c7c6.

⛔ Files ignored due to path filters (2)
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap is excluded by !**/*.snap
📒 Files selected for processing (31)
  • baml_language/crates/baml_compiler2_emit/src/lib.rs
  • baml_language/crates/baml_compiler2_tir/src/builder.rs
  • baml_language/crates/baml_compiler2_tir/src/interfaces/impl_rules.rs
  • baml_language/crates/baml_tests/tests/csv.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_engine/src/trace_heap.rs
  • baml_language/crates/bex_heap/src/accessor.rs
  • baml_language/crates/bex_heap/src/gc.rs
  • baml_language/crates/bex_heap/src/heap.rs
  • baml_language/crates/bex_heap/src/heap_debugger/real.rs
  • baml_language/crates/bex_vm/src/lib.rs
  • baml_language/crates/bex_vm/src/package_baml/csv.rs
  • baml_language/crates/bex_vm/src/package_baml/future.rs
  • baml_language/crates/bex_vm/src/package_baml/json.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/bex_vm/src/package_baml/ops.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/package_baml/root.rs
  • baml_language/crates/bex_vm/src/package_load.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/bex_vm/tests/interface_registry.rs
  • baml_language/crates/bex_vm_types/src/types.rs
  • baml_language/crates/bex_vm_types/src/types/interface.rs
  • baml_language/crates/bex_vm_types/src/types/object.rs
  • baml_language/crates/bex_vm_types/src/types/package.rs
  • baml_language/crates/tools_onionskin/src/compiler.rs
  • baml_language/crates/tools_sap_visualizer/src/compile.rs
✅ Files skipped from review due to trivial changes (2)
  • baml_language/crates/tools_sap_visualizer/src/compile.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
🚧 Files skipped from review as they are similar to previous changes (28)
  • baml_language/crates/bex_heap/src/heap_debugger/real.rs
  • baml_language/crates/bex_vm/src/package_baml/future.rs
  • baml_language/crates/bex_engine/src/trace_heap.rs
  • baml_language/crates/bex_vm/src/lib.rs
  • baml_language/crates/bex_heap/src/accessor.rs
  • baml_language/crates/tools_onionskin/src/compiler.rs
  • baml_language/crates/bex_vm/tests/interface_registry.rs
  • baml_language/crates/bex_heap/src/heap.rs
  • baml_language/crates/bex_vm/src/package_load.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_heap/src/gc.rs
  • baml_language/crates/baml_compiler2_tir/src/builder.rs
  • baml_language/crates/baml_compiler2_tir/src/interfaces/impl_rules.rs
  • baml_language/crates/bex_vm/src/package_baml/ops.rs
  • baml_language/crates/bex_vm_types/src/types/package.rs
  • baml_language/crates/bex_vm_types/src/types/interface.rs
  • baml_language/crates/bex_vm/src/package_baml/root.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/bex_vm_types/src/types.rs
  • baml_language/crates/bex_vm/src/package_baml/csv.rs
  • baml_language/crates/baml_compiler2_emit/src/lib.rs
  • baml_language/crates/bex_vm_types/src/types/object.rs
  • baml_language/crates/bex_vm/src/package_baml/json.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/vm.rs

📝 Walkthrough

Walkthrough

The compiler, VM, engine, heap, and tooling now represent interfaces and impl rules as per-package objects. Runtime lookup, type normalization, and object handling were updated to use package-indexed resolution and the new Interface/Package/ImplRule object variants.

Changes

Package-based interface impl registry

Layer / File(s) Summary
New package and object contracts
baml_compiler2_emit/src/lib.rs, baml_vm_types/src/types/package.rs, baml_vm_types/src/types/interface.rs, baml_vm_types/src/types/object.rs, baml_vm_types/src/types.rs
Adds package-scoped program/runtime structures, interface metadata types, and Object/ObjectType support for package, interface, and impl-rule values.
Compiler emission into per-package tables
baml_compiler2_emit/src/lib.rs
Builds runtime interface definitions, emits interfaces, resolves impl methods to object indices, and stores impl rules in program_packages.
Interface membership delegation
baml_compiler2_tir/src/interfaces/impl_rules.rs, baml_compiler2_tir/src/builder.rs
Adds shared realized/symbolic interface-membership helpers and delegates the builder path to them.
Associated-type bounds and subtyping
baml_type/src/normalize.rs, baml_type/src/normalize/tests.rs
Adds associated-type bound lookup, subtype handling for projections, and broader normalization tests.
Package loading and runtime type lookup
bex_vm/src/package_load.rs, bex_vm/src/lib.rs
Introduces package-slot loading, heap sealing, and package-based type/alias lookup helpers.
VM package-indexed wiring
bex_vm/src/vm.rs, bex_vm/tests/interface_registry.rs
Reworks VM/program state around shared packages and updates runtime type resolution and interface-registry tests.
Runtime lookup migration
bex_vm/src/package_baml/{resolve,ops,mod,json,csv,future,root}.rs, bex_vm/src/type_context.rs
Switches runtime resolution paths to package lookup helpers, updates equality/dispatch, and adds a VM-backed TypeContext.
Engine, heap, and GC handling of new objects
bex_engine/src/{lib,conversion,trace_heap}.rs, bex_heap/src/{accessor,gc,heap,heap_debugger/real}.rs, bex_vm/src/package_baml/root.rs
Shares package metadata across VMs and extends conversion, tracing, GC, deep copy, and heap lifecycle handling for the new object kinds.
Tooling display and package-based test updates
tools_onionskin/src/compiler.rs, tools_sap_visualizer/src/compile.rs, baml_tests/tests/csv.rs
Updates value display and alias derivation, and adds a CSV regression test for enum decoding through package-based type lookup.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • BoundaryML/baml#3076: Both PRs restructure BexEngine initialization and package/metadata plumbing in bex_engine/src/lib.rs.
  • BoundaryML/baml#3555: Both PRs touch interface-implementation semantics and the compiler/runtime seam that consumes them.
  • BoundaryML/baml#3788: Both PRs rely on the object-indexed interface dispatch substrate and runtime method resolution changes.

Poem

A rabbit hopped through package lanes,
Where interface seeds grew tidy chains.
One burrow, many pointers bright,
Impls and types now map just right,
Hop hop, the registry learned to sing —
🐇 a neat little package-wrangling spring!

🚥 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 matches the PR’s main themes: type-algebra changes and new runtime interface/package objects.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 kai/unified-type-algebra

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.

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 1, 2026 02:50 Inactive
@github-actions

github-actions Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 21.6 MB 9.2 MB file 21.5 MB +116.7 KB (+0.5%) OK
✅ packed-program Linux 🔒 15.8 MB 6.6 MB file 15.6 MB +148.6 KB (+1.0%) OK
✅ baml-cli macOS 🔒 16.6 MB 8.0 MB file 16.6 MB +66.3 KB (+0.4%) OK
✅ packed-program macOS 🔒 12.2 MB 5.8 MB file 12.1 MB +83.1 KB (+0.7%) OK
✅ baml-cli Windows 🔒 18.2 MB 8.2 MB file 18.1 MB +107.0 KB (+0.6%) OK
✅ packed-program Windows 🔒 13.1 MB 5.9 MB file 13.0 MB +129.1 KB (+1.0%) OK
✅ bridge_wasm WASM 14.5 MB 🔒 4.1 MB gzip 4.1 MB +44.7 KB (+1.1%) 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 1, 2026 03:03 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.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
baml_language/crates/bex_vm/src/package_baml/resolve.rs (1)

124-139: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Scan the declaring packages when resolving candidate impl rules.

candidate_rules only checks the concrete type’s package and the interface package, but impl rules are stored in the package where the impl is declared. A package-level blanket/primitive/container impl for an imported interface can therefore be visible in implementor_entries but missed by runtime dispatch/type membership here.

Potential fix
-    let mut pkgs: Vec<&Name> = Vec::with_capacity(2);
-    if let Some(p) = type_package(concrete_ty) {
-        pkgs.push(p);
-    }
-    let iface_pkg = iface.package();
-    if !pkgs.contains(&iface_pkg) {
-        pkgs.push(iface_pkg);
-    }
     let mut out = Vec::new();
-    for pkg in pkgs {
-        let Some(&pkg_ptr) = vm.packages.get(pkg) else {
-            continue;
-        };
+    for &pkg_ptr in vm.packages.values() {
         collect_package_rules(vm, deref_package(vm, pkg_ptr), iface_ptr, &mut out);
     }
     out
🤖 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/bex_vm/src/package_baml/resolve.rs` around lines 124 -
139, candidate_rules currently only searches the concrete type package and
iface.package(), but impl rules live in the package where the impl is declared,
so runtime dispatch can miss imported-interface impls. Update candidate_rules in
resolve.rs to also scan the declaring package(s) for the interface/impl
relationship, using the existing helpers like collect_package_rules,
deref_package, and vm.packages lookups, so package-level
blanket/primitive/container impls are included in the candidate set.
🧹 Nitpick comments (3)
baml_language/crates/bex_vm/src/type_context.rs (1)

1-110: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a unit test suite for RuntimeTypeContext once wired.

Per coding guidelines, unit tests are preferred over integration tests for *.rs files. This file currently has none, though it is intentionally dead_code and unwired per the module doc, so a test fixture would need a constructed BexVm. Worth tracking for the follow-up PR that flips call sites onto this context.

As per coding guidelines, "Prefer writing Rust unit tests over integration tests where possible."

🤖 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/bex_vm/src/type_context.rs` around lines 1 - 110, Add
Rust unit tests for RuntimeTypeContext instead of leaving this module untested;
the review asks to cover it once it is wired, and the best place is a
#[cfg(test)] module alongside RuntimeTypeContext::new and the TypeContext impl
methods. Focus on small unit-level checks for alias_def, implements_interface,
interface_requires, and enum_variants, using a minimal constructed BexVm test
fixture so the tests stay local to this file and avoid integration coverage.

Source: Coding guidelines

baml_language/crates/bex_heap/src/gc.rs (1)

550-563: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update the GC invariant comment to cover Interface, Package, and ImplRule. The leaf-arm shortcut still holds, but the doc should say these variants have no runtime HeapPtrs, not no HeapPtrs at all. Package and ImplRule do carry HeapPtr fields, so the invariant needs that wording to stay precise.

🤖 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/bex_heap/src/gc.rs` around lines 550 - 563, Update the
GC invariant comment in gc.rs so it accurately describes the leaf-arm shortcut
for Object::Interface, Object::Package, and Object::ImplRule. The current
wording implies these variants have no HeapPtr fields at all, but Package and
ImplRule do contain HeapPtr members; revise the comment to say they have no
runtime HeapPtrs that need tracing, while keeping the existing Object match arm
unchanged. Use the Object enum variant names in the comment to make the
invariant precise.
baml_language/crates/bex_vm/src/package_baml/future.rs (1)

95-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the stale unsafe lookup comment.

The pointer no longer comes from resolved_class_names; use vm.get_object(enm_ptr) here and drop the outdated safety note.

Proposed cleanup
         let Some(enm_ptr) = vm.lookup_type_by_fqn("baml.future.FutureState") else {
             return Value::NULL;
         };
-        // SAFETY: enm_ptr came from resolved_class_names which holds
-        // compile-time-registered HeapPtrs valid for the program's lifetime.
-        let idx = match unsafe { enm_ptr.get() } {
+        let idx = match vm.get_object(enm_ptr) {
             Object::Enum(e) => e.variants.iter().position(|v| v.name == variant_name),
             _ => None,
         };
🤖 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/bex_vm/src/package_baml/future.rs` around lines 95 -
100, The lookup in future.rs is outdated: the pointer is no longer sourced from
resolved_class_names, so the SAFETY comment is stale. Update the FutureState
handling in the code path around vm.lookup_type_by_fqn and enm_ptr to use
vm.get_object(enm_ptr) instead of unsafe access, and remove the obsolete safety
note so the implementation matches the current ownership model.
🤖 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.

Inline comments:
In `@baml_language/crates/baml_compiler2_emit/src/lib.rs`:
- Around line 287-298: The impl method dispatch table is currently allowed to
silently drop entries when resolve_fqn cannot find a function index, which can
serialize incomplete metadata. Update resolve_fqn and its callers in the emit
flow to fail hard during emission (or use an explicit expect with the missing
FQN) instead of returning None and skipping methods/defaults, so invalid FQNs in
the emission path surface as a compiler error. Apply the same treatment to the
related call sites around the other dispatch table builders to keep emitted impl
tables complete and consistent.
- Around line 89-93: The runtime lowering in lower_rt is dropping valid
InterfaceDef members whenever a signature mentions Self or Self.Assoc, which
then causes callers in the interface param/field/return/throws handling paths to
omit members or substitute Void. Update the signature lowering path used by
InterfaceDef-related code so it is interface-aware and can preserve arity for
Self-based and associated-type references, either by projecting them explicitly
or by carrying an unresolved/runtime placeholder instead of failing closed. Make
the change in the lower_rt flow and the callers that build interface metadata so
valid interface members are never silently removed.

In `@baml_language/crates/bex_vm/src/package_baml/csv.rs`:
- Around line 1405-1408: The CSV enum resolution in Target::Enum is using
lookup_type_by_fqn on a rendered name, which can fail for user-package enum
fields. Update the Target::Enum handling in csv.rs to keep and use the enum
TypeName and resolve it through vm.lookup_type(qtn) instead of
vm.lookup_type_by_fqn, while preserving the existing bad-conversion error path
when the type cannot be found.

In `@baml_language/crates/bex_vm/src/type_context.rs`:
- Around line 6-10: Update the stale doc comments in `type_context.rs` to match
the new per-package runtime model: revise the module and struct docs for
`TypeContext`, `implements_interface`, and `enum_variants` so they describe
delegation to `package_baml::type_implements` and
`self.vm.lookup_type(name)`/the `packages` index instead of the old baked
`interface_impls` and `resolved_class_names` terminology. Keep the wording
aligned with the actual implementations of `implements_interface`, `alias_def`,
and `enum_variants`, and remove references to the pre-refactor registry/heap
model.

In `@baml_language/crates/bex_vm/tests/interface_registry.rs`:
- Around line 23-30: The baked-rule matcher in the interface registry helper is
too loose because it compares `iface` by short name and `for_type` by substring,
which can pick the wrong rule when names overlap. Update the logic around the
`find` predicate in `interface_registry.rs` to use qualified names or a
structured `TyTemplate`/`TypeName` comparison, and keep the existing
`as_interface()` lookup aligned with the fully qualified interface identity
instead of string containment.

---

Outside diff comments:
In `@baml_language/crates/bex_vm/src/package_baml/resolve.rs`:
- Around line 124-139: candidate_rules currently only searches the concrete type
package and iface.package(), but impl rules live in the package where the impl
is declared, so runtime dispatch can miss imported-interface impls. Update
candidate_rules in resolve.rs to also scan the declaring package(s) for the
interface/impl relationship, using the existing helpers like
collect_package_rules, deref_package, and vm.packages lookups, so package-level
blanket/primitive/container impls are included in the candidate set.

---

Nitpick comments:
In `@baml_language/crates/bex_heap/src/gc.rs`:
- Around line 550-563: Update the GC invariant comment in gc.rs so it accurately
describes the leaf-arm shortcut for Object::Interface, Object::Package, and
Object::ImplRule. The current wording implies these variants have no HeapPtr
fields at all, but Package and ImplRule do contain HeapPtr members; revise the
comment to say they have no runtime HeapPtrs that need tracing, while keeping
the existing Object match arm unchanged. Use the Object enum variant names in
the comment to make the invariant precise.

In `@baml_language/crates/bex_vm/src/package_baml/future.rs`:
- Around line 95-100: The lookup in future.rs is outdated: the pointer is no
longer sourced from resolved_class_names, so the SAFETY comment is stale. Update
the FutureState handling in the code path around vm.lookup_type_by_fqn and
enm_ptr to use vm.get_object(enm_ptr) instead of unsafe access, and remove the
obsolete safety note so the implementation matches the current ownership model.

In `@baml_language/crates/bex_vm/src/type_context.rs`:
- Around line 1-110: Add Rust unit tests for RuntimeTypeContext instead of
leaving this module untested; the review asks to cover it once it is wired, and
the best place is a #[cfg(test)] module alongside RuntimeTypeContext::new and
the TypeContext impl methods. Focus on small unit-level checks for alias_def,
implements_interface, interface_requires, and enum_variants, using a minimal
constructed BexVm test fixture so the tests stay local to this file and avoid
integration coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 84edd0b0-e63b-4734-b736-70ea7be39fc4

📥 Commits

Reviewing files that changed from the base of the PR and between 424b87b and f0e9b4d.

⛔ Files ignored due to path filters (2)
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap is excluded by !**/*.snap
📒 Files selected for processing (30)
  • baml_language/crates/baml_compiler2_emit/src/lib.rs
  • baml_language/crates/baml_compiler2_tir/src/builder.rs
  • baml_language/crates/baml_compiler2_tir/src/interfaces/impl_rules.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_engine/src/trace_heap.rs
  • baml_language/crates/bex_heap/src/accessor.rs
  • baml_language/crates/bex_heap/src/gc.rs
  • baml_language/crates/bex_heap/src/heap.rs
  • baml_language/crates/bex_heap/src/heap_debugger/real.rs
  • baml_language/crates/bex_vm/src/lib.rs
  • baml_language/crates/bex_vm/src/package_baml/csv.rs
  • baml_language/crates/bex_vm/src/package_baml/future.rs
  • baml_language/crates/bex_vm/src/package_baml/json.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/bex_vm/src/package_baml/ops.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/package_baml/root.rs
  • baml_language/crates/bex_vm/src/package_load.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/bex_vm/tests/interface_registry.rs
  • baml_language/crates/bex_vm_types/src/types.rs
  • baml_language/crates/bex_vm_types/src/types/interface.rs
  • baml_language/crates/bex_vm_types/src/types/object.rs
  • baml_language/crates/bex_vm_types/src/types/package.rs
  • baml_language/crates/tools_onionskin/src/compiler.rs
  • baml_language/crates/tools_sap_visualizer/src/compile.rs

2kai2kai2 added 9 commits July 1, 2026 13:24
If we don't know the resolved base type and/or interface types, we can
still do subtyping based on the associated type's interface bounds.
The runtime implementor of `baml_type::normalize::TypeContext` for
dynamically evaluating type algebra such as subtyping and equivalence.
WIP: `<RuntimeTypeContext as TypeContext>::interface_requires`
Similar to `Object::Class` and other program objects, this makes
packages, interfaces, and impl rules heap objects. This enables us to
have pointer-based identity where possible instead of always doing
name-based lookup.
- `Object::Package` is now the main path for looking up
  types/functions/interfaces by name, as well as any impl rules defined
  in the package.
- `Object::Interface` represents an interface definition and holds
  metadata for reflection.
- `Object::ImplRule` represents an `implement` block and can be used for
  dynamic type resolution.

WIP: emitting and using the new package-based lookup paths
- By-name lookups in the runtime should use the package lookup path then
  find the correct pointers off that.
- Removes now-redundant vm fields
We no longer need to load `resolved_class_names` to populate the
error/panic name-to-pointer registries since that is handled by the
package system now.
- Error/panic class ptrs are now `Arc<[...]>` instead of copied `Vec`
- Don't do an `O(n)` walk to find the interface for `impl_rules`, just
  use package interface lookup
- Delete some now-unused code
- Docs cleanup
@2kai2kai2
2kai2kai2 force-pushed the kai/unified-type-algebra branch from f0e9b4d to 8c9c7c6 Compare July 1, 2026 21:34
@vercel
vercel Bot temporarily deployed to Preview – beps July 1, 2026 21:35 Inactive
@2kai2kai2
2kai2kai2 enabled auto-merge July 1, 2026 21:41
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 1, 2026 21:42 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle July 1, 2026 21:54 Inactive
@2kai2kai2
2kai2kai2 added this pull request to the merge queue Jul 1, 2026
Merged via the queue into canary with commit cfafa66 Jul 1, 2026
53 checks passed
@2kai2kai2
2kai2kai2 deleted the kai/unified-type-algebra branch July 1, 2026 22:25

This branch was previously deployed

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