Auto merge of #123126 - oli-obk:feed_crate_num, r=davidtwco

Enable `CrateNum` query feeding via `TyCtxt`

Instead of having a magic function that violates some `TyCtxtFeed` invariants, add a `create_def` equivalent for `CrateNum`s.

Note that this still isn't tracked by the query system (unlike `create_def`), and that feeding most `CrateNum` queries for crates other than the local one will likely cause performance regressions.

These things should be attempted on their own separately, but this PR should stand on its own
This commit is contained in:
bors 2024-04-23 20:46:48 +00:00
commit 244da22fab
5 changed files with 61 additions and 48 deletions

View file

@ -8,7 +8,7 @@ use rustc_codegen_ssa::CodegenResults;
use rustc_data_structures::steal::Steal;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
use rustc_hir::def_id::{StableCrateId, StableCrateIdMap, LOCAL_CRATE};
use rustc_hir::definitions::Definitions;
use rustc_incremental::setup_dep_graph;
use rustc_metadata::creader::CStore;
@ -140,11 +140,16 @@ impl<'tcx> Queries<'tcx> {
let cstore = FreezeLock::new(Box::new(CStore::new(
self.compiler.codegen_backend.metadata_loader(),
stable_crate_id,
)) as _);
let definitions = FreezeLock::new(Definitions::new(stable_crate_id));
let untracked =
Untracked { cstore, source_span: AppendOnlyIndexVec::new(), definitions };
let stable_crate_ids = FreezeLock::new(StableCrateIdMap::default());
let untracked = Untracked {
cstore,
source_span: AppendOnlyIndexVec::new(),
definitions,
stable_crate_ids,
};
let qcx = passes::create_global_ctxt(
self.compiler,
@ -158,7 +163,8 @@ impl<'tcx> Queries<'tcx> {
);
qcx.enter(|tcx| {
let feed = tcx.feed_local_crate();
let feed = tcx.create_crate_num(stable_crate_id).unwrap();
assert_eq!(feed.key(), LOCAL_CRATE);
feed.crate_name(crate_name);
let feed = tcx.feed_unit_query();