@@ -8,7 +8,8 @@ use rustc_query_system::HandleCycleError;
88use rustc_query_system:: dep_graph:: { DepNodeIndex , SerializedDepNodeIndex } ;
99pub ( crate ) use rustc_query_system:: query:: QueryJobId ;
1010use rustc_query_system:: query:: * ;
11- use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span } ;
11+ use rustc_span:: { ErrorGuaranteed , Span } ;
12+ pub use sealed:: IntoQueryParam ;
1213
1314use crate :: dep_graph;
1415use crate :: dep_graph:: DepKind ;
@@ -165,78 +166,17 @@ impl<'tcx> TyCtxt<'tcx> {
165166 }
166167}
167168
168- #[ inline( always) ]
169- pub fn query_get_at < ' tcx , Cache > (
170- tcx : TyCtxt < ' tcx > ,
171- execute_query : fn ( TyCtxt < ' tcx > , Span , Cache :: Key , QueryMode ) -> Option < Cache :: Value > ,
172- query_cache : & Cache ,
173- span : Span ,
174- key : Cache :: Key ,
175- ) -> Cache :: Value
176- where
177- Cache : QueryCache ,
178- {
179- let key = key. into_query_param ( ) ;
180- match try_get_cached ( tcx, query_cache, & key) {
181- Some ( value) => value,
182- None => execute_query ( tcx, span, key, QueryMode :: Get ) . unwrap ( ) ,
183- }
184- }
185-
186- #[ inline]
187- pub fn query_ensure < ' tcx , Cache > (
188- tcx : TyCtxt < ' tcx > ,
189- execute_query : fn ( TyCtxt < ' tcx > , Span , Cache :: Key , QueryMode ) -> Option < Cache :: Value > ,
190- query_cache : & Cache ,
191- key : Cache :: Key ,
192- check_cache : bool ,
193- ) where
194- Cache : QueryCache ,
195- {
196- let key = key. into_query_param ( ) ;
197- if try_get_cached ( tcx, query_cache, & key) . is_none ( ) {
198- execute_query ( tcx, DUMMY_SP , key, QueryMode :: Ensure { check_cache } ) ;
199- }
200- }
201-
202- #[ inline]
203- pub fn query_ensure_error_guaranteed < ' tcx , Cache , T > (
204- tcx : TyCtxt < ' tcx > ,
205- execute_query : fn ( TyCtxt < ' tcx > , Span , Cache :: Key , QueryMode ) -> Option < Cache :: Value > ,
206- query_cache : & Cache ,
207- key : Cache :: Key ,
208- check_cache : bool ,
209- ) -> Result < ( ) , ErrorGuaranteed >
210- where
211- Cache : QueryCache < Value = super :: erase:: Erase < Result < T , ErrorGuaranteed > > > ,
212- Result < T , ErrorGuaranteed > : EraseType ,
213- {
214- let key = key. into_query_param ( ) ;
215- if let Some ( res) = try_get_cached ( tcx, query_cache, & key) {
216- super :: erase:: restore ( res) . map ( drop)
217- } else {
218- execute_query ( tcx, DUMMY_SP , key, QueryMode :: Ensure { check_cache } )
219- . map ( super :: erase:: restore)
220- . map ( |res| res. map ( drop) )
221- // Either we actually executed the query, which means we got a full `Result`,
222- // or we can just assume the query succeeded, because it was green in the
223- // incremental cache. If it is green, that means that the previous compilation
224- // that wrote to the incremental cache compiles successfully. That is only
225- // possible if the cache entry was `Ok(())`, so we emit that here, without
226- // actually encoding the `Result` in the cache or loading it from there.
227- . unwrap_or ( Ok ( ( ) ) )
228- }
229- }
230-
231- macro_rules! query_ensure {
169+ /// Calls either `query_ensure` or `query_ensure_error_guaranteed`, depending
170+ /// on whether the list of modifiers contains `return_result_from_ensure_ok`.
171+ macro_rules! query_ensure_select {
232172 ( [ ] $( $args: tt) * ) => {
233- query_ensure( $( $args) * )
173+ crate :: query :: inner :: query_ensure( $( $args) * )
234174 } ;
235175 ( [ ( return_result_from_ensure_ok) $( $rest: tt) * ] $( $args: tt) * ) => {
236- query_ensure_error_guaranteed( $( $args) * ) . map ( |_| ( ) )
176+ crate :: query :: inner :: query_ensure_error_guaranteed( $( $args) * )
237177 } ;
238178 ( [ $other: tt $( $modifiers: tt) * ] $( $args: tt) * ) => {
239- query_ensure !( [ $( $modifiers) * ] $( $args) * )
179+ query_ensure_select !( [ $( $modifiers) * ] $( $args) * )
240180 } ;
241181}
242182
@@ -432,7 +372,7 @@ macro_rules! define_callbacks {
432372 self ,
433373 key: query_helper_param_ty!( $( $K) * ) ,
434374 ) -> ensure_ok_result!( [ $( $modifiers) * ] ) {
435- query_ensure !(
375+ query_ensure_select !(
436376 [ $( $modifiers) * ]
437377 self . tcx,
438378 self . tcx. query_system. fns. engine. $name,
@@ -447,7 +387,7 @@ macro_rules! define_callbacks {
447387 $( $( #[ $attr] ) *
448388 #[ inline( always) ]
449389 pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) {
450- query_ensure(
390+ crate :: query :: inner :: query_ensure(
451391 self . tcx,
452392 self . tcx. query_system. fns. engine. $name,
453393 & self . tcx. query_system. caches. $name,
@@ -472,7 +412,7 @@ macro_rules! define_callbacks {
472412 #[ inline( always) ]
473413 pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) -> $V
474414 {
475- restore:: <$V>( query_get_at(
415+ restore:: <$V>( crate :: query :: inner :: query_get_at(
476416 self . tcx,
477417 self . tcx. query_system. fns. engine. $name,
478418 & self . tcx. query_system. caches. $name,
@@ -565,48 +505,19 @@ macro_rules! define_feedable {
565505
566506 let tcx = self . tcx;
567507 let erased = queries:: $name:: provided_to_erased( tcx, value) ;
568- let value = restore:: <$V>( erased) ;
569508 let cache = & tcx. query_system. caches. $name;
570509
510+ let dep_kind: dep_graph:: DepKind = dep_graph:: dep_kinds:: $name;
571511 let hasher: Option <fn ( & mut StableHashingContext <' _>, & _) -> _> = hash_result!( [ $( $modifiers) * ] ) ;
572- match try_get_cached( tcx, cache, & key) {
573- Some ( old) => {
574- let old = restore:: <$V>( old) ;
575- if let Some ( hasher) = hasher {
576- let ( value_hash, old_hash) : ( Fingerprint , Fingerprint ) = tcx. with_stable_hashing_context( |mut hcx|
577- ( hasher( & mut hcx, & value) , hasher( & mut hcx, & old) )
578- ) ;
579- if old_hash != value_hash {
580- // We have an inconsistency. This can happen if one of the two
581- // results is tainted by errors. In this case, delay a bug to
582- // ensure compilation is doomed, and keep the `old` value.
583- tcx. dcx( ) . delayed_bug( format!(
584- "Trying to feed an already recorded value for query {} key={key:?}:\n \
585- old value: {old:?}\n new value: {value:?}",
586- stringify!( $name) ,
587- ) ) ;
588- }
589- } else {
590- // The query is `no_hash`, so we have no way to perform a sanity check.
591- // If feeding the same value multiple times needs to be supported,
592- // the query should not be marked `no_hash`.
593- bug!(
594- "Trying to feed an already recorded value for query {} key={key:?}:\n old value: {old:?}\n new value: {value:?}" ,
595- stringify!( $name) ,
596- )
597- }
598- }
599- None => {
600- let dep_node = dep_graph:: DepNode :: construct( tcx, dep_graph:: dep_kinds:: $name, & key) ;
601- let dep_node_index = tcx. dep_graph. with_feed_task(
602- dep_node,
603- tcx,
604- & value,
605- hash_result!( [ $( $modifiers) * ] ) ,
606- ) ;
607- cache. complete( key, erased, dep_node_index) ;
608- }
609- }
512+
513+ $crate:: query:: inner:: query_feed(
514+ tcx,
515+ dep_kind,
516+ hasher,
517+ cache,
518+ key,
519+ erased,
520+ ) ;
610521 }
611522 } ) *
612523 }
@@ -694,10 +605,6 @@ mod sealed {
694605 }
695606}
696607
697- pub use sealed:: IntoQueryParam ;
698-
699- use super :: erase:: EraseType ;
700-
701608#[ derive( Copy , Clone , Debug , HashStable ) ]
702609pub struct CyclePlaceholder ( pub ErrorGuaranteed ) ;
703610
0 commit comments