-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
delegation: fix def path hash collision, add per parent disambiguators #153955
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,11 +97,34 @@ impl DefPathTable { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub trait Disambiguator { | ||
| fn entry(&mut self, parent: LocalDefId, data: DefPathData) -> &mut u32; | ||
| } | ||
|
|
||
| #[derive(Debug, Default, Clone)] | ||
| pub struct PerParentDisambiguatorState { | ||
| next: UnordMap<DefPathData, u32>, | ||
|
Contributor
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. Should probably at least have a cfg(debug-assertion) field for the parent def id and check it in the impl
Contributor
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. Implemented in #155547. |
||
| } | ||
|
|
||
| impl Disambiguator for PerParentDisambiguatorState { | ||
| #[inline] | ||
| fn entry(&mut self, _: LocalDefId, data: DefPathData) -> &mut u32 { | ||
| self.next.entry(data).or_insert(0) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Default, Clone)] | ||
| pub struct DisambiguatorState { | ||
| next: UnordMap<(LocalDefId, DefPathData), u32>, | ||
|
aerooneqq marked this conversation as resolved.
|
||
| } | ||
|
|
||
| impl Disambiguator for DisambiguatorState { | ||
| #[inline] | ||
| fn entry(&mut self, parent: LocalDefId, data: DefPathData) -> &mut u32 { | ||
| self.next.entry((parent, data)).or_insert(0) | ||
| } | ||
| } | ||
|
|
||
| impl DisambiguatorState { | ||
| pub const fn new() -> Self { | ||
| Self { next: Default::default() } | ||
|
|
@@ -302,10 +325,6 @@ pub enum DefPathData { | |
| Ctor, | ||
| /// A constant expression (see `{ast,hir}::AnonConst`). | ||
| AnonConst, | ||
| /// A constant expression created during AST->HIR lowering.. | ||
| LateAnonConst, | ||
| /// A fresh anonymous lifetime created by desugaring elided lifetimes. | ||
| DesugaredAnonymousLifetime, | ||
| /// An existential `impl Trait` type node. | ||
| /// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name. | ||
| OpaqueTy, | ||
|
|
@@ -389,7 +408,7 @@ impl Definitions { | |
| &mut self, | ||
| parent: LocalDefId, | ||
| data: DefPathData, | ||
| disambiguator: &mut DisambiguatorState, | ||
| disambiguator: &mut impl Disambiguator, | ||
| ) -> 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. | ||
|
|
@@ -403,7 +422,7 @@ impl Definitions { | |
|
|
||
| // Find the next free disambiguator for this key. | ||
| let disambiguator = { | ||
| let next_disamb = disambiguator.next.entry((parent, data)).or_insert(0); | ||
| let next_disamb = disambiguator.entry(parent, data); | ||
| let disambiguator = *next_disamb; | ||
| *next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow"); | ||
| disambiguator | ||
|
|
@@ -458,8 +477,6 @@ impl DefPathData { | |
| TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | ||
| | OpaqueLifetime(name) => Some(name), | ||
|
|
||
| DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime), | ||
|
|
||
| Impl | ||
| | ForeignMod | ||
| | CrateRoot | ||
|
|
@@ -468,7 +485,6 @@ impl DefPathData { | |
| | Closure | ||
| | Ctor | ||
| | AnonConst | ||
| | LateAnonConst | ||
| | OpaqueTy | ||
| | AnonAssocTy(..) | ||
| | SyntheticCoroutineBody | ||
|
|
@@ -482,8 +498,6 @@ impl DefPathData { | |
| TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name) | ||
| | OpaqueLifetime(name) => Some(name), | ||
|
|
||
| DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime), | ||
|
|
||
| Impl | ||
| | ForeignMod | ||
| | CrateRoot | ||
|
|
@@ -492,7 +506,6 @@ impl DefPathData { | |
| | Closure | ||
| | Ctor | ||
| | AnonConst | ||
| | LateAnonConst | ||
| | OpaqueTy | ||
| | SyntheticCoroutineBody | ||
| | NestedStatic => None, | ||
|
|
@@ -512,8 +525,7 @@ impl DefPathData { | |
| GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm }, | ||
| Closure => DefPathDataName::Anon { namespace: sym::closure }, | ||
| Ctor => DefPathDataName::Anon { namespace: sym::constructor }, | ||
| AnonConst | LateAnonConst => DefPathDataName::Anon { namespace: sym::constant }, | ||
| DesugaredAnonymousLifetime => DefPathDataName::Named(kw::UnderscoreLifetime), | ||
| AnonConst => DefPathDataName::Anon { namespace: sym::constant }, | ||
| OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque }, | ||
| AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc }, | ||
| SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic }, | ||
|
|
||
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
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.
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'm guessing it's a perf issue to just always have a per-parent disambiguator?
View changes since the review
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.
@aerooneqq ^^^
Probably?
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.
Also, the use of
Stealhere is only for assertions, it's not technically necessary if everything works as expected.The previous perf run without
Stealgave better results.Uh oh!
There was an error while loading. Please reload this page.
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.
Steal was used also because we pass resolver by immutable reference during delayed lowering and without it we will need to clone disambiguators (which is OK for nightly delegations). Removing steals from disambiguators should work if we continue stealing
ResolverAstLoweringinlower_to_hir, but in #155460 we no longer steal resolver inlower_to_hir, those changes will conflict.So seems like we should do a hybrid approach by using per-parent disambiguators only for delegations and for everything else use default disambiguator and pass it asSteal<DisambiguatorState>to AST -> HIR lowering?