Rollup merge of #121089 - oli-obk:create_def_feed, r=petrochenkov
Remove `feed_local_def_id` best reviewed commit by commit Basically I returned `TyCtxtFeed` from `create_def` and then preserved that in the local caches based on https://github.com/rust-lang/rust/pull/121084 r? ````@petrochenkov````
This commit is contained in:
commit
4de78d2a8d
15 changed files with 181 additions and 86 deletions
|
@ -125,12 +125,11 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
|
||||
feedable
|
||||
no_hash
|
||||
desc { "getting the resolver outputs" }
|
||||
}
|
||||
|
||||
query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
|
||||
query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
|
||||
eval_always
|
||||
no_hash
|
||||
desc { "getting the resolver for lowering" }
|
||||
|
@ -2216,7 +2215,6 @@ rustc_queries! {
|
|||
/// Should not be called for the local crate before the resolver outputs are created, as it
|
||||
/// is only fed there.
|
||||
query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
|
||||
feedable
|
||||
desc { "getting cfg-ed out item names" }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
|
|||
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal};
|
||||
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, WorkerLocal};
|
||||
#[cfg(parallel_compiler)]
|
||||
use rustc_data_structures::sync::{DynSend, DynSync};
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
|
@ -60,7 +60,7 @@ use rustc_session::config::CrateType;
|
|||
use rustc_session::cstore::{CrateStoreDyn, Untracked};
|
||||
use rustc_session::lint::Lint;
|
||||
use rustc_session::{Limit, MetadataKind, Session};
|
||||
use rustc_span::def_id::{DefPathHash, StableCrateId};
|
||||
use rustc_span::def_id::{DefPathHash, StableCrateId, CRATE_DEF_ID};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{FieldIdx, Layout, LayoutS, TargetDataLayout, VariantIdx};
|
||||
|
@ -74,6 +74,7 @@ use std::cmp::Ordering;
|
|||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::iter;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::ops::{Bound, Deref};
|
||||
|
||||
|
@ -498,14 +499,55 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> {
|
|||
key: KEY,
|
||||
}
|
||||
|
||||
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
|
||||
/// allowed to feed queries for that `DefId`.
|
||||
impl<KEY: Copy, CTX> !HashStable<CTX> for TyCtxtFeed<'_, KEY> {}
|
||||
|
||||
/// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`.
|
||||
/// Use this to pass around when you have a `TyCtxt` elsewhere.
|
||||
/// Just an optimization to save space and not store hundreds of
|
||||
/// `TyCtxtFeed` in the resolver.
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Feed<'tcx, KEY: Copy> {
|
||||
_tcx: PhantomData<TyCtxt<'tcx>>,
|
||||
// Do not allow direct access, as downstream code must not mutate this field.
|
||||
key: KEY,
|
||||
}
|
||||
|
||||
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
|
||||
/// allowed to feed queries for that `DefId`.
|
||||
impl<KEY: Copy, CTX> !HashStable<CTX> for Feed<'_, KEY> {}
|
||||
|
||||
impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.key.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Some workarounds to use cases that cannot use `create_def`.
|
||||
/// Do not add new ways to create `TyCtxtFeed` without consulting
|
||||
/// with T-compiler and making an analysis about why your addition
|
||||
/// does not cause incremental compilation issues.
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Can only be fed before queries are run, and is thus exempt from any
|
||||
/// incremental issues. Do not use except for the initial query feeding.
|
||||
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
|
||||
self.dep_graph.assert_ignored();
|
||||
TyCtxtFeed { tcx: self, key: () }
|
||||
}
|
||||
|
||||
/// Can only be fed before queries are run, and is thus exempt from any
|
||||
/// incremental issues. Do not use except for the initial query feeding.
|
||||
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
|
||||
self.dep_graph.assert_ignored();
|
||||
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
|
||||
}
|
||||
pub fn feed_local_def_id(self, key: LocalDefId) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||
|
||||
/// Only used in the resolver to register the `CRATE_DEF_ID` `DefId` and feed
|
||||
/// some queries for it. It will panic if used twice.
|
||||
pub fn create_local_crate_def_id(self, span: Span) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||
let key = self.untracked().source_span.push(span);
|
||||
assert_eq!(key, CRATE_DEF_ID);
|
||||
TyCtxtFeed { tcx: self, key }
|
||||
}
|
||||
|
||||
|
@ -523,6 +565,23 @@ impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
|
|||
pub fn key(&self) -> KEY {
|
||||
self.key
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn downgrade(self) -> Feed<'tcx, KEY> {
|
||||
Feed { _tcx: PhantomData, key: self.key }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, KEY: Copy> Feed<'tcx, KEY> {
|
||||
#[inline(always)]
|
||||
pub fn key(&self) -> KEY {
|
||||
self.key
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn upgrade(self, tcx: TyCtxt<'tcx>) -> TyCtxtFeed<'tcx, KEY> {
|
||||
TyCtxtFeed { tcx, key: self.key }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
|
||||
|
@ -1067,7 +1126,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
// needs to be re-evaluated.
|
||||
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
|
||||
|
||||
let feed = self.feed_local_def_id(def_id);
|
||||
let feed = TyCtxtFeed { tcx: self, key: def_id };
|
||||
feed.def_kind(def_kind);
|
||||
// Unique types created for closures participate in type privacy checking.
|
||||
// They have visibilities inherited from the module they are defined in.
|
||||
|
@ -2304,6 +2363,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.resolutions(()).module_children.get(&def_id).map_or(&[], |v| &v[..])
|
||||
}
|
||||
|
||||
pub fn resolver_for_lowering(self) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
|
||||
self.resolver_for_lowering_raw(()).0
|
||||
}
|
||||
|
||||
/// Given an `impl_id`, return the trait it implements.
|
||||
/// Return `None` if this is an inherent impl.
|
||||
pub fn impl_trait_ref(
|
||||
|
|
|
@ -32,6 +32,7 @@ pub use generic_args::*;
|
|||
pub use generics::*;
|
||||
pub use intrinsic::IntrinsicDef;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::expand::StrippedCfgItem;
|
||||
use rustc_ast::node_id::NodeMap;
|
||||
pub use rustc_ast_ir::{try_visit, Movability, Mutability};
|
||||
use rustc_attr as attr;
|
||||
|
@ -85,7 +86,8 @@ pub use self::consts::{
|
|||
Const, ConstData, ConstInt, ConstKind, Expr, ScalarInt, UnevaluatedConst, ValTree,
|
||||
};
|
||||
pub use self::context::{
|
||||
tls, CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed,
|
||||
tls, CtxtInterners, DeducedParamAttrs, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt,
|
||||
TyCtxtFeed,
|
||||
};
|
||||
pub use self::instance::{Instance, InstanceDef, ShortInstance, UnusedGenericParams};
|
||||
pub use self::list::List;
|
||||
|
@ -189,6 +191,7 @@ pub struct ResolverGlobalCtxt {
|
|||
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
|
||||
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
|
||||
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
||||
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
|
||||
}
|
||||
|
||||
/// Resolutions that should only be used for lowering.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue