Move next_disambiguator to Resolver

This commit is contained in:
marmeladema 2020-06-21 23:49:06 +01:00
parent 1d3f49f536
commit bd4f6f0b7d
2 changed files with 15 additions and 11 deletions

View File

@ -87,7 +87,6 @@ pub struct Definitions {
parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>,
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
expansions_that_defined: FxHashMap<LocalDefId, ExpnId>,
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
}
/// A unique identifier that we can use to lookup a definition
@ -350,7 +349,6 @@ impl Definitions {
def_id_to_hir_id: Default::default(),
hir_id_to_def_id: Default::default(),
expansions_that_defined: Default::default(),
next_disambiguator: Default::default(),
parent_modules_of_macro_defs: Default::default(),
}
}
@ -366,20 +364,14 @@ impl Definitions {
parent: LocalDefId,
data: DefPathData,
expn_id: ExpnId,
mut next_disambiguator: impl FnMut(LocalDefId, DefPathData) -> u32,
) -> LocalDefId {
debug!("create_def(parent={:?}, data={:?}, expn_id={:?})", parent, data, expn_id);
// The root node must be created with `create_root_def()`.
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 disambiguator = *next_disamb;
*next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
disambiguator
};
let disambiguator = next_disambiguator(parent, data);
let key = DefKey {
parent: Some(parent.local_def_index),
disambiguated_data: DisambiguatedDefPathData { data, disambiguator },

View File

@ -982,6 +982,8 @@ pub struct Resolver<'a> {
/// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId`
/// we know what parent node that fragment should be attached to thanks to this table.
invocation_parents: FxHashMap<ExpnId, LocalDefId>,
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
}
/// Nothing really interesting here; it just provides memory for the rest of the crate.
@ -1142,7 +1144,16 @@ impl ResolverAstLowering for Resolver<'_> {
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
);
let def_id = self.definitions.create_def(parent, data, expn_id);
// Find the next free disambiguator for this key.
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);
assert_eq!(self.def_id_to_span.push(span), def_id);
@ -1322,6 +1333,7 @@ impl<'a> Resolver<'a> {
def_id_to_node_id,
placeholder_field_indices: Default::default(),
invocation_parents,
next_disambiguator: Default::default(),
}
}