@@ -41,7 +41,6 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
4141use rustc_query_system:: cache:: WithDepNode ;
4242use rustc_query_system:: dep_graph:: { DepNodeIndex , TaskDepsRef } ;
4343use rustc_query_system:: ich:: StableHashingContext ;
44- use rustc_query_system:: query:: DefIdInfo ;
4544use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
4645use rustc_session:: config:: CrateType ;
4746use rustc_session:: cstore:: { CrateStoreDyn , Untracked } ;
@@ -51,10 +50,8 @@ use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
5150use rustc_span:: symbol:: { Ident , Symbol , kw, sym} ;
5251use rustc_span:: { DUMMY_SP , Span } ;
5352use rustc_type_ir:: TyKind :: * ;
54- use rustc_type_ir:: fold:: TypeFoldable ;
55- use rustc_type_ir:: lang_items:: TraitSolverLangItem ;
56- pub use rustc_type_ir:: lift:: Lift ;
57- use rustc_type_ir:: { CollectAndApply , Interner , TypeFlags , WithCachedTypeInfo , search_graph} ;
53+ use rustc_type_ir:: WithCachedTypeInfo ;
54+ use rustc_type_ir:: { CollectAndApply , Interner , TypeFlags } ;
5855use tracing:: { debug, instrument} ;
5956
6057use crate :: arena:: Arena ;
@@ -1819,14 +1816,15 @@ impl<'tcx> TyCtxtAt<'tcx> {
18191816
18201817impl < ' tcx > TyCtxt < ' tcx > {
18211818 /// `tcx`-dependent operations performed for every created definition.
1819+ #[ instrument( level = "trace" , skip( self ) ) ]
18221820 pub fn create_def (
18231821 self ,
18241822 parent : LocalDefId ,
18251823 name : Symbol ,
18261824 def_kind : DefKind ,
18271825 ) -> TyCtxtFeed < ' tcx , LocalDefId > {
18281826 let data = def_kind. def_path_data ( name) ;
1829- // The following call has the side effect of modifying the tables inside `definitions`.
1827+ // The following create_def calls have the side effect of modifying the tables inside `definitions`.
18301828 // These very tables are relied on by the incr. comp. engine to decode DepNodes and to
18311829 // decode the on-disk cache.
18321830 //
@@ -1839,31 +1837,47 @@ impl<'tcx> TyCtxt<'tcx> {
18391837 // This is fine because:
18401838 // - those queries are `eval_always` so we won't miss their result changing;
18411839 // - this write will have happened before these queries are called.
1842- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1843-
1844- // This function modifies `self.definitions` using a side-effect.
1845- // We need to ensure that these side effects are re-run by the incr. comp. engine.
1846- tls:: with_context ( |icx| {
1840+ let def_id = tls:: with_context ( |icx| {
18471841 match icx. task_deps {
18481842 // Always gets rerun anyway, so nothing to replay
1849- TaskDepsRef :: EvalAlways => { }
1843+ TaskDepsRef :: EvalAlways => {
1844+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1845+ trace ! ( ?def_id, "eval always" ) ;
1846+ def_id
1847+ }
18501848 // Top-level queries like the resolver get rerun every time anyway
1851- TaskDepsRef :: Ignore => { }
1849+ TaskDepsRef :: Ignore => {
1850+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1851+ trace ! ( ?def_id, "ignore" ) ;
1852+ def_id
1853+ }
18521854 TaskDepsRef :: Forbid => bug ! (
18531855 "cannot create definition {parent:?}, {name:?}, {def_kind:?} without being able to register task dependencies"
18541856 ) ,
18551857 TaskDepsRef :: Allow ( _) => {
1856- icx. side_effects
1857- . as_ref ( )
1858- . unwrap ( )
1859- . lock ( )
1860- . definitions
1861- . push ( DefIdInfo { parent, data } ) ;
1858+ let ( def_id, hash) =
1859+ self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1860+ trace ! ( ?def_id, "record side effects" ) ;
1861+
1862+ icx. side_effects . as_ref ( ) . unwrap ( ) . lock ( ) . definitions . push ( DefIdInfo {
1863+ parent,
1864+ data,
1865+ hash,
1866+ } ) ;
1867+ def_id
18621868 }
18631869 TaskDepsRef :: Replay { prev_side_effects, created_def_ids } => {
1870+ trace ! ( ?created_def_ids, "replay side effects" ) ;
1871+ trace ! ( "num_defs : {}" , prev_side_effects. definitions. len( ) ) ;
18641872 let index = created_def_ids. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
18651873 let prev_info = & prev_side_effects. definitions [ index] ;
1866- assert_eq ! ( * prev_info, DefIdInfo { parent, data } ) ;
1874+ let def_id = self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id (
1875+ prev_info. hash ,
1876+ & "should have already recreated def id in try_mark_green" ,
1877+ ) ;
1878+ assert_eq ! ( prev_info. data, data) ;
1879+ assert_eq ! ( prev_info. parent, parent) ;
1880+ def_id
18671881 }
18681882 }
18691883 } ) ;
0 commit comments