Skip to content

Commit 533f0df

Browse files
committed
Drop the create_def_raw query.
1 parent 4455df9 commit 533f0df

5 files changed

Lines changed: 22 additions & 57 deletions

File tree

compiler/rustc_hir/src/definitions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap;
1111
use rustc_data_structures::stable_hasher::StableHasher;
1212
use rustc_hashes::Hash64;
1313
use rustc_index::IndexVec;
14-
use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable, extension};
14+
use rustc_macros::{BlobDecodable, Decodable, Encodable, extension};
1515
use rustc_span::def_id::LocalDefIdMap;
1616
use rustc_span::{Symbol, kw, sym};
1717
use tracing::{debug, instrument};
@@ -178,7 +178,7 @@ impl DefKey {
178178
/// between them. This introduces some artificial ordering dependency
179179
/// but means that if you have, e.g., two impls for the same type in
180180
/// the same module, they do get distinct `DefId`s.
181-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable, HashStable)]
181+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Encodable, BlobDecodable)]
182182
pub struct DisambiguatedDefPathData {
183183
pub data: DefPathData,
184184
pub disambiguator: u32,
@@ -299,7 +299,7 @@ impl DefPath {
299299
}
300300

301301
/// New variants should only be added in synchronization with `enum DefKind`.
302-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, BlobDecodable, HashStable)]
302+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, BlobDecodable)]
303303
pub enum DefPathData {
304304
// Root: these should only be used for the root nodes, because
305305
// they are treated specially by the `def_path` function.

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/query/keys.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::hash::Hash;
77
use rustc_ast::tokenstream::TokenStream;
88
use rustc_data_structures::stable_hasher::StableHash;
99
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId};
10-
use rustc_hir::definitions::DisambiguatedDefPathData;
1110
use rustc_hir::hir_id::OwnerId;
1211
use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol};
1312

@@ -361,11 +360,3 @@ impl<'tcx> QueryKey for (ty::Instance<'tcx>, CollectionMode) {
361360
self.0.default_span(tcx)
362361
}
363362
}
364-
365-
impl QueryKey for (LocalDefId, DisambiguatedDefPathData) {
366-
type Cache<V> = DefaultCache<Self, V>;
367-
368-
fn default_span(&self, _: TyCtxt<'_>) -> Span {
369-
DUMMY_SP
370-
}
371-
}

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;
@@ -1283,23 +1281,6 @@ impl<'tcx> TyCtxt<'tcx> {
12831281
}
12841282
}
12851283

1286-
#[instrument(level = "trace", skip(tcx), ret)]
1287-
fn create_def_raw_provider<'tcx>(
1288-
tcx: TyCtxt<'tcx>,
1289-
(parent, data): (LocalDefId, DisambiguatedDefPathData),
1290-
) -> LocalDefId {
1291-
// The following call has the side effect of modifying the tables inside `definitions`.
1292-
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1293-
// decode the on-disk cache.
1294-
//
1295-
// Any LocalDefId which is used within queries, either as key or result, either:
1296-
// - has been created before the construction of the TyCtxt;
1297-
// - has been created by this call to `create_def`.
1298-
// As a consequence, this LocalDefId is always re-created before it is needed by the incr.
1299-
// comp. engine itself.
1300-
tcx.untracked.definitions.write().create_def(parent, data)
1301-
}
1302-
13031284
impl<'tcx> TyCtxtAt<'tcx> {
13041285
/// Create a new definition within the incr. comp. engine.
13051286
pub fn create_def(
@@ -1334,22 +1315,28 @@ impl<'tcx> TyCtxt<'tcx> {
13341315
let data = disambiguator.disambiguate(parent, data);
13351316

13361317
let def_id = ty::tls::with_context(|icx| match icx.task_deps {
1337-
// `create_def_raw` is a query, so it can be replayed by the dep-graph engine.
1338-
// However, we may invoke it multiple times with the same `(parent, data)` pair,
1339-
// and we expect to create *different* definitions from them.
1340-
//
1341-
// In order to make this compatible with the general model of queries, we add
1342-
// additional information which must change at each call.
1318+
// If we are not tracking dependencies, we can use global mutable state.
1319+
// This is only an optimization to avoid the cost of registering the dep-node.
1320+
TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => {
1321+
self.untracked.definitions.write().create_def(parent, data)
1322+
}
1323+
1324+
// We are tracking dependencies, so we need to record a side-effect for the dep-graph
1325+
// to pick up in next execution.
13431326
TaskDepsRef::Allow(..) => {
13441327
self.dep_graph
13451328
.encode_side_effect(self, QuerySideEffect::CreateDef { parent, data });
1346-
self.create_def_raw((parent, data))
1329+
self.untracked.definitions.write().create_def(parent, data)
13471330
}
13481331

1349-
// If we are not tracking dependencies, we can use global mutable state.
1350-
// This is only an optimization to avoid the cost of registering the dep-node.
1351-
TaskDepsRef::EvalAlways | TaskDepsRef::Forbid | TaskDepsRef::Ignore => {
1352-
self.untracked.definitions.write().create_def(parent, data)
1332+
// We are in replay mode: the def-id has already been created by
1333+
// `dep_graph.force_side_effect`. We need to recover it, without creating a new one.
1334+
TaskDepsRef::Replay => {
1335+
let parent_hash = self.def_path_hash(parent.to_def_id());
1336+
let def_path_hash = data.compute_stable_hash(parent_hash);
1337+
self.def_path_hash_to_def_id(def_path_hash)
1338+
.expect("first execution should have created this definition")
1339+
.expect_local()
13531340
}
13541341
});
13551342

@@ -2788,5 +2775,4 @@ pub fn provide(providers: &mut Providers) {
27882775
tcx.lang_items().panic_impl().is_some_and(|did| did.is_local())
27892776
};
27902777
providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP);
2791-
providers.create_def_raw = create_def_raw_provider;
27922778
}

0 commit comments

Comments
 (0)