Skip to content

Commit 41ad623

Browse files
committed
Drop the create_def_raw query.
1 parent ee9c669 commit 41ad623

3 files changed

Lines changed: 19 additions & 45 deletions

File tree

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl DepGraphData {
739739
tcx.sess.used_features.lock().insert(*symbol, dep_node_index.as_u32());
740740
}
741741
QuerySideEffect::CreateDef { parent, data } => {
742-
tcx.ensure_done().create_def_raw((*parent, *data));
742+
tcx.untracked().definitions.write().create_def(*parent, *data);
743743
}
744744
}
745745

compiler/rustc_middle/src/queries.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ use rustc_hir::def::{DefKind, DocLinkResMap};
6767
use rustc_hir::def_id::{
6868
CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
6969
};
70-
use rustc_hir::definitions::DisambiguatedDefPathData;
7170
use rustc_hir::lang_items::{LangItem, LanguageItems};
7271
use rustc_hir::{ItemLocalId, ItemLocalMap, PreciseCapturingArgKind, TraitCandidate};
7372
use rustc_index::IndexVec;
@@ -199,17 +198,6 @@ rustc_queries! {
199198
desc { "getting the source span" }
200199
}
201200

202-
/// Create a new definition.
203-
///
204-
/// This query is meant to wrap a side-effect and return the resulting newly created
205-
/// definition. In incremental mode, when replaying a query, this query caches the side-effect
206-
/// to avoid performing it twice.
207-
query create_def_raw(key: (LocalDefId, DisambiguatedDefPathData)) -> LocalDefId {
208-
// Accesses untracked data
209-
eval_always
210-
desc { "create a new definition for `{}::{:?}`", tcx.def_path_str(key.0), key.1 }
211-
}
212-
213201
/// Represents crate as a whole (as distinct from the top-level crate module).
214202
///
215203
/// If you call `tcx.hir_crate(())` we will have to assume that any change

compiler/rustc_middle/src/ty/context.rs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ use rustc_data_structures::sync::{
3232
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, MultiSpan};
3333
use rustc_hir::def::DefKind;
3434
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, StableCrateIdMap};
35-
use rustc_hir::definitions::{
36-
DefPathData, Definitions, DisambiguatedDefPathData, PerParentDisambiguatorState,
37-
};
35+
use rustc_hir::definitions::{DefPathData, Definitions, PerParentDisambiguatorState};
3836
use rustc_hir::intravisit::VisitorExt;
3937
use rustc_hir::lang_items::LangItem;
4038
use rustc_hir::limit::Limit;
@@ -1322,23 +1320,6 @@ impl<'tcx> TyCtxt<'tcx> {
13221320
}
13231321
}
13241322

1325-
#[instrument(level = "trace", skip(tcx), ret)]
1326-
fn create_def_raw_provider<'tcx>(
1327-
tcx: TyCtxt<'tcx>,
1328-
(parent, data): (LocalDefId, DisambiguatedDefPathData),
1329-
) -> LocalDefId {
1330-
// The following call has the side effect of modifying the tables inside `definitions`.
1331-
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1332-
// decode the on-disk cache.
1333-
//
1334-
// Any LocalDefId which is used within queries, either as key or result, either:
1335-
// - has been created before the construction of the TyCtxt;
1336-
// - has been created by this call to `create_def`.
1337-
// As a consequence, this LocalDefId is always re-created before it is needed by the incr.
1338-
// comp. engine itself.
1339-
tcx.untracked.definitions.write().create_def(parent, data)
1340-
}
1341-
13421323
impl<'tcx> TyCtxtAt<'tcx> {
13431324
/// Create a new definition within the incr. comp. engine.
13441325
pub fn create_def(
@@ -1373,22 +1354,28 @@ impl<'tcx> TyCtxt<'tcx> {
13731354
let data = disambiguator.disambiguate(parent, data);
13741355

13751356
let def_id = ty::tls::with_context(|icx| match icx.task_deps {
1376-
// `create_def_raw` is a query, so it can be replayed by the dep-graph engine.
1377-
// However, we may invoke it multiple times with the same `(parent, data)` pair,
1378-
// and we expect to create *different* definitions from them.
1379-
//
1380-
// In order to make this compatible with the general model of queries, we add
1381-
// additional information which must change at each call.
1357+
// If we are not tracking dependencies, we can use global mutable state.
1358+
// This is only an optimization to avoid the cost of registering the dep-node.
1359+
TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => {
1360+
self.untracked.definitions.write().create_def(parent, data)
1361+
}
1362+
1363+
// We are tracking dependencies, so we need to record a side-effect for the dep-graph
1364+
// to pick up in next execution.
13821365
TaskDepsRef::Allow(..) => {
13831366
self.dep_graph
13841367
.encode_side_effect(self, QuerySideEffect::CreateDef { parent, data });
1385-
self.create_def_raw((parent, data))
1368+
self.untracked.definitions.write().create_def(parent, data)
13861369
}
13871370

1388-
// If we are not tracking dependencies, we can use global mutable state.
1389-
// This is only an optimization to avoid the cost of registering the dep-node.
1390-
TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => {
1391-
self.untracked.definitions.write().create_def(parent, data)
1371+
// We are in replay mode: the def-id has already been created by
1372+
// `dep_graph.force_side_effect`. We need to recover it, without creating a new one.
1373+
TaskDepsRef::Replay => {
1374+
let parent_hash = self.def_path_hash(parent.to_def_id());
1375+
let def_path_hash = data.compute_stable_hash(parent_hash);
1376+
self.def_path_hash_to_def_id(def_path_hash)
1377+
.expect("first execution should have created this definition")
1378+
.expect_local()
13921379
}
13931380
});
13941381

@@ -2827,5 +2814,4 @@ pub fn provide(providers: &mut Providers) {
28272814
tcx.lang_items().panic_impl().is_some_and(|did| did.is_local())
28282815
};
28292816
providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP);
2830-
providers.create_def_raw = create_def_raw_provider;
28312817
}

0 commit comments

Comments
 (0)