-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Mark more locals as moved to avoid building drops for them. #158281
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
Open
cjgillot
wants to merge
5
commits into
rust-lang:main
Choose a base branch
from
cjgillot:drop-moved-locals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -86,6 +86,7 @@ use std::mem; | |
| use interpret::ErrorHandled; | ||
| use rustc_data_structures::fx::FxHashMap; | ||
| use rustc_hir::HirId; | ||
| use rustc_index::bit_set::GrowableBitSet; | ||
| use rustc_index::{IndexSlice, IndexVec}; | ||
| use rustc_middle::middle::region; | ||
| use rustc_middle::mir::{self, *}; | ||
|
|
@@ -137,7 +138,7 @@ struct Scope { | |
| /// end of the vector (top of the stack) first. | ||
| drops: Vec<DropData>, | ||
|
|
||
| moved_locals: Vec<Local>, | ||
| moved_locals: GrowableBitSet<Local>, | ||
|
|
||
| /// The drop index that will drop everything in and below this scope on an | ||
| /// unwind path. | ||
|
|
@@ -494,7 +495,7 @@ impl<'tcx> Scopes<'tcx> { | |
| source_scope: vis_scope, | ||
| region_scope, | ||
| drops: vec![], | ||
| moved_locals: vec![], | ||
| moved_locals: GrowableBitSet::new_empty(), | ||
| cached_unwind_block: None, | ||
| cached_coroutine_drop_block: None, | ||
| }); | ||
|
|
@@ -1522,7 +1523,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |
| self.schedule_drop(span, region_scope, local, DropKind::ForLint); | ||
| } | ||
|
|
||
| /// Indicates that the "local operand" stored in `local` is | ||
| /// Indicates that the "local operand" stored in `operand` is | ||
| /// *moved* at some point during execution (see `local_scope` for | ||
| /// more information about what a "local operand" is -- in short, | ||
| /// it's an intermediate operand created as part of preparing some | ||
|
|
@@ -1558,26 +1559,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |
| /// spurious borrow-check errors -- the problem, ironically, is | ||
| /// not the `DROP(_X)` itself, but the (spurious) unwind pathways | ||
| /// that it creates. See #64391 for an example. | ||
| pub(crate) fn record_operands_moved(&mut self, operands: &[Spanned<Operand<'tcx>>]) { | ||
| #[instrument(level = "debug", skip(self))] | ||
| pub(crate) fn record_operand_moved(&mut self, operand: &Operand<'tcx>) { | ||
| let local_scope = self.local_scope(); | ||
| let scope = self.scopes.scopes.last_mut().unwrap(); | ||
|
|
||
| assert_eq!(scope.region_scope, local_scope, "local scope is not the topmost scope!",); | ||
| assert_eq!(scope.region_scope, local_scope, "local scope is not the topmost scope!"); | ||
|
|
||
| // look for moves of a local variable, like `MOVE(_X)` | ||
| let locals_moved = operands.iter().flat_map(|operand| match operand.node { | ||
| Operand::Copy(_) | Operand::Constant(_) | Operand::RuntimeChecks(_) => None, | ||
| let local_moved = match operand { | ||
| Operand::Copy(_) | Operand::Constant(_) | Operand::RuntimeChecks(_) => return, | ||
| Operand::Move(place) => place.as_local(), | ||
| }); | ||
| }; | ||
|
|
||
| for local in locals_moved { | ||
| // check if we have a Drop for this operand and -- if so | ||
| // -- add it to the list of moved operands. Note that this | ||
| // local might not have been an operand created for this | ||
| // call, it could come from other places too. | ||
| if scope.drops.iter().any(|drop| drop.local == local && drop.kind == DropKind::Value) { | ||
|
Member
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. This |
||
| scope.moved_locals.push(local); | ||
| } | ||
| // We have a move of a local. Mark its drop to be skipped when leaving top scope. | ||
| // If `local` is not dropped by the topmost scope, this is a no-op. | ||
| if let Some(local) = local_moved { | ||
| scope.moved_locals.insert(local); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1878,7 +1875,7 @@ where | |
| // path, then don't generate the drop. (We only take this into | ||
| // account for non-unwind paths so as not to disturb the | ||
| // caching mechanism.) | ||
| if scope.moved_locals.contains(&local) { | ||
| if scope.moved_locals.contains(local) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -1922,7 +1919,7 @@ where | |
| // path, then don't generate the drop. (We only take this into | ||
| // account for non-unwind paths so as not to disturb the | ||
| // caching mechanism.) | ||
| if scope.moved_locals.contains(&local) { | ||
| if scope.moved_locals.contains(local) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.