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 ;
@@ -1333,14 +1333,15 @@ impl<'tcx> TyCtxtAt<'tcx> {
1333
1333
1334
1334
impl < ' tcx > TyCtxt < ' tcx > {
1335
1335
/// `tcx`-dependent operations performed for every created definition.
1336
+ #[ instrument( level = "trace" , skip( self ) ) ]
1336
1337
pub fn create_def (
1337
1338
self ,
1338
1339
parent : LocalDefId ,
1339
1340
name : Symbol ,
1340
1341
def_kind : DefKind ,
1341
1342
) -> TyCtxtFeed < ' tcx , LocalDefId > {
1342
1343
let data = def_kind. def_path_data ( name) ;
1343
- // The following call has the side effect of modifying the tables inside `definitions`.
1344
+ // The following create_def calls have the side effect of modifying the tables inside `definitions`.
1344
1345
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1345
1346
// decode the on-disk cache.
1346
1347
//
@@ -1353,31 +1354,47 @@ impl<'tcx> TyCtxt<'tcx> {
1353
1354
// This is fine because:
1354
1355
// - those queries are `eval_always` so we won't miss their result changing;
1355
1356
// - this write will have happened before these queries are called.
1356
- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1357
-
1358
- // This function modifies `self.definitions` using a side-effect.
1359
- // We need to ensure that these side effects are re-run by the incr. comp. engine.
1360
- tls:: with_context ( |icx| {
1357
+ let def_id = tls:: with_context ( |icx| {
1361
1358
match icx. task_deps {
1362
1359
// Always gets rerun anyway, so nothing to replay
1363
- TaskDepsRef :: EvalAlways => { }
1360
+ TaskDepsRef :: EvalAlways => {
1361
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1362
+ trace ! ( ?def_id, "eval always" ) ;
1363
+ def_id
1364
+ }
1364
1365
// Top-level queries like the resolver get rerun every time anyway
1365
- TaskDepsRef :: Ignore => { }
1366
+ TaskDepsRef :: Ignore => {
1367
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1368
+ trace ! ( ?def_id, "ignore" ) ;
1369
+ def_id
1370
+ }
1366
1371
TaskDepsRef :: Forbid => bug ! (
1367
1372
"cannot create definition {parent:?}, {name:?}, {def_kind:?} without being able to register task dependencies"
1368
1373
) ,
1369
1374
TaskDepsRef :: Allow ( _) => {
1370
- icx. side_effects
1371
- . as_ref ( )
1372
- . unwrap ( )
1373
- . lock ( )
1374
- . definitions
1375
- . push ( DefIdInfo { parent, data } ) ;
1375
+ let ( def_id, hash) =
1376
+ self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1377
+ trace ! ( ?def_id, "record side effects" ) ;
1378
+
1379
+ icx. side_effects . as_ref ( ) . unwrap ( ) . lock ( ) . definitions . push ( DefIdInfo {
1380
+ parent,
1381
+ data,
1382
+ hash,
1383
+ } ) ;
1384
+ def_id
1376
1385
}
1377
1386
TaskDepsRef :: Replay { prev_side_effects, created_def_ids } => {
1387
+ trace ! ( ?created_def_ids, "replay side effects" ) ;
1388
+ trace ! ( "num_defs : {}" , prev_side_effects. definitions. len( ) ) ;
1378
1389
let index = created_def_ids. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
1379
1390
let prev_info = & prev_side_effects. definitions [ index] ;
1380
- assert_eq ! ( * prev_info, DefIdInfo { parent, data } ) ;
1391
+ let def_id = self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id (
1392
+ prev_info. hash ,
1393
+ & "should have already recreated def id in try_mark_green" ,
1394
+ ) ;
1395
+ assert_eq ! ( prev_info. data, data) ;
1396
+ assert_eq ! ( prev_info. parent, parent) ;
1397
+ def_id
1381
1398
}
1382
1399
}
1383
1400
} ) ;
0 commit comments