Skip to content

Commit 086a5fb

Browse files
committed
fix
1 parent fea3b26 commit 086a5fb

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/librustc/ty/maps/plumbing.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
9797
})
9898
}
9999

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>)>>
101102
{
102103
if let Some((i, _)) = self.query().stack.iter().enumerate().rev()
103104
.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())
108106
} else {
109-
Ok(())
107+
None
110108
}
111109
}
112110

@@ -270,13 +268,6 @@ macro_rules! define_maps {
270268
)
271269
);
272270

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-
280271
loop {
281272
let job = if let Some(value) = tcx.maps.$name.borrow().map.get(&key) {
282273
match *value {
@@ -294,7 +285,11 @@ macro_rules! define_maps {
294285
break
295286
};
296287
// 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+
}
298293
job.await();
299294
}
300295
/*
@@ -328,6 +323,13 @@ macro_rules! define_maps {
328323
//job.await();
329324
}
330325
*/
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+
331333
// Fast path for when incr. comp. is off. `to_dep_node` is
332334
// expensive for some DepKinds.
333335
if !tcx.dep_graph.is_fully_enabled() {
@@ -421,7 +423,12 @@ macro_rules! define_maps {
421423
{
422424
let query = Query::$name(Clone::clone(&key));
423425

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+
}
425432

426433
let entry = (span, query);
427434
let stack = tcx.query().stack.iter().cloned().chain(iter::once(entry)).collect();

0 commit comments

Comments
 (0)