@@ -41,7 +41,7 @@ use rustc_hir::{self as hir, Attribute, HirId, Node, TraitCandidate};
4141use rustc_index:: IndexVec ;
4242use rustc_macros:: { HashStable , TyDecodable , TyEncodable } ;
4343use rustc_query_system:: cache:: WithDepNode ;
44- use rustc_query_system:: dep_graph:: DepNodeIndex ;
44+ use rustc_query_system:: dep_graph:: { DepNodeIndex , TaskDepsRef } ;
4545use rustc_query_system:: ich:: StableHashingContext ;
4646use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
4747use rustc_session:: config:: CrateType ;
@@ -1999,22 +1999,32 @@ impl<'tcx> TyCtxt<'tcx> {
19991999 disambiguator : & mut DisambiguatorState ,
20002000 ) -> TyCtxtFeed < ' tcx , LocalDefId > {
20012001 let data = override_def_path_data. unwrap_or_else ( || def_kind. def_path_data ( name) ) ;
2002- // The following call has the side effect of modifying the tables inside `definitions`.
2003- // These very tables are relied on by the incr. comp. engine to decode DepNodes and to
2004- // decode the on-disk cache.
2005- //
2006- // Any LocalDefId which is used within queries, either as key or result, either:
2007- // - has been created before the construction of the TyCtxt;
2008- // - has been created by this call to `create_def`.
2009- // As a consequence, this LocalDefId is always re-created before it is needed by the incr.
2010- // comp. engine itself.
2011- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data, disambiguator) ;
2012-
2013- // This function modifies `self.definitions` using a side-effect.
2014- // We need to ensure that these side effects are re-run by the incr. comp. engine.
2015- // Depending on the forever-red node will tell the graph that the calling query
2016- // needs to be re-evaluated.
2017- self . dep_graph . read_index ( DepNodeIndex :: FOREVER_RED_NODE ) ;
2002+
2003+ let def_id = tls:: with_context ( |icx| {
2004+ match icx. task_deps {
2005+ // Always gets rerun anyway, so nothing to replay
2006+ TaskDepsRef :: EvalAlways |
2007+ // Top-level queries like the resolver get rerun every time anyway
2008+ TaskDepsRef :: Ignore => {
2009+ // The following call has the side effect of modifying the tables inside `definitions`.
2010+ // These very tables are relied on by the incr. comp. engine to decode DepNodes and to
2011+ // decode the on-disk cache.
2012+ //
2013+ // Any LocalDefId which is used within queries, either as key or result, either:
2014+ // - has been created before the construction of the TyCtxt;
2015+ // - has been created by this call to `create_def`.
2016+ // As a consequence, this LocalDefId is always re-created before it is needed by the incr.
2017+ // comp. engine itself.
2018+ self . untracked . definitions . write ( ) . create_def ( parent, data, disambiguator. next ( parent, data) )
2019+ }
2020+ TaskDepsRef :: Forbid => bug ! (
2021+ "cannot create definition {parent:?} {data:?} without being able to register task dependencies"
2022+ ) ,
2023+ TaskDepsRef :: Allow ( _) => {
2024+ self . create_def_raw ( ( parent, data, disambiguator. next ( parent, data) ) )
2025+ }
2026+ }
2027+ } ) ;
20182028
20192029 let feed = TyCtxtFeed { tcx : self , key : def_id } ;
20202030 feed. def_kind ( def_kind) ;
0 commit comments