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

Use non-ascribed type as field's type in mir #103880

Merged
merged 12 commits into from Dec 16, 2022
Merged

Conversation

b-naber
Copy link
Contributor

@b-naber b-naber commented Nov 2, 2022

Fixes #96514

r? @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 2, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

compiler/rustc_mir_build/src/build/matches/util.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
}
Err(place_builder) => {
match &place_builder.projection[..] {
&[ProjectionElem::OpaqueCast(base_ty), ref projections @ ..] => Some(
Copy link
Contributor

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

Copy link
Contributor Author

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.

// NOTE: With type ascriptions it can happen that we get errors
// during borrow-checking on higher-ranked types if we use the
// ascribed type as the field type, so we try to get the actual field
// type from the `Place`, if possible, see issue #96514
Copy link
Contributor

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.

compiler/rustc_mir_build/src/build/matches/util.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/matches/util.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Nov 23, 2022

☔ The latest upstream changes (presumably #103947) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2022

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

@lcnr
Copy link
Contributor

lcnr commented Nov 24, 2022

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 24, 2022
@bors
Copy link
Contributor

bors commented Nov 24, 2022

⌛ Trying commit 9061ffb with merge 231fca09c3e445b08e289e6b8f254f38aa60052d...

@bors
Copy link
Contributor

bors commented Nov 24, 2022

☀️ Try build successful - checks-actions
Build commit: 231fca09c3e445b08e289e6b8f254f38aa60052d (231fca09c3e445b08e289e6b8f254f38aa60052d)

@@ -877,9 +877,9 @@ pub struct Place<'tcx> {

#[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> {
Copy link
Member

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.

@b-naber
Copy link
Contributor Author

b-naber commented Nov 26, 2022

Why has the perf run not finished yet?

@oli-obk

This comment was marked as resolved.

@rust-timer

This comment was marked as resolved.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 28, 2022

@rust-timer build 231fca09c3e445b08e289e6b8f254f38aa60052d

@bors
Copy link
Contributor

bors commented Nov 29, 2022

☀️ Try build successful - checks-actions
Build commit: 31b351e335795f9bb7ac7deac9b27e7010770610 (31b351e335795f9bb7ac7deac9b27e7010770610)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (31b351e335795f9bb7ac7deac9b27e7010770610): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking 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
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.3%, 0.3%] 1

Max RSS (memory usage)

Results

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.1% [6.8%, 7.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.8% [-2.2%, -1.5%] 2
All ❌✅ (primary) - - 0

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 29, 2022
@b-naber
Copy link
Contributor Author

b-naber commented Nov 30, 2022

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.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 30, 2022

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.

Copy link
Contributor

@lcnr lcnr left a 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.

compiler/rustc_middle/src/mir/syntax.rs Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/matches/util.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_place.rs Outdated Show resolved Hide resolved
@lcnr
Copy link
Contributor

lcnr commented Dec 16, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Dec 16, 2022

📌 Commit ff41359 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 16, 2022
@bors
Copy link
Contributor

bors commented Dec 16, 2022

⌛ Testing commit ff41359 with merge 03770f0...

@bors
Copy link
Contributor

bors commented Dec 16, 2022

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 03770f0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 16, 2022
@bors bors merged commit 03770f0 into rust-lang:master Dec 16, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 16, 2022
@b-naber b-naber deleted the field-ty-mir branch December 16, 2022 16:56
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (03770f0): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.1% [2.5%, 3.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-3.5%, -3.5%] 1
All ❌✅ (primary) - - 0

Cycles

Results

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.7% [1.0%, 2.8%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

@rustbot rustbot added the perf-regression Performance regression. label Dec 16, 2022
lqd added a commit to lqd/rust that referenced this pull request Dec 19, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2022
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`
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Use non-ascribed type as field's type in mir

Fixes rust-lang#96514

r? `@lcnr`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the type of ProjectionElem::Field is not correct wrt subtyping
7 participants