Skip to content

Commit f693b78

Browse files
committed
feed resolver_for_lowering instead of storing it in a field
1 parent 125b729 commit f693b78

File tree

8 files changed

+50
-26
lines changed

8 files changed

+50
-26
lines changed

compiler/rustc_interface/src/passes.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_ast::{self as ast, visit};
1212
use rustc_borrowck as mir_borrowck;
1313
use rustc_codegen_ssa::traits::CodegenBackend;
1414
use rustc_data_structures::parallel;
15+
use rustc_data_structures::steal::Steal;
1516
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
1617
use rustc_errors::{ErrorGuaranteed, PResult};
1718
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
@@ -804,14 +805,21 @@ pub fn create_global_ctxt<'tcx>(
804805
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
805806
});
806807

808+
let ty::ResolverOutputs {
809+
definitions,
810+
global_ctxt: untracked_resolutions,
811+
ast_lowering: untracked_resolver_for_lowering,
812+
} = resolver_outputs;
813+
807814
let gcx = sess.time("setup_global_ctxt", || {
808815
global_ctxt.get_or_init(move || {
809816
TyCtxt::create_global_ctxt(
810817
sess,
811818
lint_store,
812819
arena,
813820
hir_arena,
814-
resolver_outputs,
821+
definitions,
822+
untracked_resolutions,
815823
krate,
816824
dep_graph,
817825
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
@@ -823,7 +831,12 @@ pub fn create_global_ctxt<'tcx>(
823831
})
824832
});
825833

826-
QueryContext { gcx }
834+
let mut qcx = QueryContext { gcx };
835+
qcx.enter(|tcx| {
836+
tcx.feed_unit_query()
837+
.resolver_for_lowering(tcx.arena.alloc(Steal::new(untracked_resolver_for_lowering)))
838+
});
839+
qcx
827840
}
828841

829842
/// Runs the resolution, type-checking, region checking and other

compiler/rustc_macros/src/query.rs

-4
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
364364
modifiers.eval_always.is_none(),
365365
"Query {name} cannot be both `feedable` and `eval_always`."
366366
);
367-
assert!(
368-
modifiers.no_hash.is_none(),
369-
"Query {name} cannot be both `feedable` and `no_hash`."
370-
);
371367
feedable_queries.extend(quote! {
372368
#(#doc_comments)*
373369
[#attribute_stream] fn #name(#arg) #result,

compiler/rustc_middle/src/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ macro_rules! arena_types {
2828
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
2929
[decode] borrowck_result:
3030
rustc_middle::mir::BorrowCheckResult<'tcx>,
31+
[] resolver: rustc_data_structures::steal::Steal<rustc_middle::ty::ResolverAstLowering>,
3132
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
3233
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
3334
[] const_allocs: rustc_middle::mir::interpret::Allocation,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rustc_queries! {
3333
}
3434

3535
query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
36-
eval_always
36+
feedable
3737
no_hash
3838
desc { "getting the resolver for lowering" }
3939
}

compiler/rustc_middle/src/ty/context.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use std::mem;
8181
use std::ops::{Bound, Deref};
8282
use std::sync::Arc;
8383

84-
use super::{ImplPolarity, ResolverOutputs, RvalueScopes};
84+
use super::{ImplPolarity, RvalueScopes};
8585

8686
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
8787
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
@@ -1040,6 +1040,12 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> {
10401040
key: KEY,
10411041
}
10421042

1043+
impl<'tcx> TyCtxt<'tcx> {
1044+
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
1045+
TyCtxtFeed { tcx: self, key: () }
1046+
}
1047+
}
1048+
10431049
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
10441050
#[inline(always)]
10451051
pub fn key(&self) -> KEY {
@@ -1106,7 +1112,6 @@ pub struct GlobalCtxt<'tcx> {
11061112

11071113
/// Output of the resolver.
11081114
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
1109-
untracked_resolver_for_lowering: Steal<ty::ResolverAstLowering>,
11101115
/// The entire crate as AST. This field serves as the input for the hir_crate query,
11111116
/// which lowers it from AST to HIR. It must not be read or used by anything else.
11121117
pub untracked_crate: Steal<Lrc<ast::Crate>>,
@@ -1269,7 +1274,8 @@ impl<'tcx> TyCtxt<'tcx> {
12691274
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
12701275
arena: &'tcx WorkerLocal<Arena<'tcx>>,
12711276
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
1272-
resolver_outputs: ResolverOutputs,
1277+
definitions: Definitions,
1278+
untracked_resolutions: ty::ResolverGlobalCtxt,
12731279
krate: Lrc<ast::Crate>,
12741280
dep_graph: DepGraph,
12751281
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
@@ -1278,11 +1284,6 @@ impl<'tcx> TyCtxt<'tcx> {
12781284
crate_name: &str,
12791285
output_filenames: OutputFilenames,
12801286
) -> GlobalCtxt<'tcx> {
1281-
let ResolverOutputs {
1282-
definitions,
1283-
global_ctxt: untracked_resolutions,
1284-
ast_lowering: untracked_resolver_for_lowering,
1285-
} = resolver_outputs;
12861287
let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| {
12871288
s.emit_fatal(err);
12881289
});
@@ -1311,7 +1312,6 @@ impl<'tcx> TyCtxt<'tcx> {
13111312
lifetimes: common_lifetimes,
13121313
consts: common_consts,
13131314
untracked_resolutions,
1314-
untracked_resolver_for_lowering: Steal::new(untracked_resolver_for_lowering),
13151315
untracked_crate: Steal::new(krate),
13161316
on_disk_cache,
13171317
queries,
@@ -3114,7 +3114,6 @@ fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
31143114

31153115
pub fn provide(providers: &mut ty::query::Providers) {
31163116
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
3117-
providers.resolver_for_lowering = |tcx, ()| &tcx.untracked_resolver_for_lowering;
31183117
providers.module_reexports =
31193118
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
31203119
providers.crate_name = |tcx, id| {

compiler/rustc_middle/src/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ pub use self::consts::{
8282
pub use self::context::{
8383
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
8484
CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GeneratorDiagnosticData,
85-
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType,
86-
UserTypeAnnotationIndex,
85+
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TyCtxtFeed, TypeckResults,
86+
UserType, UserTypeAnnotationIndex,
8787
};
8888
pub use self::instance::{Instance, InstanceDef, ShortInstance};
8989
pub use self::list::List;

compiler/rustc_middle/src/ty/query.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,18 @@ macro_rules! define_callbacks {
328328
};
329329
}
330330

331+
macro_rules! hash_result {
332+
([]) => {{
333+
Some(dep_graph::hash_result)
334+
}};
335+
([(no_hash) $($rest:tt)*]) => {{
336+
None
337+
}};
338+
([$other:tt $($modifiers:tt)*]) => {
339+
hash_result!([$($modifiers)*])
340+
};
341+
}
342+
331343
macro_rules! define_feedable {
332344
($($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
333345
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
@@ -358,7 +370,7 @@ macro_rules! define_feedable {
358370
tcx,
359371
key,
360372
&value,
361-
dep_graph::hash_result,
373+
hash_result!([$($modifiers)*]),
362374
);
363375
cache.complete(key, value, dep_node_index)
364376
}

compiler/rustc_query_system/src/dep_graph/graph.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl<K: DepKind> DepGraph<K> {
510510
cx: Ctxt,
511511
key: A,
512512
result: &R,
513-
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Fingerprint,
513+
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
514514
) -> DepNodeIndex {
515515
if let Some(data) = self.data.as_ref() {
516516
// The caller query has more dependencies than the node we are creating. We may
@@ -521,10 +521,12 @@ impl<K: DepKind> DepGraph<K> {
521521
// For sanity, we still check that the loaded stable hash and the new one match.
522522
if let Some(dep_node_index) = self.dep_node_index_of_opt(&node) {
523523
let _current_fingerprint =
524-
crate::query::incremental_verify_ich(cx, result, &node, Some(hash_result));
524+
crate::query::incremental_verify_ich(cx, result, &node, hash_result);
525525

526526
#[cfg(debug_assertions)]
527-
data.current.record_edge(dep_node_index, node, _current_fingerprint);
527+
if hash_result.is_some() {
528+
data.current.record_edge(dep_node_index, node, _current_fingerprint);
529+
}
528530

529531
return dep_node_index;
530532
}
@@ -539,8 +541,9 @@ impl<K: DepKind> DepGraph<K> {
539541
});
540542

541543
let hashing_timer = cx.profiler().incr_result_hashing();
542-
let current_fingerprint =
543-
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result));
544+
let current_fingerprint = hash_result.map(|hash_result| {
545+
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
546+
});
544547

545548
let print_status = cfg!(debug_assertions) && cx.sess().opts.unstable_opts.dep_tasks;
546549

@@ -550,7 +553,7 @@ impl<K: DepKind> DepGraph<K> {
550553
&data.previous,
551554
node,
552555
edges,
553-
Some(current_fingerprint),
556+
current_fingerprint,
554557
print_status,
555558
);
556559

0 commit comments

Comments
 (0)