-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
|
||
impl DisambiguatorState { | ||
pub fn new() -> Self { | ||
Self { next: Default::default() } |
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.
#[derive(Default)]
can be used instead of this.
@@ -288,7 +310,7 @@ pub enum DefPathData { | |||
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name. | |||
OpaqueTy, | |||
/// An anonymous associated type from an RPITIT. | |||
AnonAssocTy, | |||
AnonAssocTy(Symbol), |
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.
Need a comment telling what the symbol is.
@@ -411,7 +442,9 @@ impl DefPathData { | |||
pub fn get_opt_name(&self) -> Option<Symbol> { | |||
use self::DefPathData::*; | |||
match *self { | |||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name), | |||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name) => { |
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.
The AnonAssocTy
case here doesn't seem right.
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.
It does seem a little bit odd. I could duplicate get_opt_name
to have a variant that's used for stable hashing.
None, | ||
DefKind::SyntheticCoroutineBody, | ||
None, | ||
&mut DisambiguatorState::new(), |
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.
This needs a comment explaining why the disambiguate is correct, the removed comment sort of did that.
tcx, | ||
rbv: &mut rbv, | ||
scope: &Scope::Root { opt_parent_item: None }, | ||
disambiguator: &mut DisambiguatorState::new(), |
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.
Probably also needs a comment telling what is the def parenting here and why the disambiguator is correct.
@@ -154,6 +168,8 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx, const_eval | |||
intern_kind: InternKind, | |||
ret: &MPlaceTy<'tcx>, | |||
) -> Result<(), InternResult> { | |||
let mut disambiguator = DisambiguatorState::new(); |
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.
This is just a number, right? So it's cheap to create even when we don't need it (like for non-static
consts)?
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.
it's a hash map, but that's also cheap if it never gets pushed to
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.
Makes sense. A perf run would probably still be a good idea (once the PR is ready for that) given how this changes a bunch of stuff all over the compiler and some of that could easily be hot code.
This removes
Definitions.next_disambiguator
as it doesn't guarantee deterministic def paths whencreate_def
is called in parallel. Instead a newDisambiguatorState
type is passed as a mutable reference tocreate_def
to help create unique def paths.create_def
calls with distinctDisambiguatorState
instances must ensure that that the def paths are unique without its help.Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the
DefPathData
to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer.cc @oli-obk