-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Remove global next_disambiguator
state and handle it with a DisambiguatorState
type
#140453
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2ac60bc
We always use the current item as parent, so no need to pass it
oli-obk e561ec0
Remove global `next_disambiguator` state and handle it with a `Disamb…
Zoxc df1f8d1
Update stable-mir test
Zoxc ddff387
Rename parameter to `override_def_path_data`
Zoxc efc51ce
Add `DefPathData::NestedStatic` instead of reusing `DefPathData::Anon…
Zoxc d16daf5
Add comment about the symbol on `AnonAssocTy`
Zoxc 4869e20
Split `get_opt_name` hashing use into `hashed_symbol`
Zoxc 6a48217
Move `DisambiguatorState` into `intern_const_alloc_recursive`
Zoxc 9f8c6d5
Add comment on creation of `SyntheticCoroutineBody`
Zoxc acb50d5
Add comment on creation of lifetime inside opaque types
Zoxc 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 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
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 |
---|---|---|
|
@@ -68,7 +68,7 @@ impl DefPathTable { | |
// | ||
// See the documentation for DefPathHash for more information. | ||
panic!( | ||
"found DefPathHash collision between {def_path1:?} and {def_path2:?}. \ | ||
"found DefPathHash collision between {def_path1:#?} and {def_path2:#?}. \ | ||
Compilation cannot continue." | ||
); | ||
} | ||
|
@@ -97,13 +97,31 @@ impl DefPathTable { | |
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct DisambiguatorState { | ||
next: UnordMap<(LocalDefId, DefPathData), u32>, | ||
} | ||
|
||
impl DisambiguatorState { | ||
pub fn new() -> Self { | ||
Self { next: Default::default() } | ||
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.
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. I do prefer |
||
} | ||
|
||
/// Creates a `DisambiguatorState` where the next allocated `(LocalDefId, DefPathData)` pair | ||
/// will have `index` as the disambiguator. | ||
pub fn with(def_id: LocalDefId, data: DefPathData, index: u32) -> Self { | ||
let mut this = Self::new(); | ||
this.next.insert((def_id, data), index); | ||
this | ||
} | ||
} | ||
|
||
/// The definition table containing node definitions. | ||
/// It holds the `DefPathTable` for `LocalDefId`s/`DefPath`s. | ||
/// It also stores mappings to convert `LocalDefId`s to/from `HirId`s. | ||
#[derive(Debug)] | ||
pub struct Definitions { | ||
table: DefPathTable, | ||
next_disambiguator: UnordMap<(LocalDefId, DefPathData), u32>, | ||
} | ||
|
||
/// A unique identifier that we can use to lookup a definition | ||
|
@@ -127,7 +145,7 @@ impl DefKey { | |
let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data; | ||
|
||
std::mem::discriminant(data).hash(&mut hasher); | ||
if let Some(name) = data.get_opt_name() { | ||
if let Some(name) = data.hashed_symbol() { | ||
// Get a stable hash by considering the symbol chars rather than | ||
// the symbol index. | ||
name.as_str().hash(&mut hasher); | ||
|
@@ -173,7 +191,11 @@ impl DisambiguatedDefPathData { | |
} | ||
} | ||
DefPathDataName::Anon { namespace } => { | ||
write!(writer, "{{{}#{}}}", namespace, self.disambiguator) | ||
if let DefPathData::AnonAssocTy(method) = self.data { | ||
write!(writer, "{}::{{{}#{}}}", method, namespace, self.disambiguator) | ||
} else { | ||
write!(writer, "{{{}#{}}}", namespace, self.disambiguator) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -287,10 +309,13 @@ pub enum DefPathData { | |
/// An existential `impl Trait` type node. | ||
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name. | ||
OpaqueTy, | ||
/// An anonymous associated type from an RPITIT. | ||
AnonAssocTy, | ||
/// An anonymous associated type from an RPITIT. The symbol refers to the name of the method | ||
/// that defined the type. | ||
AnonAssocTy(Symbol), | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// A synthetic body for a coroutine's by-move body. | ||
SyntheticCoroutineBody, | ||
/// Additional static data referred to by a static. | ||
NestedStatic, | ||
} | ||
|
||
impl Definitions { | ||
|
@@ -342,24 +367,33 @@ impl Definitions { | |
let root = LocalDefId { local_def_index: table.allocate(key, def_path_hash) }; | ||
assert_eq!(root.local_def_index, CRATE_DEF_INDEX); | ||
|
||
Definitions { table, next_disambiguator: Default::default() } | ||
Definitions { table } | ||
} | ||
|
||
/// Adds a definition with a parent definition. | ||
pub fn create_def(&mut self, parent: LocalDefId, data: DefPathData) -> LocalDefId { | ||
/// Creates a definition with a parent definition. | ||
/// If there are multiple definitions with the same DefPathData and the same parent, use | ||
/// `disambiguator` to differentiate them. Distinct `DisambiguatorState` instances are not | ||
/// guaranteed to generate unique disambiguators and should instead ensure that the `parent` | ||
/// and `data` pair is distinct from other instances. | ||
pub fn create_def( | ||
&mut self, | ||
parent: LocalDefId, | ||
data: DefPathData, | ||
disambiguator: &mut DisambiguatorState, | ||
) -> LocalDefId { | ||
// We can't use `Debug` implementation for `LocalDefId` here, since it tries to acquire a | ||
// reference to `Definitions` and we're already holding a mutable reference. | ||
debug!( | ||
"create_def(parent={}, data={data:?})", | ||
self.def_path(parent).to_string_no_crate_verbose(), | ||
); | ||
|
||
// The root node must be created with `create_root_def()`. | ||
// The root node must be created in `new()`. | ||
assert!(data != DefPathData::CrateRoot); | ||
|
||
// Find the next free disambiguator for this key. | ||
let disambiguator = { | ||
let next_disamb = self.next_disambiguator.entry((parent, data)).or_insert(0); | ||
let next_disamb = disambiguator.next.entry((parent, data)).or_insert(0); | ||
let disambiguator = *next_disamb; | ||
*next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow"); | ||
disambiguator | ||
|
@@ -422,8 +456,30 @@ impl DefPathData { | |
| Ctor | ||
| AnonConst | ||
| OpaqueTy | ||
| AnonAssocTy | ||
| SyntheticCoroutineBody => None, | ||
| AnonAssocTy(..) | ||
| SyntheticCoroutineBody | ||
| NestedStatic => None, | ||
} | ||
} | ||
|
||
fn hashed_symbol(&self) -> Option<Symbol> { | ||
use self::DefPathData::*; | ||
match *self { | ||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name) => { | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Some(name) | ||
} | ||
|
||
Impl | ||
| ForeignMod | ||
| CrateRoot | ||
| Use | ||
| GlobalAsm | ||
| Closure | ||
| Ctor | ||
| AnonConst | ||
| OpaqueTy | ||
| SyntheticCoroutineBody | ||
| NestedStatic => None, | ||
} | ||
} | ||
|
||
|
@@ -443,8 +499,9 @@ impl DefPathData { | |
Ctor => DefPathDataName::Anon { namespace: sym::constructor }, | ||
AnonConst => DefPathDataName::Anon { namespace: sym::constant }, | ||
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque }, | ||
AnonAssocTy => DefPathDataName::Anon { namespace: sym::anon_assoc }, | ||
AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc }, | ||
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic }, | ||
NestedStatic => DefPathDataName::Anon { namespace: sym::nested }, | ||
} | ||
} | ||
} | ||
|
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.