4
4
5
5
pub mod tls;
6
6
7
+ use rustc_query_system:: query:: DefIdInfo ;
7
8
pub use rustc_type_ir:: lift:: Lift ;
8
9
9
10
use crate :: arena:: Arena ;
@@ -59,7 +60,6 @@ use rustc_index::IndexVec;
59
60
use rustc_macros:: { HashStable , TyDecodable , TyEncodable } ;
60
61
use rustc_query_system:: dep_graph:: { DepNodeIndex , TaskDepsRef } ;
61
62
use rustc_query_system:: ich:: StableHashingContext ;
62
- use rustc_query_system:: query:: DefIdInfo ;
63
63
use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
64
64
use rustc_session:: config:: CrateType ;
65
65
use rustc_session:: cstore:: { CrateStoreDyn , Untracked } ;
@@ -73,7 +73,7 @@ use rustc_target::spec::abi;
73
73
use rustc_type_ir:: TyKind :: * ;
74
74
use rustc_type_ir:: WithCachedTypeInfo ;
75
75
use rustc_type_ir:: { CollectAndApply , Interner , TypeFlags } ;
76
- use tracing:: { debug, instrument} ;
76
+ use tracing:: { debug, instrument, trace } ;
77
77
78
78
use std:: assert_matches:: assert_matches;
79
79
use std:: borrow:: Borrow ;
@@ -1330,14 +1330,15 @@ impl<'tcx> TyCtxtAt<'tcx> {
1330
1330
1331
1331
impl < ' tcx > TyCtxt < ' tcx > {
1332
1332
/// `tcx`-dependent operations performed for every created definition.
1333
+ #[ instrument( level = "trace" , skip( self ) ) ]
1333
1334
pub fn create_def (
1334
1335
self ,
1335
1336
parent : LocalDefId ,
1336
1337
name : Symbol ,
1337
1338
def_kind : DefKind ,
1338
1339
) -> TyCtxtFeed < ' tcx , LocalDefId > {
1339
1340
let data = def_kind. def_path_data ( name) ;
1340
- // The following call has the side effect of modifying the tables inside `definitions`.
1341
+ // The following create_def calls have the side effect of modifying the tables inside `definitions`.
1341
1342
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1342
1343
// decode the on-disk cache.
1343
1344
//
@@ -1350,31 +1351,47 @@ impl<'tcx> TyCtxt<'tcx> {
1350
1351
// This is fine because:
1351
1352
// - those queries are `eval_always` so we won't miss their result changing;
1352
1353
// - this write will have happened before these queries are called.
1353
- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1354
-
1355
- // This function modifies `self.definitions` using a side-effect.
1356
- // We need to ensure that these side effects are re-run by the incr. comp. engine.
1357
- tls:: with_context ( |icx| {
1354
+ let def_id = tls:: with_context ( |icx| {
1358
1355
match icx. task_deps {
1359
1356
// Always gets rerun anyway, so nothing to replay
1360
- TaskDepsRef :: EvalAlways => { }
1357
+ TaskDepsRef :: EvalAlways => {
1358
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1359
+ trace ! ( ?def_id, "eval always" ) ;
1360
+ def_id
1361
+ }
1361
1362
// Top-level queries like the resolver get rerun every time anyway
1362
- TaskDepsRef :: Ignore => { }
1363
+ TaskDepsRef :: Ignore => {
1364
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1365
+ trace ! ( ?def_id, "ignore" ) ;
1366
+ def_id
1367
+ }
1363
1368
TaskDepsRef :: Forbid => bug ! (
1364
1369
"cannot create definition {parent:?}, {name:?}, {def_kind:?} without being able to register task dependencies"
1365
1370
) ,
1366
1371
TaskDepsRef :: Allow ( _) => {
1367
- icx. side_effects
1368
- . as_ref ( )
1369
- . unwrap ( )
1370
- . lock ( )
1371
- . definitions
1372
- . push ( DefIdInfo { parent, data } ) ;
1372
+ let ( def_id, hash) =
1373
+ self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1374
+ trace ! ( ?def_id, "record side effects" ) ;
1375
+
1376
+ icx. side_effects . as_ref ( ) . unwrap ( ) . lock ( ) . definitions . push ( DefIdInfo {
1377
+ parent,
1378
+ data,
1379
+ hash,
1380
+ } ) ;
1381
+ def_id
1373
1382
}
1374
1383
TaskDepsRef :: Replay { prev_side_effects, created_def_ids } => {
1384
+ trace ! ( ?created_def_ids, "replay side effects" ) ;
1385
+ trace ! ( "num_defs : {}" , prev_side_effects. definitions. len( ) ) ;
1375
1386
let index = created_def_ids. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
1376
1387
let prev_info = & prev_side_effects. definitions [ index] ;
1377
- assert_eq ! ( * prev_info, DefIdInfo { parent, data } ) ;
1388
+ let def_id = self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id (
1389
+ prev_info. hash ,
1390
+ & "should have already recreated def id in try_mark_green" ,
1391
+ ) ;
1392
+ assert_eq ! ( prev_info. data, data) ;
1393
+ assert_eq ! ( prev_info. parent, parent) ;
1394
+ def_id
1378
1395
}
1379
1396
}
1380
1397
} ) ;
0 commit comments