@@ -8,7 +8,8 @@ use rustc_query_system::HandleCycleError;
8
8
use rustc_query_system:: dep_graph:: { DepNodeIndex , SerializedDepNodeIndex } ;
9
9
pub ( crate ) use rustc_query_system:: query:: QueryJobId ;
10
10
use rustc_query_system:: query:: * ;
11
- use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span } ;
11
+ use rustc_span:: { ErrorGuaranteed , Span } ;
12
+ pub use sealed:: IntoQueryParam ;
12
13
13
14
use crate :: dep_graph;
14
15
use crate :: dep_graph:: DepKind ;
@@ -165,78 +166,17 @@ impl<'tcx> TyCtxt<'tcx> {
165
166
}
166
167
}
167
168
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 {
232
172
( [ ] $( $args: tt) * ) => {
233
- query_ensure( $( $args) * )
173
+ crate :: query :: inner :: query_ensure( $( $args) * )
234
174
} ;
235
175
( [ ( 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) * )
237
177
} ;
238
178
( [ $other: tt $( $modifiers: tt) * ] $( $args: tt) * ) => {
239
- query_ensure !( [ $( $modifiers) * ] $( $args) * )
179
+ query_ensure_select !( [ $( $modifiers) * ] $( $args) * )
240
180
} ;
241
181
}
242
182
@@ -432,7 +372,7 @@ macro_rules! define_callbacks {
432
372
self ,
433
373
key: query_helper_param_ty!( $( $K) * ) ,
434
374
) -> ensure_ok_result!( [ $( $modifiers) * ] ) {
435
- query_ensure !(
375
+ query_ensure_select !(
436
376
[ $( $modifiers) * ]
437
377
self . tcx,
438
378
self . tcx. query_system. fns. engine. $name,
@@ -447,7 +387,7 @@ macro_rules! define_callbacks {
447
387
$( $( #[ $attr] ) *
448
388
#[ inline( always) ]
449
389
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) {
450
- query_ensure(
390
+ crate :: query :: inner :: query_ensure(
451
391
self . tcx,
452
392
self . tcx. query_system. fns. engine. $name,
453
393
& self . tcx. query_system. caches. $name,
@@ -472,7 +412,7 @@ macro_rules! define_callbacks {
472
412
#[ inline( always) ]
473
413
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) -> $V
474
414
{
475
- restore:: <$V>( query_get_at(
415
+ restore:: <$V>( crate :: query :: inner :: query_get_at(
476
416
self . tcx,
477
417
self . tcx. query_system. fns. engine. $name,
478
418
& self . tcx. query_system. caches. $name,
@@ -565,48 +505,19 @@ macro_rules! define_feedable {
565
505
566
506
let tcx = self . tcx;
567
507
let erased = queries:: $name:: provided_to_erased( tcx, value) ;
568
- let value = restore:: <$V>( erased) ;
569
508
let cache = & tcx. query_system. caches. $name;
570
509
510
+ let dep_kind: dep_graph:: DepKind = dep_graph:: dep_kinds:: $name;
571
511
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
+ ) ;
610
521
}
611
522
} ) *
612
523
}
@@ -694,10 +605,6 @@ mod sealed {
694
605
}
695
606
}
696
607
697
- pub use sealed:: IntoQueryParam ;
698
-
699
- use super :: erase:: EraseType ;
700
-
701
608
#[ derive( Copy , Clone , Debug , HashStable ) ]
702
609
pub struct CyclePlaceholder ( pub ErrorGuaranteed ) ;
703
610
0 commit comments