Store next_disambiguator in Definitions.
This commit is contained in:
parent
b29fa94d22
commit
c10a1cebe7
2 changed files with 10 additions and 14 deletions
|
@ -99,6 +99,7 @@ impl DefPathTable {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Definitions {
|
pub struct Definitions {
|
||||||
table: DefPathTable,
|
table: DefPathTable,
|
||||||
|
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
||||||
|
|
||||||
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
||||||
expansions_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
expansions_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
||||||
|
@ -340,6 +341,7 @@ impl Definitions {
|
||||||
|
|
||||||
Definitions {
|
Definitions {
|
||||||
table,
|
table,
|
||||||
|
next_disambiguator: Default::default(),
|
||||||
expansions_that_defined: Default::default(),
|
expansions_that_defined: Default::default(),
|
||||||
def_id_to_span,
|
def_id_to_span,
|
||||||
stable_crate_id,
|
stable_crate_id,
|
||||||
|
@ -357,7 +359,6 @@ impl Definitions {
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
data: DefPathData,
|
data: DefPathData,
|
||||||
expn_id: ExpnId,
|
expn_id: ExpnId,
|
||||||
mut next_disambiguator: impl FnMut(LocalDefId, DefPathData) -> u32,
|
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
debug!("create_def(parent={:?}, data={:?}, expn_id={:?})", parent, data, expn_id);
|
debug!("create_def(parent={:?}, data={:?}, expn_id={:?})", parent, data, expn_id);
|
||||||
|
@ -365,7 +366,13 @@ impl Definitions {
|
||||||
// The root node must be created with `create_root_def()`.
|
// The root node must be created with `create_root_def()`.
|
||||||
assert!(data != DefPathData::CrateRoot);
|
assert!(data != DefPathData::CrateRoot);
|
||||||
|
|
||||||
let disambiguator = next_disambiguator(parent, data);
|
// Find the next free disambiguator for this key.
|
||||||
|
let disambiguator = {
|
||||||
|
let next_disamb = self.next_disambiguator.entry((parent, data)).or_insert(0);
|
||||||
|
let disambiguator = *next_disamb;
|
||||||
|
*next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
|
||||||
|
disambiguator
|
||||||
|
};
|
||||||
let key = DefKey {
|
let key = DefKey {
|
||||||
parent: Some(parent.local_def_index),
|
parent: Some(parent.local_def_index),
|
||||||
disambiguated_data: DisambiguatedDefPathData { data, disambiguator },
|
disambiguated_data: DisambiguatedDefPathData { data, disambiguator },
|
||||||
|
|
|
@ -1061,7 +1061,6 @@ pub struct Resolver<'a> {
|
||||||
/// and how the `impl Trait` fragments were introduced.
|
/// and how the `impl Trait` fragments were introduced.
|
||||||
invocation_parents: FxHashMap<LocalExpnId, (LocalDefId, ImplTraitContext)>,
|
invocation_parents: FxHashMap<LocalExpnId, (LocalDefId, ImplTraitContext)>,
|
||||||
|
|
||||||
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
|
||||||
/// Some way to know that we are in a *trait* impl in `visit_assoc_item`.
|
/// Some way to know that we are in a *trait* impl in `visit_assoc_item`.
|
||||||
/// FIXME: Replace with a more general AST map (together with some other fields).
|
/// FIXME: Replace with a more general AST map (together with some other fields).
|
||||||
trait_impl_items: FxHashSet<LocalDefId>,
|
trait_impl_items: FxHashSet<LocalDefId>,
|
||||||
|
@ -1249,16 +1248,7 @@ impl ResolverAstLowering for Resolver<'_> {
|
||||||
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
|
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Find the next free disambiguator for this key.
|
let def_id = self.definitions.create_def(parent, data, expn_id, span);
|
||||||
let next_disambiguator = &mut self.next_disambiguator;
|
|
||||||
let next_disambiguator = |parent, data| {
|
|
||||||
let next_disamb = next_disambiguator.entry((parent, data)).or_insert(0);
|
|
||||||
let disambiguator = *next_disamb;
|
|
||||||
*next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
|
|
||||||
disambiguator
|
|
||||||
};
|
|
||||||
|
|
||||||
let def_id = self.definitions.create_def(parent, data, expn_id, next_disambiguator, span);
|
|
||||||
|
|
||||||
// Some things for which we allocate `LocalDefId`s don't correspond to
|
// Some things for which we allocate `LocalDefId`s don't correspond to
|
||||||
// anything in the AST, so they don't have a `NodeId`. For these cases
|
// anything in the AST, so they don't have a `NodeId`. For these cases
|
||||||
|
@ -1430,7 +1420,6 @@ impl<'a> Resolver<'a> {
|
||||||
def_id_to_node_id,
|
def_id_to_node_id,
|
||||||
placeholder_field_indices: Default::default(),
|
placeholder_field_indices: Default::default(),
|
||||||
invocation_parents,
|
invocation_parents,
|
||||||
next_disambiguator: Default::default(),
|
|
||||||
trait_impl_items: Default::default(),
|
trait_impl_items: Default::default(),
|
||||||
legacy_const_generic_args: Default::default(),
|
legacy_const_generic_args: Default::default(),
|
||||||
item_generics_num_lifetimes: Default::default(),
|
item_generics_num_lifetimes: Default::default(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue