Preserve the Feed in local tables

This commit is contained in:
Oli Scherer 2024-02-14 15:21:04 +00:00
parent 31d0a644be
commit 3b9dfd3f09

View File

@ -53,7 +53,7 @@
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt, TyCtxtFeed}; use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt, TyCtxtFeed};
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs}; use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs, Feed};
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;
use rustc_session::lint::builtin::PRIVATE_MACRO_USE; use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
use rustc_session::lint::LintBuffer; use rustc_session::lint::LintBuffer;
@ -1115,7 +1115,7 @@ pub struct Resolver<'a, 'tcx> {
next_node_id: NodeId, next_node_id: NodeId,
node_id_to_def_id: NodeMap<LocalDefId>, node_id_to_def_id: NodeMap<Feed<'tcx, LocalDefId>>,
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>, def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
/// Indices of unnamed struct or variant fields with unresolved attributes. /// Indices of unnamed struct or variant fields with unresolved attributes.
@ -1231,11 +1231,19 @@ fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> {
impl<'tcx> Resolver<'_, 'tcx> { impl<'tcx> Resolver<'_, 'tcx> {
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> { fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
self.node_id_to_def_id.get(&node).copied() self.opt_feed(node).map(|f| f.key())
} }
fn local_def_id(&self, node: NodeId) -> LocalDefId { fn local_def_id(&self, node: NodeId) -> LocalDefId {
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`")) self.feed(node).key()
}
fn opt_feed(&self, node: NodeId) -> Option<Feed<'tcx, LocalDefId>> {
self.node_id_to_def_id.get(&node).copied()
}
fn feed(&self, node: NodeId) -> Feed<'tcx, LocalDefId> {
self.opt_feed(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
} }
fn local_def_kind(&self, node: NodeId) -> DefKind { fn local_def_kind(&self, node: NodeId) -> DefKind {
@ -1258,7 +1266,7 @@ fn create_def(
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}", "adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
node_id, node_id,
data, data,
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id]), self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id].key()),
); );
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()` // FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
@ -1280,7 +1288,7 @@ fn create_def(
// we don't need a mapping from `NodeId` to `LocalDefId`. // we don't need a mapping from `NodeId` to `LocalDefId`.
if node_id != ast::DUMMY_NODE_ID { if node_id != ast::DUMMY_NODE_ID {
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id); debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
self.node_id_to_def_id.insert(node_id, def_id); self.node_id_to_def_id.insert(node_id, feed.downgrade());
} }
assert_eq!(self.def_id_to_node_id.push(node_id), def_id); assert_eq!(self.def_id_to_node_id.push(node_id), def_id);
@ -1332,7 +1340,8 @@ pub fn new(
let mut def_id_to_node_id = IndexVec::default(); let mut def_id_to_node_id = IndexVec::default();
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID); assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
let mut node_id_to_def_id = NodeMap::default(); let mut node_id_to_def_id = NodeMap::default();
node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID); let crate_feed = tcx.feed_local_def_id(CRATE_DEF_ID).downgrade();
node_id_to_def_id.insert(CRATE_NODE_ID, crate_feed);
let mut invocation_parents = FxHashMap::default(); let mut invocation_parents = FxHashMap::default();
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential)); invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
@ -1548,7 +1557,8 @@ pub fn into_outputs(self) -> ResolverOutputs {
self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter( self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter(
self.stripped_cfg_items.into_iter().filter_map(|item| { self.stripped_cfg_items.into_iter().filter_map(|item| {
let parent_module = self.node_id_to_def_id.get(&item.parent_module)?.to_def_id(); let parent_module =
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg }) Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg })
}), }),
)); ));
@ -1577,7 +1587,11 @@ pub fn into_outputs(self) -> ResolverOutputs {
lifetimes_res_map: self.lifetimes_res_map, lifetimes_res_map: self.lifetimes_res_map,
extra_lifetime_params_map: self.extra_lifetime_params_map, extra_lifetime_params_map: self.extra_lifetime_params_map,
next_node_id: self.next_node_id, next_node_id: self.next_node_id,
node_id_to_def_id: self.node_id_to_def_id, node_id_to_def_id: self
.node_id_to_def_id
.into_items()
.map(|(k, f)| (k, f.key()))
.collect(),
def_id_to_node_id: self.def_id_to_node_id, def_id_to_node_id: self.def_id_to_node_id,
trait_map: self.trait_map, trait_map: self.trait_map,
lifetime_elision_allowed: self.lifetime_elision_allowed, lifetime_elision_allowed: self.lifetime_elision_allowed,