@@ -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 ;
@@ -2001,22 +2001,32 @@ impl<'tcx> TyCtxt<'tcx> {
20012001 disambiguator : & mut DisambiguatorState ,
20022002 ) -> TyCtxtFeed < ' tcx , LocalDefId > {
20032003 let data = override_def_path_data. unwrap_or_else ( || def_kind. def_path_data ( name) ) ;
2004- // The following call has the side effect of modifying the tables inside `definitions`.
2005- // These very tables are relied on by the incr. comp. engine to decode DepNodes and to
2006- // decode the on-disk cache.
2007- //
2008- // Any LocalDefId which is used within queries, either as key or result, either:
2009- // - has been created before the construction of the TyCtxt;
2010- // - has been created by this call to `create_def`.
2011- // As a consequence, this LocalDefId is always re-created before it is needed by the incr.
2012- // comp. engine itself.
2013- let def_id = self . untracked . definitions . write ( ) . create_def ( parent, data, disambiguator) ;
2014-
2015- // This function modifies `self.definitions` using a side-effect.
2016- // We need to ensure that these side effects are re-run by the incr. comp. engine.
2017- // Depending on the forever-red node will tell the graph that the calling query
2018- // needs to be re-evaluated.
2019- self . dep_graph . read_index ( DepNodeIndex :: FOREVER_RED_NODE ) ;
2004+
2005+ let def_id = tls:: with_context ( |icx| {
2006+ match icx. task_deps {
2007+ // Always gets rerun anyway, so nothing to replay
2008+ TaskDepsRef :: EvalAlways |
2009+ // Top-level queries like the resolver get rerun every time anyway
2010+ TaskDepsRef :: Ignore => {
2011+ // The following call has the side effect of modifying the tables inside `definitions`.
2012+ // These very tables are relied on by the incr. comp. engine to decode DepNodes and to
2013+ // decode the on-disk cache.
2014+ //
2015+ // Any LocalDefId which is used within queries, either as key or result, either:
2016+ // - has been created before the construction of the TyCtxt;
2017+ // - has been created by this call to `create_def`.
2018+ // As a consequence, this LocalDefId is always re-created before it is needed by the incr.
2019+ // comp. engine itself.
2020+ self . untracked . definitions . write ( ) . create_def ( parent, data, disambiguator. next ( parent, data) )
2021+ }
2022+ TaskDepsRef :: Forbid => bug ! (
2023+ "cannot create definition {parent:?} {data:?} without being able to register task dependencies"
2024+ ) ,
2025+ TaskDepsRef :: Allow ( _) => {
2026+ self . create_def_raw ( ( parent, data, disambiguator. next ( parent, data) ) )
2027+ }
2028+ }
2029+ } ) ;
20202030
20212031 let feed = TyCtxtFeed { tcx : self , key : def_id } ;
20222032 feed. def_kind ( def_kind) ;
0 commit comments