Skip to content

Pass closure captures explicitly in HIR, and refer to them by index, not local ID. #53553

Closed
@eddyb

Description

@eddyb

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

cc @nikomatsakis @michaelwoerister

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-HIRArea: The high-level intermediate representation (HIR)A-closuresArea: Closures (`|…| { … }`)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions