Skip to content

runtime: mint type identity — TypeValue/MintId + unified eq (BEP-066 s1, PR 4) - #4331

Merged
antoniosarosi merged 2 commits into
antonio/s1-reflect-homefrom
antonio/s1-mint-identity
Aug 7, 2026
Merged

runtime: mint type identity — TypeValue/MintId + unified eq (BEP-066 s1, PR 4)#4331
antoniosarosi merged 2 commits into
antonio/s1-reflect-homefrom
antonio/s1-mint-identity

Conversation

@antoniosarosi

@antoniosarosi antoniosarosi commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

BEP-066 slice-1 stack, PR 4 of 5 — chained on #4330. Implements the ratified identity design (I-1/I-2/I-4/I-9): type values carry a mint token, and all three equality routes compare mints.

Design

  • Object::TypeBox<TypeValue { ty: RealizedTy, mint: MintId }> (64-byte Object assert intact; no anchors/defs — slice 2).
  • MintId::Static(u64): FNV-1a-64 (fixed offset/prime, big-endian numeric tokens) over NormalTy::canonical with the VM's program facts as TypeContext + a per-VM spelling-keyed digest cache — so type.of<string?>() == type.of<string | null>() and every reference to a static declaration shares one mint (I-2), process-independently.
  • MintId::Runtime(u64): shared AtomicU64 on BexHeap (spawned VMs covered). No producer yet — the constructors land in slice 2; distinctness pinned at the Rust level.
  • BexVm::alloc_static_type is the single constructor — no site can forget the mint. Wire/FFI strip mints outbound, re-derive inbound (H-4: identity never crosses); Program borsh unchanged.

The three eq routes, unified atomically

CmpOp::{Eq,NotEq} (vm.rs) · EqualsDriver (ops.rs) · baml.deep_equals (root.rs) — all mint-only, plus TypeValue::{PartialEq,Eq,Hash}. Observable consequence, pinned by the flipped PR-1 characterization tests: permuted unions stay equal under == and deep_equals flips false→true (was syntactic). GC/deep-copy preserve the full TypeValue.

Gates

Full baml_tests (1,486 lib + all binaries + 2,633 CLI cases) · bex_vm 21 + load_type 5 · bex_heap · bex_engine 109 · bex_vm_types 42 · project 82 — all green. Touched-crate clippy -D warnings, fmt, rustdoc -D warnings clean. Zero snapshot churn (mint is invisible to compilation, as designed).

Implemented by a Codex (gpt-5.6-sol) worker under stack-manager review.

Summary by CodeRabbit

  • New Features

    • Added consistent identity handling for reflected type values.
    • Equivalent type definitions now share stable identities across evaluation, reflection, host calls, and serialization.
    • Static and runtime type identities are kept distinct where appropriate.
  • Bug Fixes

    • Updated deep equality so equivalent union types compare equal regardless of member order.
    • Ensured optional types and explicit nullable unions resolve to the same identity.
    • Preserved type identity through garbage collection and value conversion.
  • Tests

    • Expanded coverage for canonical type equality, reflection, serialization, and cross-runtime behavior.

@vercel

vercel Bot commented Aug 6, 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 Aug 7, 2026 5:33am
promptfiddle2 Ready Ready Preview Aug 7, 2026 5:33am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3839c7ab-66c3-4781-9576-ad6470389d3a

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
📝 Walkthrough

Walkthrough

The PR adds TypeValue and minted type identities, computes deterministic static identities from canonical types, and updates VM, heap, host conversion, equality, serialization, reflection, and tests to use mint-based semantics.

Changes

Minted Type Identity

Layer / File(s) Summary
Type identity and canonical digest
baml_language/crates/baml_type/normalize.rs, baml_language/crates/bex_vm_types/src/types/..., baml_language/crates/bex_heap/src/heap.rs
Defines MintId and TypeValue, adds deterministic canonical_digest, preserves type wire compatibility, and adds heap-wide runtime mint allocation.
VM allocation and equality paths
baml_language/crates/bex_vm/src/vm.rs, baml_language/crates/bex_vm/src/package_baml/..., baml_language/crates/bex_vm/tests/..., baml_language/crates/baml_tests/...
Uses cached static mints for VM type allocation. Runtime equality and deep equality compare mints. Reflection and type-loading tests validate canonical identity behavior.
Heap and host-boundary integration
baml_language/crates/bex_heap/src/{accessor.rs,tlab.rs,gc.rs}, baml_language/crates/bex_engine/src/{conversion.rs,lib.rs}
Stores TypeValue in heap objects, extracts only realized types for external values, and recreates static identities when values return to a VM.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: 2kai2kai2, codeshaunted, hellovai

Poem

I’m a rabbit with a minted type,
Canonical hops from left to right.
Unions reorder, yet identities stay,
Deep equals joins the same array.
Fresh VM borders mint anew—
A tidy burrow, stable through and through.

🚥 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 summarizes the main change: minted runtime type identity with TypeValue, MintId, and unified equality for BEP-066.
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 antonio/s1-mint-identity

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.

@antoniosarosi

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

github-actions Bot commented Aug 6, 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 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 (3)
baml_language/crates/bex_vm/src/vm.rs (1)

756-765: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Consider bounding static_mint_cache for long-lived VMs.

static_mint_cache has no eviction policy. LoadType runs on every generic call, and each distinct spelled RealizedTy gets its own cache entry for the life of the BexVm. A long-lived VM (reused across many calls, or exposed to dynamically compiled/grafted packages with many concrete type instantiations) can grow this cache without bound.

Cache entries are pure memoization (a stale/evicted entry only costs a re-walk, never a correctness issue), so a size cap or periodic clear is safe to add.

Also applies to: 1300-1312

🤖 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/vm.rs` around lines 756 - 765, Bound the
`static_mint_cache` used by `BexVm` so repeated `LoadType` calls cannot grow it
without limit. Add a fixed capacity or periodic eviction/clear policy at the
cache insertion path near the `LoadType` handling around the referenced symbols,
while preserving cache hits and recomputing evicted digests through the existing
canonicalization flow.
baml_language/crates/baml_tests/baml_src/ns_type_reflection/type_reflection.baml (1)

111-113: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the stale syntactic test names.

These tests now assert canonical mint equality, not syntactic inequality. Rename union_order_deep_equals_syntactic_in_function and union_order_deep_equals_syntactic_in_test_block so test names match the behavior.

Also applies to: 119-119

🤖 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/baml_src/ns_type_reflection/type_reflection.baml`
around lines 111 - 113, Rename the stale test functions
union_order_deep_equals_syntactic_in_function and
union_order_deep_equals_syntactic_in_test_block to remove “syntactic” and
reflect canonical mint equality, while preserving their assertions and behavior.
baml_language/crates/bex_vm/tests/load_type.rs (1)

139-146: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the static mint value, not only its variant.

The test description says LoadType(int) produces a deterministic static mint. matches!(type_value.mint(), MintId::Static(_)) only checks the variant. Capture a second LoadType(int) result and assert that both MintId values are equal, preferably across two VM instances.

🤖 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/tests/load_type.rs` around lines 139 - 146,
Strengthen the LoadType(int) test around the Object::Type branch by executing
the same load in a second VM instance, capturing both results from
type_value.mint(), and asserting the complete MintId values are equal. Retain
the existing RealizedTy::int() assertion while replacing the variant-only
MintId::Static(_) check with a deterministic-value comparison.
🤖 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/baml_src/ns_type_reflection/type_reflection.baml`:
- Around line 111-113: Rename the stale test functions
union_order_deep_equals_syntactic_in_function and
union_order_deep_equals_syntactic_in_test_block to remove “syntactic” and
reflect canonical mint equality, while preserving their assertions and behavior.

In `@baml_language/crates/bex_vm/src/vm.rs`:
- Around line 756-765: Bound the `static_mint_cache` used by `BexVm` so repeated
`LoadType` calls cannot grow it without limit. Add a fixed capacity or periodic
eviction/clear policy at the cache insertion path near the `LoadType` handling
around the referenced symbols, while preserving cache hits and recomputing
evicted digests through the existing canonicalization flow.

In `@baml_language/crates/bex_vm/tests/load_type.rs`:
- Around line 139-146: Strengthen the LoadType(int) test around the Object::Type
branch by executing the same load in a second VM instance, capturing both
results from type_value.mint(), and asserting the complete MintId values are
equal. Retain the existing RealizedTy::int() assertion while replacing the
variant-only MintId::Static(_) check with a deterministic-value comparison.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a8541de1-8d02-407b-be2b-717621b73c1a

📥 Commits

Reviewing files that changed from the base of the PR and between 1ffa345 and 5304e45.

📒 Files selected for processing (19)
  • baml_language/crates/baml_tests/baml_src/ns_type_reflection/type_reflection.baml
  • baml_language/crates/baml_tests/tests/type_value_equality.rs
  • baml_language/crates/baml_type/src/normalize.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_engine/src/lib.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/tlab.rs
  • baml_language/crates/bex_vm/src/package_baml/ops.rs
  • baml_language/crates/bex_vm/src/package_baml/reflect.rs
  • baml_language/crates/bex_vm/src/package_baml/root.rs
  • baml_language/crates/bex_vm/src/package_baml/type_class.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/bex_vm/tests/load_type.rs
  • baml_language/crates/bex_vm/tests/method_class_type_args.rs
  • baml_language/crates/bex_vm_types/src/types.rs
  • baml_language/crates/bex_vm_types/src/types/object.rs
  • baml_language/crates/bex_vm_types/src/types/type_value.rs

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 27.9 MB 11.9 MB file 27.4 MB +566.8 KB (+2.1%) OK
packed-program Linux 🔒 18.2 MB 7.5 MB file 17.7 MB +480.3 KB (+2.7%) OK
baml-cli macOS 🔒 21.7 MB 10.4 MB file 21.3 MB +445.3 KB (+2.1%) OK
packed-program macOS 🔒 14.2 MB 6.6 MB file 13.8 MB +376.3 KB (+2.7%) OK
baml-cli Windows 🔒 23.3 MB 10.6 MB file 23.0 MB +380.3 KB (+1.7%) OK
packed-program Windows 🔒 15.2 MB 6.7 MB file 14.8 MB +375.3 KB (+2.5%) OK
bridge_wasm WASM 17.2 MB 🔒 4.7 MB gzip 4.6 MB +53.5 KB (+1.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

…e) (#4334)

**BEP-066 slice-1 stack, PR 5 of 5 — the capstone.** Chained on #4331.
With this green, the slice-1 stack is complete: the reflection read API
(K/V/N rule families) is fully live.

## What
- **Grammar carve-out**: `class`/`enum`/`interface`/`function` legal as
path segments after `.` across type parsing, expression paths, patterns,
map entries, generic lookahead, AST lowering, and formatting — bare
keywords still rejected.
- **The nine sealed kind classes** (`reflect.class.Type` …
`reflect.function.Type`) + the closed `baml.reflect.TypeKind` union
alias; identity-preserving `kind()` (K-5), all nine nullable `as_*()`
(K-6 — never throw), `as_type()`.
- **The one type-system fact**: kind class `<: type` sealed edge in
shared normalization; `Object::Type` reports its precise kind class
while keeping the physical TYPE tag; `implement … for type` preserved by
teaching impl resolution to follow the sealed edge (`to_string()`
verified on all nine kinds).
- **Read-back (C-15)**: fields/values/member_types/element_type/params
natives for all nine kinds; generic class fields substituted before
read-back; function.Type has ordered params + return, no throws (K-11).
New `docstring` + string-valued `other` columns on
Class/Field/Enum/Variant; emit preserves aliases, descriptions,
docstrings, and custom annotations (found + fixed + pinned a
pre-existing hoist bug where the custom-attribute path consumed
`stream.*`).
- Kind classes non-constructible with a dedicated diagnostic.

## Oracle coverage
Exhaustive nine-arm `TypeKind` match + missing-arm diagnostics · every
`as_*` positive/null path · mint identity through `kind().as_type()`
(I-2 × K-5) · non-throwing accessor contracts · full metadata read-back
· conformance queries · recursive type walking · `of_value` precision.

## Gates
Full corpus + parser + LSP (reviewed) + all-features baml_cli + tir +
project green; fmt/clippy/rustdoc clean; snapshot accepts grouped in the
commit (new type_kinds corpus + describe-listing growth).

Implemented by a Codex (gpt-5.6-sol) worker under stack-manager review.
**Both BEP-066 foundation stacks are now complete at 5/5.**

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added comprehensive runtime reflection for classes, enums, unions,
literals, arrays, maps, interfaces, primitives, and functions.
* Type values now expose their kind and provide kind-specific views and
nested type information.
* Added access to fields, parameters, enum values, metadata, aliases,
documentation, and custom annotations.
* Added validation preventing direct construction of reflection-kind
values.
  * Expanded support for keyword-based names in qualified paths.

* **Bug Fixes**
* Improved type alias handling, metadata propagation, and reflection
type matching.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@antoniosarosi
antoniosarosi merged commit a478cd4 into antonio/s1-reflect-home Aug 7, 2026
4 of 6 checks passed
@antoniosarosi
antoniosarosi deleted the antonio/s1-mint-identity branch August 7, 2026 05:25
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