-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make PlaceMention a non-mutating use. #110826
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,7 +410,7 @@ macro_rules! make_mir_visitor { | |
StatementKind::PlaceMention(place) => { | ||
self.visit_place( | ||
place, | ||
PlaceContext::NonUse(NonUseContext::PlaceMention), | ||
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention), | ||
location | ||
); | ||
} | ||
|
@@ -1251,6 +1251,11 @@ pub enum NonMutatingUseContext { | |
UniqueBorrow, | ||
/// AddressOf for *const pointer. | ||
AddressOf, | ||
/// PlaceMention statement. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth adding a clarifying comment on why this is here, given that it used to be in the wrong category. |
||
/// | ||
/// This statement is executed as a check that the `Place` is live without reading from it, | ||
/// so it must be considered as a non-mutating use. | ||
PlaceMention, | ||
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place. | ||
/// For example, the projection `x.y` is not marked as a mutation in these cases: | ||
/// ```ignore (illustrative) | ||
|
@@ -1301,8 +1306,6 @@ pub enum NonUseContext { | |
AscribeUserTy, | ||
/// The data of a user variable, for debug info. | ||
VarDebugInfo, | ||
/// PlaceMention statement. | ||
PlaceMention, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/mir-opt/dead-store-elimination/place_mention.main.DeadStoreElimination.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- // MIR for `main` before DeadStoreElimination | ||
+ // MIR for `main` after DeadStoreElimination | ||
|
||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/place_mention.rs:+0:11: +0:11 | ||
let mut _1: (&str, &str); // in scope 0 at $DIR/place_mention.rs:+3:18: +3:36 | ||
scope 1 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36 | ||
_1 = (const "Hello", const "World"); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36 | ||
// mir::Constant | ||
// + span: $DIR/place_mention.rs:8:19: 8:26 | ||
// + literal: Const { ty: &str, val: Value(Slice(..)) } | ||
// mir::Constant | ||
// + span: $DIR/place_mention.rs:8:28: 8:35 | ||
// + literal: Const { ty: &str, val: Value(Slice(..)) } | ||
PlaceMention(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36 | ||
StorageDead(_1); // scope 0 at $DIR/place_mention.rs:+3:36: +3:37 | ||
_0 = const (); // scope 0 at $DIR/place_mention.rs:+0:11: +4:2 | ||
return; // scope 0 at $DIR/place_mention.rs:+4:2: +4:2 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// unit-test: DeadStoreElimination | ||
// compile-flags: -Zmir-keep-place-mention | ||
|
||
// EMIT_MIR place_mention.main.DeadStoreElimination.diff | ||
fn main() { | ||
// Verify that we account for the `PlaceMention` statement as a use of the tuple, | ||
// and don't remove it as a dead store. | ||
let (_, _) = ("Hello", "World"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Looks like we're going from invariant to covariant here? If intentional, probably a behavior change that would need a types FCP?
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'd consider this more of a bugfix for #104844, which is still on nightly.
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.
Ok, I'm going to cc @rust-lang/types here to get some eyes on this. From my understanding it's probably fine, but I'm definitely not a qualified reviewer
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.
being covariant is fine here 👍