fix: record closure Ty in type table after instance traversal#129
Draft
fix: record closure Ty in type table after instance traversal#129
Conversation
After resolving a closure instance, the visitor early-returned without inserting the closure's Ty into the types collection. This caused downstream consumers (kmir) to miss closure type metadata, leading to thunked zero-sized constants that blocked execution. Now the closure's Ty, kind, and layout shape are recorded in the type table after successful instance traversal.
Draft
3 tasks
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
After resolving a closure instance in
TyCollector::visit_ty, record the closure'sTy, kind, and layout shape in thetypescollection before returning.Context
In
TyCollector::visit_ty, theRigidTy::Closurearm resolves the closure instance viaInstance::resolve_closureand then callsself.visit_instance(instance). However, after visiting the instance, the method returned immediately without inserting the closure'sTyinto thetypesmap.For other type kinds (e.g. structs, tuples), the
Tyis recorded in thetypesmap either by the defaultvisit_typath or by explicit insertion. Closures were the exception — their instance was traversed (collecting inner types) but the closure type itself was never recorded.Downstream consumers (kmir) rely on the
typesmap for type metadata lookup during constant decoding. When a zero-sized closure constant is decoded, kmir callslookupTy(closureTy). Without the entry, this returnstypeInfoVoidType, causing the closure to be thunked instead of decoded asAggregate(variantIdx(0), .List).Without this fix, zero-sized closure constants are decoded as thunks:
With this fix, the closure type is recorded in the type table, and downstream consumers can look up the correct
typeInfoFunType(...)metadata.Related PRs
Test plan
cargo build/cargo test