-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Capture precise paths in THIR and MIR #79553
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 3ac3ff2 with merge f76f72250e36c9ad4eb3bd3f08770228cc07da6c... |
☀️ Try build successful - checks-actions |
Queued f76f72250e36c9ad4eb3bd3f08770228cc07da6c with parent 28b86e0, future comparison URL. |
Finished benchmarking try commit (f76f72250e36c9ad4eb3bd3f08770228cc07da6c): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some initial comments
4c2eabd
to
097e490
Compare
@@ -2179,6 +2179,15 @@ impl<'tcx> TyS<'tcx> { | |||
} | |||
} | |||
|
|||
/// Get the `i`-th element of a tuple. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Computes the index of a capture within the desugared closure provided the closure's | ||
/// `closure_min_captures` and the capture's index of the capture in the | ||
/// `ty::MinCaptureList` of the root variable `var_hir_id`. | ||
fn compute_capture_idx<'tcx>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably be optimized by moving it into the min_capture map itself, so we move the table from looking like
root variable -> list of captures
to
root variarble -> { start_idx, list of captures }
where the start_idx
is essentially the index in min_capture
map for the first capture in the list of captures for the root variable.
@nikomatsakis updated |
- Derive TypeFoldable on `hir::place::Place` and associated structs, to them to be written into typeck results. Co-authored-by: Jennifer Wills <[email protected]> Co-authored-by: Logan Mosier <[email protected]>
- final_upvar_tys now reads types from places instead of using `node_ty` Co-authored-by: Roxane Fruytier <[email protected]>
097e490
to
487352b
Compare
- This allows us to delay figuring out the index of a capture in the closure structure when all projections to atleast form a capture have been applied to the builder Co-authored-by: Roxane Fruytier <[email protected]>
487352b
to
ef71437
Compare
Hey! Left a bunch of comments. Mostly nits and small suggestions, though there are a few points where I was confused. This is looking really good. :) |
ef71437
to
ad36cd2
Compare
I pushed changed in the same commit because there weren't any logical changes. Just the diff is here: https://github.com/sexxi-goose/rust/compare/ef71437..ad36cd2 |
/// start off of the same root variable. | ||
/// | ||
/// Eg: 1. `foo.x` which is represented using `projections=[Field(x)]` is an ancestor of | ||
/// `foo.x.y` which is represented using `prjections=[Field(x), Field(y)]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment
proj_possible_ancestor: &Vec<HirProjectionKind>, | ||
proj_capture: &Vec<HirProjectionKind>, | ||
) -> bool { | ||
// We want to make sure `is_ancestor_of_capture("x.0", "x.0.0")` not return true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_ancestor_or_same_capture("x.0.0", "x.0")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking very good. I am wondering if we want to do more tests.
src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-1.rs
Show resolved
Hide resolved
src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-2.rs
Show resolved
Hide resolved
src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-2.rs
Show resolved
Hide resolved
src/test/ui/closures/2229_closure_analysis/run_pass/simple-struct-min-capture.rs
Outdated
Show resolved
Hide resolved
- Use closure_min_capture maps to capture precise paths - PlaceBuilder now searches for ancestors in min_capture list - Add API to `Ty` to allow access to the n-th element in a tuple in O(1) time. Co-authored-by: Roxane Fruytier <[email protected]>
- Closures now use closure_min_captures to figure out captured paths - Build upvar_mutbls using closure_min_captures - Change logic in limit_capture_mutability to differentiate b/w capturing parent's local variable or capturing a variable that is captured by the parent (in case of nested closure) using PlaceBase. Co-authored-by: Roxane Fruytier <[email protected]>
- Use closure_min_captures to generate the Upvar structure that stores information for diagnostics and information about mutability of captures.
ad36cd2
to
0f60e68
Compare
@nikomatsakis updated. I added some more test cases:
|
0f60e68
to
01df563
Compare
@bors r+ |
📌 Commit 01df563 has been approved by |
☀️ Test successful - checks-actions |
/// DefId of the closure | ||
closure_def_id: DefId, | ||
/// The trait closure implements, `Fn`, `FnMut`, `FnOnce` | ||
closure_kind: ty::ClosureKind }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, how did rustfmt accept this formatting???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that...is a good question :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened rust-lang/rustfmt#4589.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've no idea whether this is intentional, but believe this file would be skipped entirely due the ignore settings specified in the rustfmt file since it's under a build
directory
Compare the build directory entry in rustfmt.toml vs the gitignore entry where the latter is limited to the root.
As I recall there were also some constraints added around which files get formatted and how due to the nature of some of the content within the repo. It's formatted fine when running rustfmt directly, so may want to check whether x.py fmt is actually running rustfmt on these files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah seems like a bug. Would be great to fix in a PR.
@arora-aman @nikomatsakis This changes seems to have caused a moderate regression in the clap benchmark. It looks like |
@rylev I had brought this in t-performance a while back, it's likely that this is because of extra data now being stored in TypeckResults, which adds more data that needs to get hashed in incr-compile mode. We are working de duplicating some of the information in TypeckResults, to hopefully being this back down :) |
This PR allows THIR and MIR to use the result of the new capture analysis to actually capture precise paths
To achieve we:
Closes: rust-lang/project-rfc-2229#10
Partly implements: rust-lang/project-rfc-2229#18
Work that remains (not in this PR):
r? @ghost