Pre-compute LocalDefId <-> HirId mappings and remove NodeId <-> HirId conversion APIs by marmeladema · Pull Request #73291 · rust-lang/rust (original) (raw)

What is the end goal here, removing any mentions of NodeId from struct Definitions?

Definitions is a pretty heterogeneous structure.
Perhaps it can be split into two structures instead, one for fields used before lowering to HIR, and one for fields used after lowering to HIR?

struct Definitions { // Both before and after (or filled before, used after) table: DefPathTable, parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>, expansions_that_defined: FxHashMap<LocalDefId, ExpnId>,

// Before
def_id_to_span: IndexVec<LocalDefId, Span>,
node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
invocation_parents: FxHashMap<ExpnId, LocalDefId>,
placeholder_field_indices: FxHashMap<ast::NodeId, usize>,

// ???
node_id_to_hir_id: IndexVec<ast::NodeId, Option<hir::HirId>>,
hir_id_to_node_id: FxHashMap<hir::HirId, ast::NodeId>,

}

Having the "before" fields in the ResolverOutputs version of Definitions doesn't make any sense, but they are currently placed there.