fix(rt): closure type metadata decode + setupCalleeClosure3#957
Draft
fix(rt): closure type metadata decode + setupCalleeClosure3#957
Conversation
… closures stable-mir-json wasn't recording closure Ty entries in the type table, so zero-sized closure constants decoded to thunks. Additionally, the existing setupCalleeClosure rules didn't handle the case where the closure pointee type resolves to a known typeInfoFunType (as opposed to typeInfoVoidType). Changes: - Add zero-sized typeInfoFunType constant decode rule (data.md) - Add setupCalleeClosure3 rule for typed closure environments (kmir.md) - Add isFunType function declaration and rules - Fix isTypedLocal -> isTypedValue guards on existing closure rules - Add #setLocalValue for closure environment in all setupCalleeClosure rules - Remove unused Span parameter from #execTerminatorCall, #setUpCalleeData, and #execIntrinsic signatures (cleanup, no behavior change) Test: iter-eq-copied-take-dereftruncate-fail.rs Note: The new setupCalleeClosure3 rule requires a stable-mir-json submodule bump (separate PR) to be exercised at runtime.
This was referenced Feb 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for typed closure environments in the call setup path, and clean up the
Spanparameter threading.typeInfoFunTypeconstant decode rule (data.md)setupCalleeClosure3rule for closures whose pointee type resolves totypeInfoFunType(kmir.md)isFunTypefunction declaration and rulesisTypedLocal→isTypedValueguards on existingsetupCalleeClosurerules#setLocalValuefor closure environment initialization in allsetupCalleeClosurerulesSpanparameter from#execTerminatorCall,#setUpCalleeData, and#execIntrinsic(cleanup)iter-eq-copied-take-dereftruncate-fail.rstestContext
When stable-mir-json records closure type metadata (via the companion PR stable-mir-json#129), the closure's
Tyentry appears in the type table astypeInfoFunType(...). The existingsetupCalleeClosurerules only matched when the closure pointee type wastypeInfoVoidType(missing from type table) — with proper metadata present, no rule matched and call setup got stuck.The fix adds
setupCalleeClosure3at priority 46 that matches whenisFunType(#lookupMaybeTy(pointeeTy(...)))is true. This follows the same pattern as existing rules but handles the case where type metadata is available.The
isTypedLocal→isTypedValuefix is necessary because closure locals may benewLocal(...)(reserved but not yet assigned), andisTypedLocalrequires a fully typed value.isTypedValueis the correct check since it matches both initialized typed values andnewLocalentries.Additionally, the existing rules did not initialize local
_1(the closure environment). Rustc's calling convention places the closure environment in_1and the argument tuple in_2. The fix adds#setLocalValue(place(local(1), ...), ...)before#setTupleArgs.The
Spanparameter removal is a cleanup —Spanwas threaded through#execTerminatorCall→#setUpCalleeData→#execIntrinsicbut never used in any rule body. Removing it simplifies the signatures.Without this fix (after stable-mir-json provides closure types), closure calls get stuck:
With this fix,
setupCalleeClosure3matches and the closure call proceeds correctly.Note: The new
setupCalleeClosure3rule is safe dead code until stable-mir-json#129 is merged and the submodule is bumped. Without the submodule bump, closure types remaintypeInfoVoidTypeand the existing rules handle them.Related PRs
Test plan
-failtest (proof advances further)make test-integrationregression