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 } ;
@@ -74,7 +74,7 @@ use rustc_type_ir::fold::TypeFoldable;
74
74
use rustc_type_ir:: TyKind :: * ;
75
75
use rustc_type_ir:: WithCachedTypeInfo ;
76
76
use rustc_type_ir:: { CollectAndApply , Interner , TypeFlags } ;
77
- use tracing:: { debug, instrument} ;
77
+ use tracing:: { debug, instrument, trace } ;
78
78
79
79
use std:: assert_matches:: assert_matches;
80
80
use std:: borrow:: Borrow ;
@@ -1363,14 +1363,15 @@ impl<'tcx> TyCtxtAt<'tcx> {
1363
1363
1364
1364
impl < ' tcx > TyCtxt < ' tcx > {
1365
1365
/// `tcx`-dependent operations performed for every created definition.
1366
+ #[ instrument( level = "trace" , skip( self ) ) ]
1366
1367
pub fn create_def (
1367
1368
self ,
1368
1369
parent : LocalDefId ,
1369
1370
name : Symbol ,
1370
1371
def_kind : DefKind ,
1371
1372
) -> TyCtxtFeed < ' tcx , LocalDefId > {
1372
1373
let data = def_kind. def_path_data ( name) ;
1373
- // The following call has the side effect of modifying the tables inside `definitions`.
1374
+ // The following create_def calls have the side effect of modifying the tables inside `definitions`.
1374
1375
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1375
1376
// decode the on-disk cache.
1376
1377
//
@@ -1383,31 +1384,47 @@ impl<'tcx> TyCtxt<'tcx> {
1383
1384
// This is fine because:
1384
1385
// - those queries are `eval_always` so we won't miss their result changing;
1385
1386
// - this write will have happened before these queries are called.
1386
- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1387
-
1388
- // This function modifies `self.definitions` using a side-effect.
1389
- // We need to ensure that these side effects are re-run by the incr. comp. engine.
1390
- tls:: with_context ( |icx| {
1387
+ let def_id = tls:: with_context ( |icx| {
1391
1388
match icx. task_deps {
1392
1389
// Always gets rerun anyway, so nothing to replay
1393
- TaskDepsRef :: EvalAlways => { }
1390
+ TaskDepsRef :: EvalAlways => {
1391
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1392
+ trace ! ( ?def_id, "eval always" ) ;
1393
+ def_id
1394
+ }
1394
1395
// Top-level queries like the resolver get rerun every time anyway
1395
- TaskDepsRef :: Ignore => { }
1396
+ TaskDepsRef :: Ignore => {
1397
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1398
+ trace ! ( ?def_id, "ignore" ) ;
1399
+ def_id
1400
+ }
1396
1401
TaskDepsRef :: Forbid => bug ! (
1397
1402
"cannot create definition {parent:?}, {name:?}, {def_kind:?} without being able to register task dependencies"
1398
1403
) ,
1399
1404
TaskDepsRef :: Allow ( _) => {
1400
- icx. side_effects
1401
- . as_ref ( )
1402
- . unwrap ( )
1403
- . lock ( )
1404
- . definitions
1405
- . push ( DefIdInfo { parent, data } ) ;
1405
+ let ( def_id, hash) =
1406
+ self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1407
+ trace ! ( ?def_id, "record side effects" ) ;
1408
+
1409
+ icx. side_effects . as_ref ( ) . unwrap ( ) . lock ( ) . definitions . push ( DefIdInfo {
1410
+ parent,
1411
+ data,
1412
+ hash,
1413
+ } ) ;
1414
+ def_id
1406
1415
}
1407
1416
TaskDepsRef :: Replay { prev_side_effects, created_def_ids } => {
1417
+ trace ! ( ?created_def_ids, "replay side effects" ) ;
1418
+ trace ! ( "num_defs : {}" , prev_side_effects. definitions. len( ) ) ;
1408
1419
let index = created_def_ids. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
1409
1420
let prev_info = & prev_side_effects. definitions [ index] ;
1410
- assert_eq ! ( * prev_info, DefIdInfo { parent, data } ) ;
1421
+ let def_id = self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id (
1422
+ prev_info. hash ,
1423
+ & "should have already recreated def id in try_mark_green" ,
1424
+ ) ;
1425
+ assert_eq ! ( prev_info. data, data) ;
1426
+ assert_eq ! ( prev_info. parent, parent) ;
1427
+ def_id
1411
1428
}
1412
1429
}
1413
1430
} ) ;
0 commit comments