Skip to content

Commit

Permalink
Auto merge of #106776 - oli-obk:om_nom_nom_nom_nom, r=cjgillot
Browse files Browse the repository at this point in the history
Feed a bunch of queries instead of tracking fields on TyCtxt

r? `@cjgillot`

pulled out of #105462
  • Loading branch information
bors committed Jan 13, 2023
2 parents 5ca6f7d + d36db0d commit 0b90256
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 46 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -416,8 +416,7 @@ fn compute_hir_hash(

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

let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
let mut owners = IndexVec::from_fn_n(
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_interface/src/passes.rs
Expand Up @@ -817,23 +817,26 @@ pub fn create_global_ctxt<'tcx>(
lint_store,
arena,
hir_arena,
untracked_resolutions,
untracked,
krate,
dep_graph,
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
queries.as_dyn(),
rustc_query_impl::query_callbacks(arena),
crate_name,
outputs,
)
})
});

let mut qcx = QueryContext { gcx };
qcx.enter(|tcx| {
tcx.feed_unit_query()
.resolver_for_lowering(tcx.arena.alloc(Steal::new(untracked_resolver_for_lowering)))
let feed = tcx.feed_unit_query();
feed.resolver_for_lowering(
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, krate))),
);
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
feed.output_filenames(tcx.arena.alloc(std::sync::Arc::new(outputs)));
feed.features_query(sess.features_untracked());
let feed = tcx.feed_local_crate();
feed.crate_name(crate_name);
});
qcx
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/expect.rs
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn provide(providers: &mut Providers) {
}

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

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_middle/src/arena.rs
Expand Up @@ -30,7 +30,12 @@ macro_rules! arena_types {
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
[decode] borrowck_result:
rustc_middle::mir::BorrowCheckResult<'tcx>,
[] resolver: rustc_data_structures::steal::Steal<rustc_middle::ty::ResolverAstLowering>,
[] resolver: rustc_data_structures::steal::Steal<(
rustc_middle::ty::ResolverAstLowering,
rustc_data_structures::sync::Lrc<rustc_ast::Crate>,
)>,
[] output_filenames: std::sync::Arc<rustc_session::config::OutputFilenames>,
[] resolutions: rustc_middle::ty::ResolverGlobalCtxt,
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,
[decode] code_region: rustc_middle::mir::coverage::CodeRegion,
[] const_allocs: rustc_middle::mir::interpret::Allocation,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/query/mod.rs
Expand Up @@ -27,12 +27,12 @@ rustc_queries! {
}

query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
eval_always
feedable
no_hash
desc { "getting the resolver outputs" }
}

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

/// Gets the name of the crate.
query crate_name(_: CrateNum) -> Symbol {
eval_always
feedable
desc { "fetching what a crate is named" }
separate_provide_extern
}
Expand Down Expand Up @@ -1857,7 +1857,7 @@ rustc_queries! {
/// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
/// has been destroyed.
query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
eval_always
feedable
desc { "getting output filenames" }
}

Expand Down Expand Up @@ -2041,7 +2041,7 @@ rustc_queries! {
}

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

Expand Down
34 changes: 5 additions & 29 deletions compiler/rustc_middle/src/ty/context.rs
Expand Up @@ -51,7 +51,7 @@ use rustc_macros::HashStable;
use rustc_query_system::dep_graph::DepNodeIndex;
use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_session::config::{CrateType, OutputFilenames};
use rustc_session::config::CrateType;
use rustc_session::cstore::{CrateStoreDyn, Untracked};
use rustc_session::lint::Lint;
use rustc_session::Limit;
Expand All @@ -74,7 +74,6 @@ use std::hash::{Hash, Hasher};
use std::iter;
use std::mem;
use std::ops::{Bound, Deref};
use std::sync::Arc;

pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
Expand Down Expand Up @@ -363,6 +362,9 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
TyCtxtFeed { tcx: self, key: () }
}
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
}
}

impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
Expand Down Expand Up @@ -428,11 +430,6 @@ pub struct GlobalCtxt<'tcx> {
pub consts: CommonConsts<'tcx>,

untracked: Untracked,
/// Output of the resolver.
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
/// 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.
pub untracked_crate: Steal<Lrc<ast::Crate>>,

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

/// The definite name of the current crate after taking into account
/// attributes, commandline parameters, etc.
crate_name: Symbol,

/// Data layout specification for the current target.
pub data_layout: TargetDataLayout,

/// Stores memory for globals (statics/consts).
pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,

output_filenames: Arc<OutputFilenames>,
}

impl<'tcx> TyCtxt<'tcx> {
Expand Down Expand Up @@ -592,15 +583,11 @@ impl<'tcx> TyCtxt<'tcx> {
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
untracked_resolutions: ty::ResolverGlobalCtxt,
untracked: Untracked,
krate: Lrc<ast::Crate>,
dep_graph: DepGraph,
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
queries: &'tcx dyn query::QueryEngine<'tcx>,
query_kinds: &'tcx [DepKindStruct<'tcx>],
crate_name: Symbol,
output_filenames: OutputFilenames,
) -> GlobalCtxt<'tcx> {
let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| {
s.emit_fatal(err);
Expand All @@ -622,8 +609,6 @@ impl<'tcx> TyCtxt<'tcx> {
lifetimes: common_lifetimes,
consts: common_consts,
untracked,
untracked_resolutions,
untracked_crate: Steal::new(krate),
on_disk_cache,
queries,
query_caches: query::QueryCaches::default(),
Expand All @@ -632,10 +617,8 @@ impl<'tcx> TyCtxt<'tcx> {
pred_rcache: Default::default(),
selection_cache: Default::default(),
evaluation_cache: Default::default(),
crate_name,
data_layout,
alloc_map: Lock::new(interpret::AllocMap::new()),
output_filenames: Arc::new(output_filenames),
}
}

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

pub fn provide(providers: &mut ty::query::Providers) {
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
providers.module_reexports =
|tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
providers.crate_name = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
tcx.crate_name
};
providers.maybe_unused_trait_imports =
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
providers.maybe_unused_extern_crates =
Expand All @@ -2424,8 +2402,6 @@ pub fn provide(providers: &mut ty::query::Providers) {

providers.extern_mod_stmt_cnum =
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
providers.output_filenames = |tcx, ()| &tcx.output_filenames;
providers.features_query = |tcx, ()| tcx.sess.features_untracked();
providers.is_panic_runtime = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Expand Up @@ -1221,7 +1221,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
) {
let ast_attrs = self.tcx.hir().attrs(hir_id);
if let Some(ref cfg) = ast_attrs.cfg(self.tcx, &FxHashSet::default()) {
if !cfg.matches(&self.sess.parse_sess, Some(self.sess.features_untracked())) {
if !cfg.matches(&self.sess.parse_sess, Some(self.tcx.features())) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/attrs.rs
Expand Up @@ -472,7 +472,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMe

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

Expand Down

0 comments on commit 0b90256

Please sign in to comment.