Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move capture lowering from THIR to MIR #30

Closed
wants to merge 2 commits into from
Closed

Conversation

arora-aman
Copy link
Member

@arora-aman arora-aman commented Nov 17, 2020

This allows us to:

  • Handle precise Places captured by a closure directly in MIR. Handling
    captures in MIR is easier since we can rely on/ tweak PlaceBuilder to
    generate mir::Places that resemble how we store captures (hir::Place).

  • Handle let _ = x case when feature capture_disjoint_fields
    is enabled directly in MIR. This is required to be done in MIR since
    patterns are desugared in MIR.

Closes: rust-lang/project-rfc-2229#25


This change is Reviewable

Copy link
Member

@roxelo roxelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits but otherwise lgtm

// Access the capture by accessing the field within the Closure struct.
//
// We must have inferred the capture types since we are build MIR, therefore
// it's safe to call `upvar_tys` and we know can unwrap here because
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now


// Access the capture by accessing the field within the Closure struct.
//
// We must have inferred the capture types since we are build MIR, therefore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

building

This allows us to:
- Handle precise Places captured by a closure directly in MIR. Handling
captures in MIR is easier since we can rely on/ tweak PlaceBuilder to
generate `mir::Place`s that resemble how we store captures (`hir::Place`).
- Allows us to handle `let _ = x` case when feature `capture_disjoint_fields`
is enabled directly in MIR. This is required to be done in MIR since
patterns are desugared in MIR.
ExprKind::SelfRef was used to express accessing `self` in
the desugared Closure/Generator struct when lowering captures in THIR.

Since we handle captures in MIR now, we don't need `ExprKind::Self`.
@arora-aman
Copy link
Member Author

Fixed and created rust-lang PR here: rust-lang#79149

@arora-aman arora-aman closed this Nov 19, 2020
@arora-aman arora-aman deleted the upvar_ref branch November 22, 2020 09:26
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.

Move Upvar lowering from THIR to MIR
2 participants