-
Notifications
You must be signed in to change notification settings - Fork 14k
Use non-ascribed type as field's type in mir #103880
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
Conversation
lcnr
left a comment
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.
thanks ❤️ a few nits
can you also add a test for infallible enum variants: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=62fcc4d83fb144317784e548798d86e9 and https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9cab784eee21f76c52fdbe0fb84f654d
and also enums with multiple variants: (not sure how that test should behave tbh) https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=74134c559bb8b169788b8ca5694674b3
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's clever but I am not sure whether it is necessary 🤔
afaict the only reason why this returns Err is if the upvar is not part of the final mir body so it doesn't affect mir borrowck.
I would prefer always returning None in the Err case i think
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 necessary for the following scenario (compiling with --edition==2021:
fn test1() {
let t = (String::from("Hello"), String::from("bla"));
let c = || {
let (t1, t2) = t;
//~^ WARN unused variable: `t1`
//~| WARN unused variable: `t2`
};
c();
}
where y is not captured as an upvar and we only get an OpaqueCast projection in the PlaceBuilder.
I'm not sure what the correct behaviour here is. One could argue that the name of the method implies a best-effort approach, so that we get the current type of the PlaceBuilder whenever possible, in which case these additional projections would be necessary.
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.
if my understanding is correct, this "if possible" is quite right, as getting the correct field type isn't relevant if try_ty returns None.
|
☔ The latest upstream changes (presumably #103947) made this pull request unmergeable. Please resolve the merge conflicts. |
05c37ff to
9061ffb
Compare
|
This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
⌛ Trying commit 9061ffb with merge 231fca09c3e445b08e289e6b8f254f38aa60052d... |
|
☀️ Try build successful - checks-actions |
| #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| #[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] | ||
| pub enum ProjectionElem<V, T> { | ||
| pub enum ProjectionElem<V, T1, T2> { |
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.
At this point it might be worth documenting what these types mean? Their names are not exactly descriptive.
|
Why has the perf run not finished yet? |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
@rust-timer build 231fca09c3e445b08e289e6b8f254f38aa60052d |
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (31b351e335795f9bb7ac7deac9b27e7010770610): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
|
Any thoughts on those perf results? Don't see any other options to improve perf and I think we would have a similar perf hit when "calculating" the place type for a field projection in other approaches. Getting the type while projecting seems to me the more reasonable approach compared to doing it during the simplify stage of mir building. |
|
This perf regression seems to be somewhere in the noise of that test. Afaict this PR is only blocked on trying out the hypothetical alternative designs (like re-using OpaqueCast). I don't know if @lcnr was going to do that or what the plan was. |
lcnr
left a comment
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.
a bunch of nits, I think the current design is fine and we don't have to test the OpaqueCast approach.
I think the core of my nits about clone_project and fresh infer var in field could be changed by changing PlaceBuilder::project to take ProjectionElem<Local, (), Ty<'tcx>> and then recomputing the field type in there.
Instead of requiring Builder for base_place.to_place you could move
cx.tcx.intern_place_elems(&builder.projection);
Some(Place { local, projection })into a separate function, maybe Place::new(tcx, local, projections) and only take a TyCtxt for project.
13619e6 to
ff41359
Compare
|
@bors r+ |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (03770f0): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
Revert rust-lang#103880 "Use non-ascribed type as field's type in mir" This PR prepares a revert for rust-lang#103880 to fix rust-lang#105809, rust-lang#105881, rust-lang#105886 and others (like the duplicates of the first one), in case an actual fix can't get done today. I've also added the MCVE from rust-lang#105809. There is no MCVE for the rust-lang#105881 and rust-lang#105886 ICEs yet however, so there are no tests for them here, although we'll need one before relanding the original changes. Were this PR to land, it would also reopen rust-lang#96514 as it was fixed by the original PR. Opening as draft to allow time for a possible fix. r? `@jackh726`
Use non-ascribed type as field's type in mir Fixes rust-lang#96514 r? `@lcnr`
Fixes #96514
r? @lcnr