@@ -97,16 +97,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
97
97
} )
98
98
}
99
99
100
- pub ( super ) fn cycle_check ( self , span : Span , query : & Query < ' gcx > ) -> Result < ( ) , CycleError < ' gcx > >
100
+ pub ( super ) fn cycle_check ( self , query : & Query < ' gcx > )
101
+ -> Option < Vec < ( Span , Query < ' gcx > ) > >
101
102
{
102
103
if let Some ( ( i, _) ) = self . query ( ) . stack . iter ( ) . enumerate ( ) . rev ( )
103
104
. find ( |& ( _, & ( _, ref q) ) | q == query) {
104
- Err ( CycleError {
105
- span,
106
- cycle : self . query ( ) . stack [ i..] . iter ( ) . cloned ( ) . collect ( ) ,
107
- } )
105
+ Some ( self . query ( ) . stack [ i..] . iter ( ) . cloned ( ) . collect ( ) )
108
106
} else {
109
- Ok ( ( ) )
107
+ None
110
108
}
111
109
}
112
110
@@ -270,13 +268,6 @@ macro_rules! define_maps {
270
268
)
271
269
) ;
272
270
273
- // FIXME(eddyb) Get more valid Span's on queries.
274
- // def_span guard is necessary to prevent a recursive loop,
275
- // default_span calls def_span query internally.
276
- if span == DUMMY_SP && stringify!( $name) != "def_span" {
277
- span = key. default_span( tcx)
278
- }
279
-
280
271
loop {
281
272
let job = if let Some ( value) = tcx. maps. $name. borrow( ) . map. get( & key) {
282
273
match * value {
@@ -294,7 +285,11 @@ macro_rules! define_maps {
294
285
break
295
286
} ;
296
287
// If there is a cycle, waiting will never complete
297
- tcx. cycle_check( span, & Query :: $name( Clone :: clone( & key) ) ) ?;
288
+ if let Some ( _) = tcx. cycle_check( & Query :: $name( Clone :: clone( & key) ) ) {
289
+ // There was a cycle. Pretend there's no entry in the cache.
290
+ // We'll hit the other cycle check below
291
+ break ;
292
+ }
298
293
job. await ( ) ;
299
294
}
300
295
/*
@@ -328,6 +323,13 @@ macro_rules! define_maps {
328
323
//job.await();
329
324
}
330
325
*/
326
+ // FIXME(eddyb) Get more valid Span's on queries.
327
+ // def_span guard is necessary to prevent a recursive loop,
328
+ // default_span calls def_span query internally.
329
+ if span == DUMMY_SP && stringify!( $name) != "def_span" {
330
+ span = key. default_span( tcx)
331
+ }
332
+
331
333
// Fast path for when incr. comp. is off. `to_dep_node` is
332
334
// expensive for some DepKinds.
333
335
if !tcx. dep_graph. is_fully_enabled( ) {
@@ -421,7 +423,12 @@ macro_rules! define_maps {
421
423
{
422
424
let query = Query :: $name( Clone :: clone( & key) ) ;
423
425
424
- tcx. cycle_check( span, & query) ?;
426
+ if let Some ( cycle) = tcx. cycle_check( & query) {
427
+ return Err ( CycleError {
428
+ span,
429
+ cycle,
430
+ } ) ;
431
+ }
425
432
426
433
let entry = ( span, query) ;
427
434
let stack = tcx. query( ) . stack. iter( ) . cloned( ) . chain( iter:: once( entry) ) . collect( ) ;
0 commit comments