@@ -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 ;
@@ -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-
13421323impl < ' 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