Skip to content

Commit 9cc558b

Browse files
committed
Preserve the Feed in local tables
1 parent 56ef997 commit 9cc558b

File tree

1 file changed

+23
-12
lines changed
  • compiler/rustc_resolve/src

1 file changed

+23
-12
lines changed

compiler/rustc_resolve/src/lib.rs

+23-12
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ pub struct Resolver<'a, 'tcx> {
10981098

10991099
next_node_id: NodeId,
11001100

1101-
node_id_to_def_id: NodeMap<LocalDefId>,
1101+
node_id_to_def_id: NodeMap<Feed<'tcx, LocalDefId>>,
11021102
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
11031103

11041104
/// Indices of unnamed struct or variant fields with unresolved attributes.
@@ -1214,11 +1214,19 @@ impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for Resolver<'a, 'tcx> {
12141214

12151215
impl<'tcx> Resolver<'_, 'tcx> {
12161216
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
1217-
self.node_id_to_def_id.get(&node).copied()
1217+
self.opt_feed(node).map(|f| f.key())
12181218
}
12191219

12201220
fn local_def_id(&self, node: NodeId) -> LocalDefId {
1221-
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
1221+
self.feed(node).key()
1222+
}
1223+
1224+
fn opt_feed(&self, node: NodeId) -> Option<Feed<'tcx, LocalDefId>> {
1225+
self.node_id_to_def_id.get(&node).copied()
1226+
}
1227+
1228+
fn feed(&self, node: NodeId) -> Feed<'tcx, LocalDefId> {
1229+
self.opt_feed(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
12221230
}
12231231

12241232
fn local_def_kind(&self, node: NodeId) -> DefKind {
@@ -1241,7 +1249,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
12411249
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
12421250
node_id,
12431251
data,
1244-
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id]),
1252+
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id].key()),
12451253
);
12461254

12471255
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
@@ -1263,7 +1271,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
12631271
// we don't need a mapping from `NodeId` to `LocalDefId`.
12641272
if node_id != ast::DUMMY_NODE_ID {
12651273
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
1266-
self.node_id_to_def_id.insert(node_id, def_id);
1274+
self.node_id_to_def_id.insert(node_id, feed.downgrade());
12671275
}
12681276
assert_eq!(self.def_id_to_node_id.push(node_id), def_id);
12691277

@@ -1315,13 +1323,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13151323
let mut def_id_to_node_id = IndexVec::default();
13161324
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
13171325
let mut node_id_to_def_id = NodeMap::default();
1318-
node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID);
1326+
let crate_feed = tcx.feed_local_def_id(CRATE_DEF_ID).downgrade();
1327+
node_id_to_def_id.insert(CRATE_NODE_ID, crate_feed);
13191328

13201329
let mut invocation_parents = FxHashMap::default();
1321-
invocation_parents.insert(
1322-
LocalExpnId::ROOT,
1323-
(tcx.feed_local_def_id(CRATE_DEF_ID).downgrade(), ImplTraitContext::Existential),
1324-
);
1330+
invocation_parents.insert(LocalExpnId::ROOT, (crate_feed, ImplTraitContext::Existential));
13251331

13261332
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = tcx
13271333
.sess
@@ -1534,7 +1540,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15341540

15351541
self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter(
15361542
self.stripped_cfg_items.into_iter().filter_map(|item| {
1537-
let parent_module = self.node_id_to_def_id.get(&item.parent_module)?.to_def_id();
1543+
let parent_module =
1544+
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
15381545
Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg })
15391546
}),
15401547
));
@@ -1563,7 +1570,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15631570
lifetimes_res_map: self.lifetimes_res_map,
15641571
extra_lifetime_params_map: self.extra_lifetime_params_map,
15651572
next_node_id: self.next_node_id,
1566-
node_id_to_def_id: self.node_id_to_def_id,
1573+
node_id_to_def_id: self
1574+
.node_id_to_def_id
1575+
.into_items()
1576+
.map(|(k, f)| (k, f.key()))
1577+
.collect(),
15671578
def_id_to_node_id: self.def_id_to_node_id,
15681579
trait_map: self.trait_map,
15691580
lifetime_elision_allowed: self.lifetime_elision_allowed,

0 commit comments

Comments
 (0)