Repository navigation
Reflection + matching on futures - #4225
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (23)
📒 Files selected for processing (30)
🚧 Files skipped from review as they are similar to previous changes (29)
📝 WalkthroughWalkthroughThis change preserves ChangesTyped Future Identity
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant SpawnLowering
participant BytecodeEmitter
participant VM
participant FutureManager
participant HeapFuture
participant TypeMatcher
SpawnLowering->>BytecodeEmitter: provide Future<T, E> templates
BytecodeEmitter->>VM: emit typed Spawn operands
VM->>FutureManager: allocate with returns and throws
FutureManager->>HeapFuture: store Future<T, E> metadata
TypeMatcher->>HeapFuture: read returns and throws for is/match
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
Binary size checks passed✅ 7 passed
Generated by |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 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_tir/src/builder.rs`:
- Around line 5456-5466: The throws lookup in lower_spawn_expr must preserve
diagnostic-first behavior for malformed spawn bodies instead of panicking.
Handle non-lambda or missing spawn bodies before lambda_effective_throws lookup,
using the existing Ty::Null approximation (or equivalent prior fallback), while
retaining the side-table throws type for valid inferred lambdas.
In `@baml_language/crates/bex_heap/src/gc.rs`:
- Around line 2232-2233: Update both UnscheduledFuture fixtures in
baml_language/crates/bex_heap/src/gc.rs at lines 2232-2233 and 2786-2787,
changing their throws type from RealizedTy::null() to RealizedTy::never() so
they consistently represent Future<T, never>.
In `@baml_language/TYPE_SYSTEM.md`:
- Around line 418-423: Update the out-of-body generic implementation example to
use the existing implement<T> syntax instead of implements<T>. Also correct the
constraint identifier on line 438 to preserve the declared Bound capitalization.
- Line 70: The invalid variance example should read from the widened array `b`,
not the original `int[]` array `a`. Update the assignment on the affected line
to use `b[1]`, preserving the intended demonstration that a `string` value can
be read as `int`.
- Line 337: Update the generic type-parameter requirement wording in the
function declarations section to allow parameters that are either explicitly
specified or unambiguously inferred from function-value context. Ensure it
aligns with the following `let c: (int) -> int = foo` example while retaining
the monomorphization requirement.
🪄 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 Plus
Run ID: a9f5014f-28a6-4e9b-ac0c-dd433833adfe
⛔ Files ignored due to path filters (23)
baml_language/crates/baml_tests/snapshots/baml_src/_root.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/cancel_cascade.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/cancel_token.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/defer.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/future_methods.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/future_types.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/http_server.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_basic.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_name_object.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_semantics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_throws.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/streaming_parsing.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/streaming_sse_primitives.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/task_group.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_ppir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_5_mir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____06_codegen.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_textual.snapis excluded by!**/*.snap
📒 Files selected for processing (29)
baml_language/TYPE_SYSTEM.mdbaml_language/crates/baml_builtins2/baml_std/testing/registry.bamlbaml_language/crates/baml_compiler2_emit/src/emit.rsbaml_language/crates/baml_compiler2_emit/src/stack_carry.rsbaml_language/crates/baml_compiler2_mir/src/builder.rsbaml_language/crates/baml_compiler2_mir/src/ir.rsbaml_language/crates/baml_compiler2_mir/src/lower.rsbaml_language/crates/baml_compiler2_mir/src/pretty.rsbaml_language/crates/baml_compiler2_tir/src/builder.rsbaml_language/crates/baml_compiler2_tir/src/interfaces/impl_rules.rsbaml_language/crates/baml_tests/baml_src/ns_future_types/future_types.bamlbaml_language/crates/baml_tests/baml_src/ns_spawn_semantics/spawn_semantics.bamlbaml_language/crates/baml_tests/src/compiler2_tir/phase8_exceptions.rsbaml_language/crates/baml_tests/tests/spawn_specialization.rsbaml_language/crates/baml_type/src/family.rsbaml_language/crates/baml_type/src/lib.rsbaml_language/crates/baml_type/src/realized_ty.rsbaml_language/crates/bex_engine/src/future.rsbaml_language/crates/bex_engine/src/lib.rsbaml_language/crates/bex_engine/tests/combinators.rsbaml_language/crates/bex_engine/tests/middleware.rsbaml_language/crates/bex_heap/src/gc.rsbaml_language/crates/bex_vm/src/package_reflect/mod.rsbaml_language/crates/bex_vm/src/type_match.rsbaml_language/crates/bex_vm/src/vm.rsbaml_language/crates/bex_vm_types/src/bytecode.rsbaml_language/crates/bex_vm_types/src/types/future.rsbaml_language/crates/bex_vm_types/src/types/object.rsbaml_language/sdk_tests/crates/.gitignore
35de669 to
26b66a0
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
baml_language/crates/baml_tests/src/compiler2_tir/phase8_exceptions.rs (1)
994-1043: 📐 Maintainability & Code Quality | 🔵 TrivialRun the required Rust library tests before merge.
Because this PR changes Rust code, run
cargo test --libfrom the workspace root.Also applies to: 1080-1080
🤖 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/src/compiler2_tir/phase8_exceptions.rs` around lines 994 - 1043, Run the required Rust library test suite from the workspace root with cargo test --lib, and ensure it passes before merging.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.
Inline comments:
In `@baml_language/TYPE_SYSTEM.md`:
- Around line 122-125: Update the match reachability and exhaustiveness rules
described in the documentation: guarded arms must be excluded from prior-pattern
coverage and exhaustiveness unions, but their patterns must still be checked for
provable reachability against earlier unguarded arms. Revise the wording around
`match` arm reachability and the `if`-guard behavior to distinguish these two
responsibilities.
---
Nitpick comments:
In `@baml_language/crates/baml_tests/src/compiler2_tir/phase8_exceptions.rs`:
- Around line 994-1043: Run the required Rust library test suite from the
workspace root with cargo test --lib, and ensure it passes before merging.
🪄 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 Plus
Run ID: d6ab3a23-d636-48a5-8c32-e7a30f7b6c41
⛔ Files ignored due to path filters (23)
baml_language/crates/baml_tests/snapshots/baml_src/_root.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/cancel_cascade.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/cancel_token.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/defer.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/future_methods.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/future_types.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/http_server.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_basic.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_name_object.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_semantics.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/spawn_throws.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/streaming_parsing.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/streaming_sse_primitives.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/baml_src/task_group.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_ppir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_5_mir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_tir.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____06_codegen.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snapis excluded by!**/*.snapbaml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_textual.snapis excluded by!**/*.snap
📒 Files selected for processing (30)
baml_language/TYPE_SYSTEM.mdbaml_language/crates/baml_builtins2/baml_std/testing/registry.bamlbaml_language/crates/baml_compiler2_ast/src/lower_expr_body.rsbaml_language/crates/baml_compiler2_emit/src/emit.rsbaml_language/crates/baml_compiler2_emit/src/stack_carry.rsbaml_language/crates/baml_compiler2_mir/src/builder.rsbaml_language/crates/baml_compiler2_mir/src/ir.rsbaml_language/crates/baml_compiler2_mir/src/lower.rsbaml_language/crates/baml_compiler2_mir/src/pretty.rsbaml_language/crates/baml_compiler2_tir/src/builder.rsbaml_language/crates/baml_compiler2_tir/src/interfaces/impl_rules.rsbaml_language/crates/baml_tests/baml_src/ns_future_types/future_types.bamlbaml_language/crates/baml_tests/baml_src/ns_spawn_semantics/spawn_semantics.bamlbaml_language/crates/baml_tests/src/compiler2_tir/phase8_exceptions.rsbaml_language/crates/baml_tests/tests/spawn_specialization.rsbaml_language/crates/baml_type/src/family.rsbaml_language/crates/baml_type/src/lib.rsbaml_language/crates/baml_type/src/realized_ty.rsbaml_language/crates/bex_engine/src/future.rsbaml_language/crates/bex_engine/src/lib.rsbaml_language/crates/bex_engine/tests/combinators.rsbaml_language/crates/bex_engine/tests/middleware.rsbaml_language/crates/bex_heap/src/gc.rsbaml_language/crates/bex_vm/src/package_reflect/mod.rsbaml_language/crates/bex_vm/src/type_match.rsbaml_language/crates/bex_vm/src/vm.rsbaml_language/crates/bex_vm_types/src/bytecode.rsbaml_language/crates/bex_vm_types/src/types/future.rsbaml_language/crates/bex_vm_types/src/types/object.rsbaml_language/sdk_tests/crates/.gitignore
🚧 Files skipped from review as they are similar to previous changes (24)
- baml_language/crates/baml_tests/baml_src/ns_spawn_semantics/spawn_semantics.baml
- baml_language/crates/baml_type/src/family.rs
- baml_language/crates/baml_compiler2_mir/src/pretty.rs
- baml_language/sdk_tests/crates/.gitignore
- baml_language/crates/baml_tests/tests/spawn_specialization.rs
- baml_language/crates/baml_compiler2_emit/src/stack_carry.rs
- baml_language/crates/baml_compiler2_tir/src/interfaces/impl_rules.rs
- baml_language/crates/bex_vm_types/src/bytecode.rs
- baml_language/crates/baml_compiler2_tir/src/builder.rs
- baml_language/crates/baml_builtins2/baml_std/testing/registry.baml
- baml_language/crates/bex_engine/tests/combinators.rs
- baml_language/crates/baml_compiler2_mir/src/ir.rs
- baml_language/crates/bex_vm/src/package_reflect/mod.rs
- baml_language/crates/baml_type/src/lib.rs
- baml_language/crates/baml_compiler2_mir/src/builder.rs
- baml_language/crates/bex_vm_types/src/types/object.rs
- baml_language/crates/baml_compiler2_emit/src/emit.rs
- baml_language/crates/bex_heap/src/gc.rs
- baml_language/crates/bex_engine/src/lib.rs
- baml_language/crates/bex_engine/tests/middleware.rs
- baml_language/crates/baml_tests/baml_src/ns_future_types/future_types.baml
- baml_language/crates/bex_engine/src/future.rs
- baml_language/crates/bex_vm/src/vm.rs
- baml_language/crates/baml_compiler2_mir/src/lower.rs
`spawn { 1 }` now has type `Future<int, never>` instead of `Future<int,
null>`. The body is infallible; while cancellation and other threading
failures are possible those are panics.
26b66a0 to
eec948e
Compare
Future objects now hold their return/error types. This allows us to properly reconstruct and match on the
Future<T, E>type. Also fixes the use ofnullinstead ofneveras the error type for infallible futures.Summary by CodeRabbit
ischecks andmatchexpressions can distinguish futures by type parameters (including through generic spawning and within arrays), with type info preserved through awaiting, reflection, and middleware.spawnexpression is incomplete.