@@ -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 ;
@@ -1819,14 +1816,15 @@ impl<'tcx> TyCtxtAt<'tcx> {
1819
1816
1820
1817
impl < ' tcx > TyCtxt < ' tcx > {
1821
1818
/// `tcx`-dependent operations performed for every created definition.
1819
+ #[ instrument( level = "trace" , skip( self ) ) ]
1822
1820
pub fn create_def (
1823
1821
self ,
1824
1822
parent : LocalDefId ,
1825
1823
name : Symbol ,
1826
1824
def_kind : DefKind ,
1827
1825
) -> TyCtxtFeed < ' tcx , LocalDefId > {
1828
1826
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`.
1830
1828
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
1831
1829
// decode the on-disk cache.
1832
1830
//
@@ -1839,31 +1837,47 @@ impl<'tcx> TyCtxt<'tcx> {
1839
1837
// This is fine because:
1840
1838
// - those queries are `eval_always` so we won't miss their result changing;
1841
1839
// - 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| {
1847
1841
match icx. task_deps {
1848
1842
// 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
+ }
1850
1848
// 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
+ }
1852
1854
TaskDepsRef :: Forbid => bug ! (
1853
1855
"cannot create definition {parent:?}, {name:?}, {def_kind:?} without being able to register task dependencies"
1854
1856
) ,
1855
1857
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
1862
1868
}
1863
1869
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( ) ) ;
1864
1872
let index = created_def_ids. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
1865
1873
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
1867
1881
}
1868
1882
}
1869
1883
} ) ;
0 commit comments