Skip to content

fix: record closure Ty in type table after instance traversal#129

Draft
Stevengre wants to merge 6 commits intomasterfrom
jh/closure-type-metadata
Draft

fix: record closure Ty in type table after instance traversal#129
Stevengre wants to merge 6 commits intomasterfrom
jh/closure-type-metadata

Conversation

@Stevengre
Copy link
Contributor

@Stevengre Stevengre commented Feb 28, 2026

Summary

After resolving a closure instance in TyCollector::visit_ty, record the closure's Ty, kind, and layout shape in the types collection before returning.

Context

In TyCollector::visit_ty, the RigidTy::Closure arm resolves the closure instance via Instance::resolve_closure and then calls self.visit_instance(instance). However, after visiting the instance, the method returned immediately without inserting the closure's Ty into the types map.

For other type kinds (e.g. structs, tuples), the Ty is recorded in the types map either by the default visit_ty path 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 types map for type metadata lookup during constant decoding. When a zero-sized closure constant is decoded, kmir calls lookupTy(closureTy). Without the entry, this returns typeInfoVoidType, causing the closure to be thunked instead of decoded as Aggregate(variantIdx(0), .List).

Without this fix, zero-sized closure constants are decoded as thunks:

lookupTy(closureTy) => typeInfoVoidType
-- closure decoded as thunk(operandCopy(...)) instead of Aggregate(variantIdx(0), .List)
-- downstream projection traversal gets stuck

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
  • mir-semantics integration tests after submodule bump

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