Skip to content

Eliminate parallel type algebra logic in runtime#4046

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

Eliminate parallel type algebra logic in runtime#4046
2kai2kai2 merged 9 commits into
canaryfrom
kai/unified-type-algebra

Conversation

@2kai2kai2

@2kai2kai2 2kai2kai2 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

The baml_type algebra is the only canonical type algebra and all parallel implementations in the runtime have now been eliminated (there are some other type algebra implementations that intentionally are different like SAP's attribute-aware normalization but that is separate)

Summary by CodeRabbit

  • Bug Fixes

    • Improved generic match runtime type testing and dispatch-guard selection to use invariant canonical type-argument equality (e.g., Opt<T> patterns).
    • Improved interface is checks so interface-based throws-contract validation behaves correctly (catchable interface values instead of contract panics).
    • Improved equality/matching for generic and interface types and ensured unresolved type projections don’t produce matches.
    • Enforced coercion-free numeric type behavior so numeric primitives are not treated as subtypes (only handled as coercions at the host/FFI boundary).
  • Tests

    • Updated and added coverage for generic subtype/typevar matching, numeric non-widening, and interface-based host callable contract errors.

@vercel

vercel Bot commented Jul 16, 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 21, 2026 10:53pm
promptfiddle Ready Ready Preview, Comment Jul 21, 2026 10:53pm
promptfiddle2 Ready Ready Preview, Comment Jul 21, 2026 10:53pm

Request Review

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

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR centralizes subtype and equivalence checks on canonical type contexts, removes legacy subtype helpers, changes generic and interface pattern lowering to invariant IsType matching, and refactors VM implementation resolution around ImplResolver.

Changes

Canonical type algebra and fact-free solving

Layer / File(s) Summary
Canonical normalization and inference
baml_language/crates/baml_type/..., baml_language/crates/baml_type_runtime/..., baml_language/crates/sys_jinja_types/...
Removes direct subtype methods, adds fail-closed NoFacts, and updates inference to use canonical subtype and equivalence operations.
Normalization coverage and documentation
baml_language/crates/baml_type/src/normalize/tests.rs, baml_language/crates/baml_type/src/family.rs, baml_language/crates/baml_type_macros/src/lib.rs
Adds literal and numeric non-widening subtype tests and updates subtype API documentation.

Invariant compiler type-test lowering

Layer / File(s) Summary
Generic and interface lowering
baml_language/crates/baml_compiler2_mir/src/lower.rs, baml_language/crates/baml_compiler2_emit/src/emit.rs
Emits invariant TypeArgRef templates, lowers resolved interfaces structurally, and replaces per-implementor guard chains with interface IsType checks.
Generic match expectations
baml_language/crates/baml_tests/...
Updates B-634 explanations and snapshot expectations for invariant canonical matching.

VM-backed implementation resolution

Layer / File(s) Summary
ImplResolver and runtime context
baml_language/crates/bex_vm/src/package_baml/resolve.rs, baml_language/crates/bex_vm/src/type_context.rs, baml_language/crates/bex_vm/src/package_baml/mod.rs
Moves implementation lookup, template matching, proof, reflection, and frame realization into ImplResolver; BexVm now implements TypeContext.
Resolver integrations
baml_language/crates/bex_vm/src/package_baml/ops.rs, baml_language/crates/bex_vm/src/package_baml/type_class.rs
Routes dispatch, equality, class membership, and implementor enumeration through VM-backed resolver instances.

Runtime IsType and virtual dispatch

Layer / File(s) Summary
Canonical runtime matching
baml_language/crates/bex_vm/src/type_match.rs, baml_language/crates/bex_vm/src/vm.rs
Removes legacy template matching, uses template_relates with invariant variance, and updates template substitution and virtual dispatch paths.

Host contract validation and boundary alignment

Layer / File(s) Summary
Host contract checks
baml_language/crates/bex_engine/src/lib.rs, baml_language/crates/bex_engine/tests/host_value_callable.rs
Uses VM-aware normalization for throws-contract checks and adds interface-membership coverage.
Numeric boundary documentation
baml_language/crates/bex_engine/src/conversion.rs, baml_language/crates/bex_external_types/src/host_return.rs, baml_language/crates/bex_sap/src/deserializer/coercer/array_helper.rs
Clarifies coercion-free subtype behavior and exact numeric representation handling.

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

Sequence Diagram(s)

sequenceDiagram
  participant Compiler
  participant BexVM
  participant ImplResolver
  participant TypeContext
  Compiler->>BexVM: emit invariant interface IsType template
  BexVM->>TypeContext: evaluate canonical type relation
  BexVM->>ImplResolver: resolve interface implementation
  ImplResolver->>TypeContext: compare templates and interface arguments
  TypeContext-->>ImplResolver: return equivalence or membership result
  ImplResolver-->>BexVM: return implementation or proof
Loading

Possibly related PRs

  • BoundaryML/baml#3702: Both PRs address runtime generic type-argument inference and interface dispatch plumbing.
  • BoundaryML/baml#3902: Both PRs modify generic-pattern dispatch-guard lowering around TypeArgRef and TypeArgRefOrWildcard.
  • BoundaryML/baml#4032: Both PRs update interface dispatch and type-equivalence handling in MIR and runtime resolution.

Poem

I’m a rabbit with templates, precise as can be,
Invariant type-args now match merrily.
Old wildcard trails fade into the night,
Interfaces resolve with canonical light.
VM paths hop through one resolver true.

🚥 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 accurately captures the main change: consolidating runtime type-algebra logic into a single canonical implementation.
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 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.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 25.5 MB 10.8 MB file 25.3 MB +247.6 KB (+1.0%) OK
packed-program Linux 🔒 17.1 MB 7.0 MB file 17.0 MB +39.0 KB (+0.2%) OK
baml-cli macOS 🔒 19.8 MB 9.4 MB file 19.6 MB +214.9 KB (+1.1%) OK
packed-program macOS 🔒 13.3 MB 6.2 MB file 13.2 MB +33.1 KB (+0.3%) OK
baml-cli Windows 🔒 21.3 MB 9.6 MB file 21.1 MB +206.8 KB (+1.0%) OK
packed-program Windows 🔒 14.2 MB 6.3 MB file 14.2 MB +39.0 KB (+0.3%) OK
bridge_wasm WASM 16.2 MB 🔒 4.4 MB gzip 4.4 MB +10.2 KB (+0.2%) 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

@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: 4

🤖 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_mir/src/lower.rs`:
- Around line 12468-12470: Update the RuntimeTy::Class conversion in the
surrounding lowering method to detect interface declarations, not only keys
present in self.interface_implementors. Seed or consult interface membership
from the declaration metadata so interfaces without local implementors still
convert to RuntimeTy::Interface and undergo membership checks.

In `@baml_language/crates/bex_vm/src/package_baml/ops.rs`:
- Around line 468-478: Add a regression test covering type equality where an
implementing type is absorbed by its interface: assert that type_of<Shape |
Sq>() equals type_of<Shape>() when Sq implements Shape. Place it alongside the
existing union-order equality coverage and exercise the Object::Type comparison
path using vm.equivalent semantics.

In `@baml_language/crates/bex_vm/src/package_baml/resolve.rs`:
- Around line 190-213: Update resolve_implements_rule so non-empty iface_args
return only when rule_args are equivalent; remove the fallback assignment and
return None after all candidates fail to match. Preserve the existing behavior
for empty interface arguments.

In `@baml_language/crates/bex_vm/src/type_match.rs`:
- Around line 100-106: Add a unit test covering union absorption for
ClassWithTypeArgs in addition to the existing class_type_args_are_invariant
coverage. Exercise the widened frame-argument comparison of Shape | Sq against
Shape and assert the expected type relationship, using the existing test setup
and helpers.
🪄 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: a2e8c157-c1c1-468b-bb73-84e51b9fe7ca

📥 Commits

Reviewing files that changed from the base of the PR and between 408b2be and 4d43c04.

⛔ Files ignored due to path filters (7)
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_match_typevar.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/iter_impl_generics_only.core.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__01_lexer__generic_match_typevar_arm.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__10_formatter__generic_match_typevar_arm.snap is excluded by !**/*.snap
📒 Files selected for processing (23)
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/lib.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_external_types/src/host_return.rs
  • baml_language/crates/bex_sap/src/deserializer/coercer/array_helper.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/type_class.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
💤 Files with no reviewable changes (1)
  • baml_language/crates/baml_type/src/lib.rs

Comment thread baml_language/crates/baml_compiler2_mir/src/lower.rs Outdated
Comment thread baml_language/crates/bex_vm/src/package_baml/ops.rs
Comment thread baml_language/crates/bex_vm/src/package_baml/resolve.rs
Comment thread baml_language/crates/bex_vm/src/type_match.rs

@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: 1

🤖 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/TYPE_SYSTEM_AUDIT.md`:
- Line 99: Remove audit finding 4.8 for the alleged E0139 double assignment and
remove its corresponding sequencing item in TYPE_SYSTEM_AUDIT.md. Keep the audit
consistent with diagnostic.rs, where IntegerLiteralOutOfRange uses E0150 and
ImplViolatesOrphanRule uses E0139; only update the evidence instead if the audit
is intentionally for an older revision.
🪄 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: 3abfbb3e-5389-4506-b8d8-43f4d6f94992

📥 Commits

Reviewing files that changed from the base of the PR and between 4d43c04 and bc17e15.

⛔ Files ignored due to path filters (7)
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_match_typevar.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/iter_impl_generics_only.core.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__01_lexer__generic_match_typevar_arm.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__10_formatter__generic_match_typevar_arm.snap is excluded by !**/*.snap
📒 Files selected for processing (24)
  • baml_language/TYPE_SYSTEM_AUDIT.md
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/lib.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_external_types/src/host_return.rs
  • baml_language/crates/bex_sap/src/deserializer/coercer/array_helper.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/type_class.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
💤 Files with no reviewable changes (1)
  • baml_language/crates/baml_type/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (19)
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/bex_vm/src/package_baml/type_class.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_vm/src/package_baml/ops.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/bex_vm/src/type_match.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_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs

Comment thread baml_language/TYPE_SYSTEM_AUDIT.md Outdated
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@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 (1)
baml_language/crates/bex_vm/src/type_match.rs (1)

2-3: 📐 Maintainability & Code Quality | 🔵 Trivial

cargo test --lib needs a full native toolchain. ring v0.17.14 currently fails to build without standard C headers like assert.h and stdint.h.

🤖 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_match.rs` around lines 2 - 3, Ensure the
native build prerequisites required by ring v0.17.14, including standard C
headers such as assert.h and stdint.h, are installed in the environment used by
cargo test --lib. Update the project’s test or CI setup rather than changing the
BexVm documentation comment.

Source: Coding guidelines

🤖 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/bex_vm/src/type_match.rs`:
- Around line 2-3: Ensure the native build prerequisites required by ring
v0.17.14, including standard C headers such as assert.h and stdint.h, are
installed in the environment used by cargo test --lib. Update the project’s test
or CI setup rather than changing the BexVm documentation comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a25b44d5-6b98-4501-98d2-93ec93447843

📥 Commits

Reviewing files that changed from the base of the PR and between bc17e15 and 8ed0178.

⛔ Files ignored due to path filters (7)
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_match_typevar.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/iter_impl_generics_only.core.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__01_lexer__generic_match_typevar_arm.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__10_formatter__generic_match_typevar_arm.snap is excluded by !**/*.snap
📒 Files selected for processing (24)
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/lib.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_external_types/src/host_return.rs
  • baml_language/crates/bex_sap/src/deserializer/coercer/array_helper.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/type_class.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/sys_jinja_types/src/evaluate_type/types.rs
💤 Files with no reviewable changes (1)
  • baml_language/crates/baml_type/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (19)
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/bex_vm/src/package_baml/type_class.rs
  • baml_language/crates/bex_sap/src/deserializer/coercer/array_helper.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_vm/src/package_baml/ops.rs
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/bex_vm/src/vm.rs

@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 (1)
baml_language/crates/bex_engine/tests/host_value_callable.rs (1)

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

Remove redundant explicit drop.

The explicit drop(arc); call is redundant here since arc will be automatically dropped on the very next line when it goes out of scope at the end of the function. Based on learnings, we should rely on Drop implementations automatically triggering when handles go out of scope.

🧹 Proposed fix
-    assert_host_callable_throw(&result);
-    drop(arc);
+    assert_host_callable_throw(&result);
🤖 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_engine/tests/host_value_callable.rs` at line 1053,
Remove the redundant explicit drop(arc) call in the surrounding test function
and rely on automatic scope-based destruction when arc goes out of scope; leave
the rest of the function unchanged.

Source: Learnings

🤖 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/bex_engine/tests/host_value_callable.rs`:
- Line 1053: Remove the redundant explicit drop(arc) call in the surrounding
test function and rely on automatic scope-based destruction when arc goes out of
scope; leave the rest of the function unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5ac127a0-f3fd-474a-a75e-498704243baa

📥 Commits

Reviewing files that changed from the base of the PR and between 8ed0178 and 2a0ddcc.

⛔ Files ignored due to path filters (7)
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_match_typevar.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/iter_impl_generics_only.core.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__01_lexer__generic_match_typevar_arm.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__10_formatter__generic_match_typevar_arm.snap is excluded by !**/*.snap
📒 Files selected for processing (24)
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/lib.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_external_types/src/host_return.rs
  • baml_language/crates/bex_sap/src/deserializer/coercer/array_helper.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/type_class.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/sys_jinja_types/src/evaluate_type/types.rs
💤 Files with no reviewable changes (1)
  • baml_language/crates/baml_type/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (18)
  • baml_language/crates/baml_tests/projects/compiles/generic_match_typevar_arm/generic_match_typevar_arm.baml
  • baml_language/crates/baml_type_macros/src/lib.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/bex_vm/src/package_baml/type_class.rs
  • baml_language/crates/sys_jinja_types/src/evaluate_type/types.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/baml_type/src/normalize/tests.rs
  • baml_language/crates/baml_type/src/runtime_ty.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/baml_type_runtime/src/lib.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_engine/src/lib.rs
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/bex_vm/src/vm.rs

We now just use `BexVm` directly
It was a "fix" that introduced covariance via type erasure to address a
case caused by lack of type normalization. Now that we have type
normalization via the canonical type algebra we can move towards
eliminating it.
@blacksmith-sh

This comment has been minimized.

- `StructuralEquivCtx` is the coarse-nominal context (coarse to handle
  cycles, we need a co/inductive solver to fully resolve)
- `ImplResolver` unifies free functions to cleanly thread the
  VM-references through
@2kai2kai2
2kai2kai2 force-pushed the kai/unified-type-algebra branch from 2ca1100 to d0f3f6c Compare July 21, 2026 22:26
@2kai2kai2
2kai2kai2 added this pull request to the merge queue Jul 21, 2026
Merged via the queue into canary with commit e318148 Jul 21, 2026
64 of 65 checks passed
@2kai2kai2
2kai2kai2 deleted the kai/unified-type-algebra branch July 21, 2026 22:43
codeshaunted added a commit that referenced this pull request Jul 21, 2026
Not the qualified path: `greet`, `bump`, `println`. Also adapts the
reflect native to canary's runtime type-algebra rework (#4046), where
the VM itself is the `TypeContext` and `RuntimeTypeContext` is gone.
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