@@ -41,7 +41,6 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
41
41
use rustc_query_system:: cache:: WithDepNode ;
42
42
use rustc_query_system:: dep_graph:: { DepNodeIndex , TaskDepsRef } ;
43
43
use rustc_query_system:: ich:: StableHashingContext ;
44
- use rustc_query_system:: query:: DefIdInfo ;
45
44
use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
46
45
use rustc_session:: config:: CrateType ;
47
46
use rustc_session:: cstore:: { CrateStoreDyn , Untracked } ;
@@ -51,10 +50,8 @@ use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
51
50
use rustc_span:: symbol:: { Ident , Symbol , kw, sym} ;
52
51
use rustc_span:: { DUMMY_SP , Span } ;
53
52
use 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 } ;
58
55
use tracing:: { debug, instrument} ;
59
56
60
57
use crate :: arena:: Arena ;
@@ -1796,14 +1793,15 @@ impl<'tcx> TyCtxtAt<'tcx> {
1796
1793
1797
1794
impl < ' tcx > TyCtxt < ' tcx > {
1798
1795
/// `tcx`-dependent operations performed for every created definition.
1796
+ #[ instrument( level = "trace" , skip( self ) ) ]
1799
1797
pub fn create_def (
1800
1798
self ,
1801
1799
parent : LocalDefId ,
1802
1800
name : Symbol ,
1803
1801
def_kind : DefKind ,
1804
1802
) -> TyCtxtFeed < ' tcx , LocalDefId > {
1805
1803
let data = def_kind. def_path_data ( name) ;
1806
- // The following call has the side effect of modifying the tables inside `definitions`.
1804
+ // The following create_def calls have the side effect of modifying the tables inside `definitions`.
1807
1805
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1808
1806
// decode the on-disk cache.
1809
1807
//
@@ -1816,31 +1814,47 @@ impl<'tcx> TyCtxt<'tcx> {
1816
1814
// This is fine because:
1817
1815
// - those queries are `eval_always` so we won't miss their result changing;
1818
1816
// - this write will have happened before these queries are called.
1819
- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1820
-
1821
- // This function modifies `self.definitions` using a side-effect.
1822
- // We need to ensure that these side effects are re-run by the incr. comp. engine.
1823
- tls:: with_context ( |icx| {
1817
+ let def_id = tls:: with_context ( |icx| {
1824
1818
match icx. task_deps {
1825
1819
// Always gets rerun anyway, so nothing to replay
1826
- TaskDepsRef :: EvalAlways => { }
1820
+ TaskDepsRef :: EvalAlways => {
1821
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1822
+ trace ! ( ?def_id, "eval always" ) ;
1823
+ def_id
1824
+ }
1827
1825
// Top-level queries like the resolver get rerun every time anyway
1828
- TaskDepsRef :: Ignore => { }
1826
+ TaskDepsRef :: Ignore => {
1827
+ let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data) . 0 ;
1828
+ trace ! ( ?def_id, "ignore" ) ;
1829
+ def_id
1830
+ }
1829
1831
TaskDepsRef :: Forbid => bug ! (
1830
1832
"cannot create definition {parent:?}, {name:?}, {def_kind:?} without being able to register task dependencies"
1831
1833
) ,
1832
1834
TaskDepsRef :: Allow ( _) => {
1833
- icx. side_effects
1834
- . as_ref ( )
1835
- . unwrap ( )
1836
- . lock ( )
1837
- . definitions
1838
- . push ( DefIdInfo { parent, data } ) ;
1835
+ let ( def_id, hash) =
1836
+ self . untracked . definitions . write ( ) . create_def ( parent, data) ;
1837
+ trace ! ( ?def_id, "record side effects" ) ;
1838
+
1839
+ icx. side_effects . as_ref ( ) . unwrap ( ) . lock ( ) . definitions . push ( DefIdInfo {
1840
+ parent,
1841
+ data,
1842
+ hash,
1843
+ } ) ;
1844
+ def_id
1839
1845
}
1840
1846
TaskDepsRef :: Replay { prev_side_effects, created_def_ids } => {
1847
+ trace ! ( ?created_def_ids, "replay side effects" ) ;
1848
+ trace ! ( "num_defs : {}" , prev_side_effects. definitions. len( ) ) ;
1841
1849
let index = created_def_ids. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
1842
1850
let prev_info = & prev_side_effects. definitions [ index] ;
1843
- assert_eq ! ( * prev_info, DefIdInfo { parent, data } ) ;
1851
+ let def_id = self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id (
1852
+ prev_info. hash ,
1853
+ & "should have already recreated def id in try_mark_green" ,
1854
+ ) ;
1855
+ assert_eq ! ( prev_info. data, data) ;
1856
+ assert_eq ! ( prev_info. parent, parent) ;
1857
+ def_id
1844
1858
}
1845
1859
}
1846
1860
} ) ;
0 commit comments