feed resolver_for_lowering instead of storing it in a field
This commit is contained in:
parent
125b729ddd
commit
f693b7848e
@ -12,6 +12,7 @@ use rustc_ast::{self as ast, visit};
|
|||||||
use rustc_borrowck as mir_borrowck;
|
use rustc_borrowck as mir_borrowck;
|
||||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||||
use rustc_data_structures::parallel;
|
use rustc_data_structures::parallel;
|
||||||
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
|
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
|
||||||
use rustc_errors::{ErrorGuaranteed, PResult};
|
use rustc_errors::{ErrorGuaranteed, PResult};
|
||||||
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
|
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
|
||||||
@ -804,6 +805,12 @@ pub fn create_global_ctxt<'tcx>(
|
|||||||
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
|
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let ty::ResolverOutputs {
|
||||||
|
definitions,
|
||||||
|
global_ctxt: untracked_resolutions,
|
||||||
|
ast_lowering: untracked_resolver_for_lowering,
|
||||||
|
} = resolver_outputs;
|
||||||
|
|
||||||
let gcx = sess.time("setup_global_ctxt", || {
|
let gcx = sess.time("setup_global_ctxt", || {
|
||||||
global_ctxt.get_or_init(move || {
|
global_ctxt.get_or_init(move || {
|
||||||
TyCtxt::create_global_ctxt(
|
TyCtxt::create_global_ctxt(
|
||||||
@ -811,7 +818,8 @@ pub fn create_global_ctxt<'tcx>(
|
|||||||
lint_store,
|
lint_store,
|
||||||
arena,
|
arena,
|
||||||
hir_arena,
|
hir_arena,
|
||||||
resolver_outputs,
|
definitions,
|
||||||
|
untracked_resolutions,
|
||||||
krate,
|
krate,
|
||||||
dep_graph,
|
dep_graph,
|
||||||
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
|
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
|
||||||
@ -823,7 +831,12 @@ pub fn create_global_ctxt<'tcx>(
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
QueryContext { gcx }
|
let mut qcx = QueryContext { gcx };
|
||||||
|
qcx.enter(|tcx| {
|
||||||
|
tcx.feed_unit_query()
|
||||||
|
.resolver_for_lowering(tcx.arena.alloc(Steal::new(untracked_resolver_for_lowering)))
|
||||||
|
});
|
||||||
|
qcx
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the resolution, type-checking, region checking and other
|
/// Runs the resolution, type-checking, region checking and other
|
||||||
|
@ -364,10 +364,6 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
|
|||||||
modifiers.eval_always.is_none(),
|
modifiers.eval_always.is_none(),
|
||||||
"Query {name} cannot be both `feedable` and `eval_always`."
|
"Query {name} cannot be both `feedable` and `eval_always`."
|
||||||
);
|
);
|
||||||
assert!(
|
|
||||||
modifiers.no_hash.is_none(),
|
|
||||||
"Query {name} cannot be both `feedable` and `no_hash`."
|
|
||||||
);
|
|
||||||
feedable_queries.extend(quote! {
|
feedable_queries.extend(quote! {
|
||||||
#(#doc_comments)*
|
#(#doc_comments)*
|
||||||
[#attribute_stream] fn #name(#arg) #result,
|
[#attribute_stream] fn #name(#arg) #result,
|
||||||
|
@ -28,6 +28,7 @@ macro_rules! arena_types {
|
|||||||
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
|
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
|
||||||
[decode] borrowck_result:
|
[decode] borrowck_result:
|
||||||
rustc_middle::mir::BorrowCheckResult<'tcx>,
|
rustc_middle::mir::BorrowCheckResult<'tcx>,
|
||||||
|
[] resolver: rustc_data_structures::steal::Steal<rustc_middle::ty::ResolverAstLowering>,
|
||||||
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
|
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
|
||||||
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
|
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
|
||||||
[] const_allocs: rustc_middle::mir::interpret::Allocation,
|
[] const_allocs: rustc_middle::mir::interpret::Allocation,
|
||||||
|
@ -33,7 +33,7 @@ rustc_queries! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
|
query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
|
||||||
eval_always
|
feedable
|
||||||
no_hash
|
no_hash
|
||||||
desc { "getting the resolver for lowering" }
|
desc { "getting the resolver for lowering" }
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ use std::mem;
|
|||||||
use std::ops::{Bound, Deref};
|
use std::ops::{Bound, Deref};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use super::{ImplPolarity, ResolverOutputs, RvalueScopes};
|
use super::{ImplPolarity, RvalueScopes};
|
||||||
|
|
||||||
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
|
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
|
||||||
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
|
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
|
||||||
@ -1040,6 +1040,12 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> {
|
|||||||
key: KEY,
|
key: KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
|
||||||
|
TyCtxtFeed { tcx: self, key: () }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
|
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn key(&self) -> KEY {
|
pub fn key(&self) -> KEY {
|
||||||
@ -1106,7 +1112,6 @@ pub struct GlobalCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Output of the resolver.
|
/// Output of the resolver.
|
||||||
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
|
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
|
||||||
untracked_resolver_for_lowering: Steal<ty::ResolverAstLowering>,
|
|
||||||
/// The entire crate as AST. This field serves as the input for the hir_crate query,
|
/// The entire crate as AST. This field serves as the input for the hir_crate query,
|
||||||
/// which lowers it from AST to HIR. It must not be read or used by anything else.
|
/// which lowers it from AST to HIR. It must not be read or used by anything else.
|
||||||
pub untracked_crate: Steal<Lrc<ast::Crate>>,
|
pub untracked_crate: Steal<Lrc<ast::Crate>>,
|
||||||
@ -1269,7 +1274,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
|
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
|
||||||
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
||||||
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
|
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
|
||||||
resolver_outputs: ResolverOutputs,
|
definitions: Definitions,
|
||||||
|
untracked_resolutions: ty::ResolverGlobalCtxt,
|
||||||
krate: Lrc<ast::Crate>,
|
krate: Lrc<ast::Crate>,
|
||||||
dep_graph: DepGraph,
|
dep_graph: DepGraph,
|
||||||
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
|
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
|
||||||
@ -1278,11 +1284,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
crate_name: &str,
|
crate_name: &str,
|
||||||
output_filenames: OutputFilenames,
|
output_filenames: OutputFilenames,
|
||||||
) -> GlobalCtxt<'tcx> {
|
) -> GlobalCtxt<'tcx> {
|
||||||
let ResolverOutputs {
|
|
||||||
definitions,
|
|
||||||
global_ctxt: untracked_resolutions,
|
|
||||||
ast_lowering: untracked_resolver_for_lowering,
|
|
||||||
} = resolver_outputs;
|
|
||||||
let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| {
|
let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| {
|
||||||
s.emit_fatal(err);
|
s.emit_fatal(err);
|
||||||
});
|
});
|
||||||
@ -1311,7 +1312,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
lifetimes: common_lifetimes,
|
lifetimes: common_lifetimes,
|
||||||
consts: common_consts,
|
consts: common_consts,
|
||||||
untracked_resolutions,
|
untracked_resolutions,
|
||||||
untracked_resolver_for_lowering: Steal::new(untracked_resolver_for_lowering),
|
|
||||||
untracked_crate: Steal::new(krate),
|
untracked_crate: Steal::new(krate),
|
||||||
on_disk_cache,
|
on_disk_cache,
|
||||||
queries,
|
queries,
|
||||||
@ -3114,7 +3114,6 @@ fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
|
|||||||
|
|
||||||
pub fn provide(providers: &mut ty::query::Providers) {
|
pub fn provide(providers: &mut ty::query::Providers) {
|
||||||
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
|
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
|
||||||
providers.resolver_for_lowering = |tcx, ()| &tcx.untracked_resolver_for_lowering;
|
|
||||||
providers.module_reexports =
|
providers.module_reexports =
|
||||||
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
|
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
|
||||||
providers.crate_name = |tcx, id| {
|
providers.crate_name = |tcx, id| {
|
||||||
|
@ -82,8 +82,8 @@ pub use self::consts::{
|
|||||||
pub use self::context::{
|
pub use self::context::{
|
||||||
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
||||||
CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GeneratorDiagnosticData,
|
CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GeneratorDiagnosticData,
|
||||||
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType,
|
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TyCtxtFeed, TypeckResults,
|
||||||
UserTypeAnnotationIndex,
|
UserType, UserTypeAnnotationIndex,
|
||||||
};
|
};
|
||||||
pub use self::instance::{Instance, InstanceDef, ShortInstance};
|
pub use self::instance::{Instance, InstanceDef, ShortInstance};
|
||||||
pub use self::list::List;
|
pub use self::list::List;
|
||||||
|
@ -328,6 +328,18 @@ macro_rules! define_callbacks {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! hash_result {
|
||||||
|
([]) => {{
|
||||||
|
Some(dep_graph::hash_result)
|
||||||
|
}};
|
||||||
|
([(no_hash) $($rest:tt)*]) => {{
|
||||||
|
None
|
||||||
|
}};
|
||||||
|
([$other:tt $($modifiers:tt)*]) => {
|
||||||
|
hash_result!([$($modifiers)*])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! define_feedable {
|
macro_rules! define_feedable {
|
||||||
($($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
($($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
||||||
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
|
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
|
||||||
@ -358,7 +370,7 @@ macro_rules! define_feedable {
|
|||||||
tcx,
|
tcx,
|
||||||
key,
|
key,
|
||||||
&value,
|
&value,
|
||||||
dep_graph::hash_result,
|
hash_result!([$($modifiers)*]),
|
||||||
);
|
);
|
||||||
cache.complete(key, value, dep_node_index)
|
cache.complete(key, value, dep_node_index)
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ impl<K: DepKind> DepGraph<K> {
|
|||||||
cx: Ctxt,
|
cx: Ctxt,
|
||||||
key: A,
|
key: A,
|
||||||
result: &R,
|
result: &R,
|
||||||
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Fingerprint,
|
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
|
||||||
) -> DepNodeIndex {
|
) -> DepNodeIndex {
|
||||||
if let Some(data) = self.data.as_ref() {
|
if let Some(data) = self.data.as_ref() {
|
||||||
// The caller query has more dependencies than the node we are creating. We may
|
// The caller query has more dependencies than the node we are creating. We may
|
||||||
@ -521,10 +521,12 @@ impl<K: DepKind> DepGraph<K> {
|
|||||||
// For sanity, we still check that the loaded stable hash and the new one match.
|
// For sanity, we still check that the loaded stable hash and the new one match.
|
||||||
if let Some(dep_node_index) = self.dep_node_index_of_opt(&node) {
|
if let Some(dep_node_index) = self.dep_node_index_of_opt(&node) {
|
||||||
let _current_fingerprint =
|
let _current_fingerprint =
|
||||||
crate::query::incremental_verify_ich(cx, result, &node, Some(hash_result));
|
crate::query::incremental_verify_ich(cx, result, &node, hash_result);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
data.current.record_edge(dep_node_index, node, _current_fingerprint);
|
if hash_result.is_some() {
|
||||||
|
data.current.record_edge(dep_node_index, node, _current_fingerprint);
|
||||||
|
}
|
||||||
|
|
||||||
return dep_node_index;
|
return dep_node_index;
|
||||||
}
|
}
|
||||||
@ -539,8 +541,9 @@ impl<K: DepKind> DepGraph<K> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let hashing_timer = cx.profiler().incr_result_hashing();
|
let hashing_timer = cx.profiler().incr_result_hashing();
|
||||||
let current_fingerprint =
|
let current_fingerprint = hash_result.map(|hash_result| {
|
||||||
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result));
|
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
|
||||||
|
});
|
||||||
|
|
||||||
let print_status = cfg!(debug_assertions) && cx.sess().opts.unstable_opts.dep_tasks;
|
let print_status = cfg!(debug_assertions) && cx.sess().opts.unstable_opts.dep_tasks;
|
||||||
|
|
||||||
@ -550,7 +553,7 @@ impl<K: DepKind> DepGraph<K> {
|
|||||||
&data.previous,
|
&data.previous,
|
||||||
node,
|
node,
|
||||||
edges,
|
edges,
|
||||||
Some(current_fingerprint),
|
current_fingerprint,
|
||||||
print_status,
|
print_status,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user