@@ -67,7 +67,7 @@ use rustc_macros::{Decodable, Encodable};
6767use rustc_query_system:: ich:: StableHashingContext ;
6868use rustc_span:: Symbol ;
6969
70- use super :: { DepContext , FingerprintStyle , SerializedDepNodeIndex } ;
70+ use super :: { FingerprintStyle , SerializedDepNodeIndex } ;
7171use crate :: mir:: mono:: MonoItem ;
7272use crate :: ty:: TyCtxt ;
7373
@@ -92,6 +92,26 @@ impl DepKind {
9292 pub const fn as_usize ( & self ) -> usize {
9393 self . variant as usize
9494 }
95+
96+ pub ( crate ) fn name ( self ) -> & ' static str {
97+ DEP_KIND_NAMES [ self . as_usize ( ) ]
98+ }
99+
100+ /// We use this for most things when incr. comp. is turned off.
101+ pub ( crate ) const NULL : DepKind = dep_kinds:: Null ;
102+
103+ /// We use this to create a forever-red node.
104+ pub ( crate ) const RED : DepKind = dep_kinds:: Red ;
105+
106+ /// We use this to create a side effect node.
107+ pub ( crate ) const SIDE_EFFECT : DepKind = dep_kinds:: SideEffect ;
108+
109+ /// We use this to create the anon node with zero dependencies.
110+ pub ( crate ) const ANON_ZERO_DEPS : DepKind = dep_kinds:: AnonZeroDeps ;
111+
112+ /// This is the highest value a `DepKind` can have. It's used during encoding to
113+ /// pack information into the unused bits.
114+ pub ( crate ) const MAX : u16 = DEP_KIND_VARIANTS - 1 ;
95115}
96116
97117pub fn default_dep_kind_debug ( kind : DepKind , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -117,29 +137,25 @@ impl DepNode {
117137 /// Creates a new, parameterless DepNode. This method will assert
118138 /// that the DepNode corresponding to the given DepKind actually
119139 /// does not require any parameters.
120- pub fn new_no_params < Tcx > ( tcx : Tcx , kind : DepKind ) -> DepNode
121- where
122- Tcx : super :: DepContext ,
123- {
140+ pub fn new_no_params < ' tcx > ( tcx : TyCtxt < ' tcx > , kind : DepKind ) -> DepNode {
124141 debug_assert_eq ! ( tcx. fingerprint_style( kind) , FingerprintStyle :: Unit ) ;
125142 DepNode { kind, hash : Fingerprint :: ZERO . into ( ) }
126143 }
127144
128- pub fn construct < Tcx , Key > ( tcx : Tcx , kind : DepKind , arg : & Key ) -> DepNode
145+ pub fn construct < ' tcx , Key > ( tcx : TyCtxt < ' tcx > , kind : DepKind , arg : & Key ) -> DepNode
129146 where
130- Tcx : super :: DepContext ,
131- Key : DepNodeKey < Tcx > ,
147+ Key : DepNodeKey < ' tcx > ,
132148 {
133149 let hash = arg. to_fingerprint ( tcx) ;
134150 let dep_node = DepNode { kind, hash : hash. into ( ) } ;
135151
136152 #[ cfg( debug_assertions) ]
137153 {
138154 if !tcx. fingerprint_style ( kind) . reconstructible ( )
139- && ( tcx. sess ( ) . opts . unstable_opts . incremental_info
140- || tcx. sess ( ) . opts . unstable_opts . query_dep_graph )
155+ && ( tcx. sess . opts . unstable_opts . incremental_info
156+ || tcx. sess . opts . unstable_opts . query_dep_graph )
141157 {
142- tcx. dep_graph ( ) . register_dep_node_debug_str ( dep_node, || arg. to_debug_str ( tcx) ) ;
158+ tcx. dep_graph . register_dep_node_debug_str ( dep_node, || arg. to_debug_str ( tcx) ) ;
143159 }
144160 }
145161
@@ -149,10 +165,11 @@ impl DepNode {
149165 /// Construct a DepNode from the given DepKind and DefPathHash. This
150166 /// method will assert that the given DepKind actually requires a
151167 /// single DefId/DefPathHash parameter.
152- pub fn from_def_path_hash < Tcx > ( tcx : Tcx , def_path_hash : DefPathHash , kind : DepKind ) -> Self
153- where
154- Tcx : super :: DepContext ,
155- {
168+ pub fn from_def_path_hash < ' tcx > (
169+ tcx : TyCtxt < ' tcx > ,
170+ def_path_hash : DefPathHash ,
171+ kind : DepKind ,
172+ ) -> Self {
156173 debug_assert ! ( tcx. fingerprint_style( kind) == FingerprintStyle :: DefPathHash ) ;
157174 DepNode { kind, hash : def_path_hash. 0 . into ( ) }
158175 }
@@ -172,26 +189,26 @@ impl fmt::Debug for DepNode {
172189}
173190
174191/// Trait for query keys as seen by dependency-node tracking.
175- pub trait DepNodeKey < Tcx : DepContext > : fmt:: Debug + Sized {
192+ pub trait DepNodeKey < ' tcx > : fmt:: Debug + Sized {
176193 fn fingerprint_style ( ) -> FingerprintStyle ;
177194
178195 /// This method turns a query key into an opaque `Fingerprint` to be used
179196 /// in `DepNode`.
180- fn to_fingerprint ( & self , _ : Tcx ) -> Fingerprint ;
197+ fn to_fingerprint ( & self , tcx : TyCtxt < ' tcx > ) -> Fingerprint ;
181198
182- fn to_debug_str ( & self , tcx : Tcx ) -> String ;
199+ fn to_debug_str ( & self , tcx : TyCtxt < ' tcx > ) -> String ;
183200
184201 /// This method tries to recover the query key from the given `DepNode`,
185202 /// something which is needed when forcing `DepNode`s during red-green
186203 /// evaluation. The query system will only call this method if
187204 /// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
188205 /// It is always valid to return `None` here, in which case incremental
189206 /// compilation will treat the query as having changed instead of forcing it.
190- fn recover ( tcx : Tcx , dep_node : & DepNode ) -> Option < Self > ;
207+ fn recover ( tcx : TyCtxt < ' tcx > , dep_node : & DepNode ) -> Option < Self > ;
191208}
192209
193210// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
194- impl < Tcx : DepContext , T > DepNodeKey < Tcx > for T
211+ impl < ' tcx , T > DepNodeKey < ' tcx > for T
195212where
196213 T : for < ' a > HashStable < StableHashingContext < ' a > > + fmt:: Debug ,
197214{
@@ -201,7 +218,7 @@ where
201218 }
202219
203220 #[ inline( always) ]
204- default fn to_fingerprint ( & self , tcx : Tcx ) -> Fingerprint {
221+ default fn to_fingerprint ( & self , tcx : TyCtxt < ' tcx > ) -> Fingerprint {
205222 tcx. with_stable_hashing_context ( |mut hcx| {
206223 let mut hasher = StableHasher :: new ( ) ;
207224 self . hash_stable ( & mut hcx, & mut hasher) ;
@@ -210,15 +227,15 @@ where
210227 }
211228
212229 #[ inline( always) ]
213- default fn to_debug_str ( & self , tcx : Tcx ) -> String {
230+ default fn to_debug_str ( & self , tcx : TyCtxt < ' tcx > ) -> String {
214231 // Make sure to print dep node params with reduced queries since printing
215232 // may themselves call queries, which may lead to (possibly untracked!)
216233 // query cycles.
217234 tcx. with_reduced_queries ( || format ! ( "{self:?}" ) )
218235 }
219236
220237 #[ inline( always) ]
221- default fn recover ( _: Tcx , _: & DepNode ) -> Option < Self > {
238+ default fn recover ( _: TyCtxt < ' tcx > , _: & DepNode ) -> Option < Self > {
222239 None
223240 }
224241}
@@ -228,7 +245,7 @@ where
228245/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
229246/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
230247/// jump table instead of large matches.
231- pub struct DepKindVTable < Tcx : DepContext > {
248+ pub struct DepKindVTable < ' tcx > {
232249 /// Anonymous queries cannot be replayed from one compiler invocation to the next.
233250 /// When their result is needed, it is recomputed. They are useful for fine-grained
234251 /// dependency tracking, and caching within one compiler invocation.
@@ -279,11 +296,12 @@ pub struct DepKindVTable<Tcx: DepContext> {
279296 /// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
280297 /// is actually a `DefPathHash`, and can therefore just look up the corresponding
281298 /// `DefId` in `tcx.def_path_hash_to_def_id`.
282- pub force_from_dep_node :
283- Option < fn ( tcx : Tcx , dep_node : DepNode , prev_index : SerializedDepNodeIndex ) -> bool > ,
299+ pub force_from_dep_node : Option <
300+ fn ( tcx : TyCtxt < ' tcx > , dep_node : DepNode , prev_index : SerializedDepNodeIndex ) -> bool ,
301+ > ,
284302
285303 /// Invoke a query to put the on-disk cached value in memory.
286- pub try_load_from_on_disk_cache : Option < fn ( Tcx , DepNode ) > ,
304+ pub try_load_from_on_disk_cache : Option < fn ( TyCtxt < ' tcx > , DepNode ) > ,
287305
288306 /// The name of this dep kind.
289307 pub name : & ' static & ' static str ,
@@ -434,19 +452,7 @@ pub(crate) fn make_metadata(tcx: TyCtxt<'_>) -> DepNode {
434452 DepNode :: construct ( tcx, dep_kinds:: Metadata , & ( ) )
435453}
436454
437- pub trait DepNodeExt : Sized {
438- fn extract_def_id ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > ;
439-
440- fn from_label_string (
441- tcx : TyCtxt < ' _ > ,
442- label : & str ,
443- def_path_hash : DefPathHash ,
444- ) -> Result < Self , ( ) > ;
445-
446- fn has_label_string ( label : & str ) -> bool ;
447- }
448-
449- impl DepNodeExt for DepNode {
455+ impl DepNode {
450456 /// Extracts the DefId corresponding to this DepNode. This will work
451457 /// if two conditions are met:
452458 ///
@@ -457,16 +463,15 @@ impl DepNodeExt for DepNode {
457463 /// DepNode. Condition (2) might not be fulfilled if a DepNode
458464 /// refers to something from the previous compilation session that
459465 /// has been removed.
460- fn extract_def_id ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > {
466+ pub fn extract_def_id ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > {
461467 if tcx. fingerprint_style ( self . kind ) == FingerprintStyle :: DefPathHash {
462468 tcx. def_path_hash_to_def_id ( DefPathHash ( self . hash . into ( ) ) )
463469 } else {
464470 None
465471 }
466472 }
467473
468- /// Used in testing
469- fn from_label_string (
474+ pub fn from_label_string (
470475 tcx : TyCtxt < ' _ > ,
471476 label : & str ,
472477 def_path_hash : DefPathHash ,
@@ -482,8 +487,7 @@ impl DepNodeExt for DepNode {
482487 }
483488 }
484489
485- /// Used in testing
486- fn has_label_string ( label : & str ) -> bool {
490+ pub fn has_label_string ( label : & str ) -> bool {
487491 dep_kind_from_label_string ( label) . is_ok ( )
488492 }
489493}
0 commit comments