Skip to content

Commit 0b90256

Browse files
committed
Auto merge of rust-lang#106776 - oli-obk:om_nom_nom_nom_nom, r=cjgillot
Feed a bunch of queries instead of tracking fields on TyCtxt r? `@cjgillot` pulled out of rust-lang#105462
2 parents 5ca6f7d + d36db0d commit 0b90256

File tree

8 files changed

+29
-46
lines changed

8 files changed

+29
-46
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ fn compute_hir_hash(
416416

417417
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
418418
let sess = tcx.sess;
419-
let krate = tcx.untracked_crate.steal();
420-
let mut resolver = tcx.resolver_for_lowering(()).steal();
419+
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
421420

422421
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
423422
let mut owners = IndexVec::from_fn_n(

compiler/rustc_interface/src/passes.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -817,23 +817,26 @@ pub fn create_global_ctxt<'tcx>(
817817
lint_store,
818818
arena,
819819
hir_arena,
820-
untracked_resolutions,
821820
untracked,
822-
krate,
823821
dep_graph,
824822
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
825823
queries.as_dyn(),
826824
rustc_query_impl::query_callbacks(arena),
827-
crate_name,
828-
outputs,
829825
)
830826
})
831827
});
832828

833829
let mut qcx = QueryContext { gcx };
834830
qcx.enter(|tcx| {
835-
tcx.feed_unit_query()
836-
.resolver_for_lowering(tcx.arena.alloc(Steal::new(untracked_resolver_for_lowering)))
831+
let feed = tcx.feed_unit_query();
832+
feed.resolver_for_lowering(
833+
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, krate))),
834+
);
835+
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
836+
feed.output_filenames(tcx.arena.alloc(std::sync::Arc::new(outputs)));
837+
feed.features_query(sess.features_untracked());
838+
let feed = tcx.feed_local_crate();
839+
feed.crate_name(crate_name);
837840
});
838841
qcx
839842
}

compiler/rustc_lint/src/expect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn provide(providers: &mut Providers) {
1111
}
1212

1313
fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
14-
if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
14+
if !tcx.features().enabled(sym::lint_reasons) {
1515
return;
1616
}
1717

compiler/rustc_middle/src/arena.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ macro_rules! arena_types {
3030
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
3131
[decode] borrowck_result:
3232
rustc_middle::mir::BorrowCheckResult<'tcx>,
33-
[] resolver: rustc_data_structures::steal::Steal<rustc_middle::ty::ResolverAstLowering>,
33+
[] resolver: rustc_data_structures::steal::Steal<(
34+
rustc_middle::ty::ResolverAstLowering,
35+
rustc_data_structures::sync::Lrc<rustc_ast::Crate>,
36+
)>,
37+
[] output_filenames: std::sync::Arc<rustc_session::config::OutputFilenames>,
38+
[] resolutions: rustc_middle::ty::ResolverGlobalCtxt,
3439
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
3540
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
3641
[] const_allocs: rustc_middle::mir::interpret::Allocation,

compiler/rustc_middle/src/query/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ rustc_queries! {
2727
}
2828

2929
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
30-
eval_always
30+
feedable
3131
no_hash
3232
desc { "getting the resolver outputs" }
3333
}
3434

35-
query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
35+
query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
3636
feedable
3737
no_hash
3838
desc { "getting the resolver for lowering" }
@@ -1673,7 +1673,7 @@ rustc_queries! {
16731673

16741674
/// Gets the name of the crate.
16751675
query crate_name(_: CrateNum) -> Symbol {
1676-
eval_always
1676+
feedable
16771677
desc { "fetching what a crate is named" }
16781678
separate_provide_extern
16791679
}
@@ -1857,7 +1857,7 @@ rustc_queries! {
18571857
/// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
18581858
/// has been destroyed.
18591859
query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1860-
eval_always
1860+
feedable
18611861
desc { "getting output filenames" }
18621862
}
18631863

@@ -2041,7 +2041,7 @@ rustc_queries! {
20412041
}
20422042

20432043
query features_query(_: ()) -> &'tcx rustc_feature::Features {
2044-
eval_always
2044+
feedable
20452045
desc { "looking up enabled feature gates" }
20462046
}
20472047

compiler/rustc_middle/src/ty/context.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use rustc_macros::HashStable;
5151
use rustc_query_system::dep_graph::DepNodeIndex;
5252
use rustc_query_system::ich::StableHashingContext;
5353
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
54-
use rustc_session::config::{CrateType, OutputFilenames};
54+
use rustc_session::config::CrateType;
5555
use rustc_session::cstore::{CrateStoreDyn, Untracked};
5656
use rustc_session::lint::Lint;
5757
use rustc_session::Limit;
@@ -74,7 +74,6 @@ use std::hash::{Hash, Hasher};
7474
use std::iter;
7575
use std::mem;
7676
use std::ops::{Bound, Deref};
77-
use std::sync::Arc;
7877

7978
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
8079
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
@@ -363,6 +362,9 @@ impl<'tcx> TyCtxt<'tcx> {
363362
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
364363
TyCtxtFeed { tcx: self, key: () }
365364
}
365+
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
366+
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
367+
}
366368
}
367369

368370
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
@@ -428,11 +430,6 @@ pub struct GlobalCtxt<'tcx> {
428430
pub consts: CommonConsts<'tcx>,
429431

430432
untracked: Untracked,
431-
/// Output of the resolver.
432-
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
433-
/// The entire crate as AST. This field serves as the input for the hir_crate query,
434-
/// which lowers it from AST to HIR. It must not be read or used by anything else.
435-
pub untracked_crate: Steal<Lrc<ast::Crate>>,
436433

437434
/// This provides access to the incremental compilation on-disk cache for query results.
438435
/// Do not access this directly. It is only meant to be used by
@@ -457,17 +454,11 @@ pub struct GlobalCtxt<'tcx> {
457454
/// Merge this with `selection_cache`?
458455
pub evaluation_cache: traits::EvaluationCache<'tcx>,
459456

460-
/// The definite name of the current crate after taking into account
461-
/// attributes, commandline parameters, etc.
462-
crate_name: Symbol,
463-
464457
/// Data layout specification for the current target.
465458
pub data_layout: TargetDataLayout,
466459

467460
/// Stores memory for globals (statics/consts).
468461
pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,
469-
470-
output_filenames: Arc<OutputFilenames>,
471462
}
472463

473464
impl<'tcx> TyCtxt<'tcx> {
@@ -592,15 +583,11 @@ impl<'tcx> TyCtxt<'tcx> {
592583
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
593584
arena: &'tcx WorkerLocal<Arena<'tcx>>,
594585
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
595-
untracked_resolutions: ty::ResolverGlobalCtxt,
596586
untracked: Untracked,
597-
krate: Lrc<ast::Crate>,
598587
dep_graph: DepGraph,
599588
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
600589
queries: &'tcx dyn query::QueryEngine<'tcx>,
601590
query_kinds: &'tcx [DepKindStruct<'tcx>],
602-
crate_name: Symbol,
603-
output_filenames: OutputFilenames,
604591
) -> GlobalCtxt<'tcx> {
605592
let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| {
606593
s.emit_fatal(err);
@@ -622,8 +609,6 @@ impl<'tcx> TyCtxt<'tcx> {
622609
lifetimes: common_lifetimes,
623610
consts: common_consts,
624611
untracked,
625-
untracked_resolutions,
626-
untracked_crate: Steal::new(krate),
627612
on_disk_cache,
628613
queries,
629614
query_caches: query::QueryCaches::default(),
@@ -632,10 +617,8 @@ impl<'tcx> TyCtxt<'tcx> {
632617
pred_rcache: Default::default(),
633618
selection_cache: Default::default(),
634619
evaluation_cache: Default::default(),
635-
crate_name,
636620
data_layout,
637621
alloc_map: Lock::new(interpret::AllocMap::new()),
638-
output_filenames: Arc::new(output_filenames),
639622
}
640623
}
641624

@@ -810,7 +793,7 @@ impl<'tcx> TyCtxt<'tcx> {
810793
// statements within the query system and we'd run into endless
811794
// recursion otherwise.
812795
let (crate_name, stable_crate_id) = if def_id.is_local() {
813-
(self.crate_name, self.sess.local_stable_crate_id())
796+
(self.crate_name(LOCAL_CRATE), self.sess.local_stable_crate_id())
814797
} else {
815798
let cstore = &*self.untracked.cstore;
816799
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
@@ -2407,13 +2390,8 @@ fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
24072390
}
24082391

24092392
pub fn provide(providers: &mut ty::query::Providers) {
2410-
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
24112393
providers.module_reexports =
24122394
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
2413-
providers.crate_name = |tcx, id| {
2414-
assert_eq!(id, LOCAL_CRATE);
2415-
tcx.crate_name
2416-
};
24172395
providers.maybe_unused_trait_imports =
24182396
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
24192397
providers.maybe_unused_extern_crates =
@@ -2424,8 +2402,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
24242402

24252403
providers.extern_mod_stmt_cnum =
24262404
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
2427-
providers.output_filenames = |tcx, ()| &tcx.output_filenames;
2428-
providers.features_query = |tcx, ()| tcx.sess.features_untracked();
24292405
providers.is_panic_runtime = |tcx, cnum| {
24302406
assert_eq!(cnum, LOCAL_CRATE);
24312407
tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
12211221
) {
12221222
let ast_attrs = self.tcx.hir().attrs(hir_id);
12231223
if let Some(ref cfg) = ast_attrs.cfg(self.tcx, &FxHashSet::default()) {
1224-
if !cfg.matches(&self.sess.parse_sess, Some(self.sess.features_untracked())) {
1224+
if !cfg.matches(&self.sess.parse_sess, Some(self.tcx.features())) {
12251225
return;
12261226
}
12271227
}

src/tools/clippy/clippy_lints/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMe
472472

473473
fn check_lint_reason(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem], attr: &'_ Attribute) {
474474
// Check for the feature
475-
if !cx.tcx.sess.features_untracked().lint_reasons {
475+
if !cx.tcx.features().lint_reasons {
476476
return;
477477
}
478478

0 commit comments

Comments
 (0)