Description
HIR lowering happens after name resolution, so we know the set of captures (aka "upvars" aka "freevars") of each closure. We could write them out in the closure expression/"definition" instead of keeping an extra map around, and we could also change the Def::Upvar
of their uses in the body, to use an index instead of referring to each captured local's original NodeId
/ HirId
.
This way I think we can have closure bodies completely disjoint from the bodies the closures are instantiated in, maybe even at the HirId
level. Ideally we would change the HIR in such a way that expr/pat/etc. nodes can't reference locals/labels across HirId
"owners".
That is, we have DefId
s for "global definitions" and everything else (ignoring the type-level signatures/where clauses etc. for the moment) lives in bodies that can't refer to eachother.