@@ -32,9 +32,7 @@ use rustc_data_structures::sync::{
3232use rustc_errors:: { Applicability , Diag , DiagCtxtHandle , Diagnostic , MultiSpan } ;
3333use rustc_hir:: def:: DefKind ;
3434use 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 } ;
3836use rustc_hir:: intravisit:: VisitorExt ;
3937use rustc_hir:: lang_items:: LangItem ;
4038use 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-
13031284impl < ' 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