-
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
Move the extended lifetime resolution into typeck context #95563
Merged
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::middle::region::{Scope, ScopeData, ScopeTree}; | ||
use rustc_data_structures::fx::FxHashMap; | ||
use rustc_hir as hir; | ||
|
||
/// `RvalueScopes` is a mapping from sub-expressions to _extended_ lifetime as determined by | ||
/// rules laid out in `rustc_typeck::check::rvalue_scopes`. | ||
#[derive(TyEncodable, TyDecodable, Clone, Debug, Default, Eq, PartialEq, HashStable)] | ||
pub struct RvalueScopes { | ||
map: FxHashMap<hir::ItemLocalId, Option<Scope>>, | ||
} | ||
|
||
impl RvalueScopes { | ||
pub fn new() -> Self { | ||
Self { map: <_>::default() } | ||
} | ||
|
||
/// Returns the scope when the temp created by `expr_id` will be cleaned up. | ||
pub fn temporary_scope( | ||
&self, | ||
region_scope_tree: &ScopeTree, | ||
expr_id: hir::ItemLocalId, | ||
) -> Option<Scope> { | ||
// Check for a designated rvalue scope. | ||
if let Some(&s) = self.map.get(&expr_id) { | ||
debug!("temporary_scope({expr_id:?}) = {s:?} [custom]"); | ||
return s; | ||
} | ||
|
||
// Otherwise, locate the innermost terminating scope | ||
// if there's one. Static items, for instance, won't | ||
// have an enclosing scope, hence no scope will be | ||
// returned. | ||
let mut id = Scope { id: expr_id, data: ScopeData::Node }; | ||
|
||
while let Some(&(p, _)) = region_scope_tree.parent_map.get(&id) { | ||
match p.data { | ||
ScopeData::Destruction => { | ||
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]"); | ||
return Some(id); | ||
} | ||
_ => id = p, | ||
} | ||
} | ||
|
||
debug!("temporary_scope({expr_id:?}) = None"); | ||
None | ||
} | ||
|
||
/// Make an association between a sub-expression and an extended lifetime | ||
pub fn record_rvalue_scope(&mut self, var: hir::ItemLocalId, lifetime: Option<Scope>) { | ||
debug!("record_rvalue_scope(var={var:?}, lifetime={lifetime:?})"); | ||
if let Some(lifetime) = lifetime { | ||
assert!(var != lifetime.item_local_id()); | ||
} | ||
self.map.insert(var, lifetime); | ||
} | ||
} |
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
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.
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.
@Mark-Simulacrum I think by removing
region_scope_tree
from the list of queries, I suspect that the caching is lost since this computation could get repeated.