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

mir opt + codegen: handle subtyping #112307

Merged
merged 5 commits into from
Jun 28, 2023
Merged

mir opt + codegen: handle subtyping #112307

merged 5 commits into from
Jun 28, 2023

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jun 5, 2023

fixes #107205

the same issue was caused in multiple places:

  • mir opts: both copy and destination propagation
  • codegen: assigning operands to locals (which also propagates values)

I changed codegen to always update the type in the operands used for locals which should guard against any new occurrences of this bug going forward. I don't know how to make mir optimizations more resilient here. Hopefully the added tests will be enough to detect any trivially wrong optimizations going forward.

@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@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 Jun 5, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@lcnr
Copy link
Contributor Author

lcnr commented Jun 5, 2023

@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 Jun 5, 2023
@bors
Copy link
Contributor

bors commented Jun 5, 2023

⌛ Trying commit b47112e337af38985998a9c2cb8b0663da9bfdee with merge 688ecdd88c9c98c0dd3ed5f53d5180535c63086b...

@bors
Copy link
Contributor

bors commented Jun 5, 2023

☀️ Try build successful - checks-actions
Build commit: 688ecdd88c9c98c0dd3ed5f53d5180535c63086b (688ecdd88c9c98c0dd3ed5f53d5180535c63086b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (688ecdd88c9c98c0dd3ed5f53d5180535c63086b): 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-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
Regressions ❌
(secondary)
1.9% [1.9%, 1.9%] 1
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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.8% [-1.8%, -1.8%] 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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.7% [-5.2%, -4.2%] 5
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 646.615s -> 645.351s (-0.20%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 5, 2023
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the operand-ref branch 2 times, most recently from 29ef7e2 to a4fc594 Compare June 9, 2023 11:16
@lcnr lcnr added A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) T-types Relevant to the types team, which will review and decide on the PR/issue. labels Jun 9, 2023
@lcnr
Copy link
Contributor Author

lcnr commented Jun 9, 2023

@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 Jun 9, 2023
@bors
Copy link
Contributor

bors commented Jun 9, 2023

⌛ Trying commit a4fc594dfeaa7cee6b4aa2769ab282b183a7eaf7 with merge 26bd1b92367a2173690199389c3e1e44a1ce759b...

@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor Author

lcnr commented Jun 9, 2023

@bors try @rust-timer queue

@lcnr
Copy link
Contributor Author

lcnr commented Jun 15, 2023

yeah, agree with that 👍 we should add a mir pass post analysis which makes subtyping explicit, opened #112651 for that. I don't have the capacity to actually implement this though, so I would like for someone else to take that over.

I would still like to merge this PR (putting a FIXME(#112651) at every place which should be changed once subtyping is explicit) given that it still fixes the unsoundness. I also think that extracting Locals into a private module is a positive change regardless. Checking the type of LocalRef::Operand detected another 'bug' (using wrong types in shims) and we can change overwrite_local to assert that the types are equal instead afterwards.

does this seem sensible to you @cjgillot?

@cjgillot
Copy link
Contributor

I agree to do it that way.

@lcnr
Copy link
Contributor Author

lcnr commented Jun 19, 2023

add a bunch of FIXME(#112651) to everything that should be changed/reverted after #112651.

@rustbot ready

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Everything looks good.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 27, 2023

📌 Commit 46973c9 has been approved by compiler-errors

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 Jun 27, 2023
@bors
Copy link
Contributor

bors commented Jun 28, 2023

⌛ Testing commit 46973c9 with merge bb95b7d...

@bors
Copy link
Contributor

bors commented Jun 28, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing bb95b7d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 28, 2023
@bors bors merged commit bb95b7d into rust-lang:master Jun 28, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 28, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bb95b7d): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

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)
- - 0
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
-2.7% [-3.6%, -1.8%] 2
All ❌✅ (primary) -1.5% [-1.5%, -1.5%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 662.939s -> 662s (-0.14%)

@lcnr lcnr deleted the operand-ref branch June 28, 2023 08:31
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 12, 2023
Remove assert that checks type equality

rust-lang#112307 although this prevented `unsound` issues it also seems to introduce regressions rust-lang#114858 is example of this regression. I locally tested this rust-lang#114858 (comment) issue and failing assert is [this](https://www.diffchecker.com/cjb7jSQm/).

This is also related to rust-lang#115025
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 15, 2023
Remove assert that checks type equality

rust-lang/rust#112307 although this prevented `unsound` issues it also seems to introduce regressions rust-lang/rust#114858 is example of this regression. I locally tested this rust-lang/rust#114858 (comment) issue and failing assert is [this](https://www.diffchecker.com/cjb7jSQm/).

This is also related to rust-lang/rust#115025
op.layout.ty = local_ty;
}
}
};
Copy link
Member

Choose a reason for hiding this comment

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

FWIW in the MIR interpreter we avoid the risk of this by not having the type of the local in our locals map to begin with: we store a IndexVec<mir::Local, LocalState<'tcx, Prov>>, where LocalState is basically just interpret::Operand. When we need the type we always go through body.local_decls.

So that might also be something codegen can do; storing the type in self.locals is redundant.

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 1, 2023
…fleLapkin

explain a good reason for why LocalValue does not store the type of the local

As found out by `@lcnr` in rust-lang#112307, storing the type here can lead to subtle bugs when it gets out of sync with the MIR body. That's not the reason why the interpreter does it this way I think, but good thing we dodged that bullet. :)
bors added a commit to rust-lang/miri that referenced this pull request Dec 2, 2023
explain a good reason for why LocalValue does not store the type of the local

As found out by `@lcnr` in rust-lang/rust#112307, storing the type here can lead to subtle bugs when it gets out of sync with the MIR body. That's not the reason why the interpreter does it this way I think, but good thing we dodged that bullet. :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) merged-by-bors This PR was explicitly merged by bors. 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. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codegen generates vtables for a variable's supertype when unsizing sometimes
9 participants