Skip to content

Commit 39b36ea

Browse files
committed
Do not assert that a change in global cache only happens when concurrent
1 parent 6f34f4e commit 39b36ea

File tree

7 files changed

+81
-8
lines changed

7 files changed

+81
-8
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
207207
from_entry(entry)
208208
}
209209

210-
fn evaluation_is_concurrent(&self) -> bool {
211-
self.sess.threads() > 1
210+
fn assert_evaluation_is_concurrent(&self) {
211+
// Turns out, the assumption for this function isn't perfect.
212+
// See trait-system-refactor-initiative#234.
212213
}
213214

214215
fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {

compiler/rustc_type_ir/src/interner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ pub trait Interner:
185185
from_entry: impl FnOnce(&CanonicalParamEnvCacheEntry<Self>) -> R,
186186
) -> R;
187187

188-
fn evaluation_is_concurrent(&self) -> bool;
188+
// Useful for testing. If a cache entry is replaced, this should
189+
// (in theory) only happen when concurrent.
190+
fn assert_evaluation_is_concurrent(&self);
189191

190192
fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;
191193

@@ -569,7 +571,7 @@ impl<I: Interner> search_graph::Cx for I {
569571
fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
570572
I::with_global_cache(self, f)
571573
}
572-
fn evaluation_is_concurrent(&self) -> bool {
573-
self.evaluation_is_concurrent()
574+
fn assert_evaluation_is_concurrent(&self) {
575+
self.assert_evaluation_is_concurrent()
574576
}
575577
}

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ impl<X: Cx> GlobalCache<X> {
5656
let with_overflow = WithOverflow { nested_goals, result };
5757
let prev = entry.with_overflow.insert(required_depth, with_overflow);
5858
if let Some(prev) = &prev {
59-
assert!(cx.evaluation_is_concurrent());
59+
cx.assert_evaluation_is_concurrent();
6060
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6161
}
6262
} else {
6363
let prev = entry.success.replace(Success { required_depth, nested_goals, result });
6464
if let Some(prev) = &prev {
65-
assert!(cx.evaluation_is_concurrent());
65+
cx.assert_evaluation_is_concurrent();
6666
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6767
}
6868
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait Cx: Copy {
5353

5454
fn with_global_cache<R>(self, f: impl FnOnce(&mut GlobalCache<Self>) -> R) -> R;
5555

56-
fn evaluation_is_concurrent(&self) -> bool;
56+
fn assert_evaluation_is_concurrent(&self);
5757
}
5858

5959
pub trait Delegate: Sized {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/fn-delegation-opaque-cycle.rs:25:5: 25:24>::opaque_ret::{anon_assoc#0}`
2+
--> $DIR/fn-delegation-opaque-cycle.rs:26:25
3+
|
4+
LL | reuse to_reuse::opaque_ret;
5+
| ^^^^^^^^^^
6+
|
7+
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
8+
--> $DIR/fn-delegation-opaque-cycle.rs:26:25
9+
|
10+
LL | reuse to_reuse::opaque_ret;
11+
| ^^^^^^^^^^
12+
= note: ...which again requires computing type of `opaque::<impl at $DIR/fn-delegation-opaque-cycle.rs:25:5: 25:24>::opaque_ret::{anon_assoc#0}`, completing the cycle
13+
note: cycle used when checking assoc item `opaque::<impl at $DIR/fn-delegation-opaque-cycle.rs:25:5: 25:24>::opaque_ret` is compatible with trait definition
14+
--> $DIR/fn-delegation-opaque-cycle.rs:26:25
15+
|
16+
LL | reuse to_reuse::opaque_ret;
17+
| ^^^^^^^^^^
18+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0391`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/fn-delegation-opaque-cycle.rs:25:5: 25:24>::opaque_ret::{anon_assoc#0}`
2+
--> $DIR/fn-delegation-opaque-cycle.rs:26:25
3+
|
4+
LL | reuse to_reuse::opaque_ret;
5+
| ^^^^^^^^^^
6+
|
7+
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
8+
--> $DIR/fn-delegation-opaque-cycle.rs:26:25
9+
|
10+
LL | reuse to_reuse::opaque_ret;
11+
| ^^^^^^^^^^
12+
= note: ...which again requires computing type of `opaque::<impl at $DIR/fn-delegation-opaque-cycle.rs:25:5: 25:24>::opaque_ret::{anon_assoc#0}`, completing the cycle
13+
= note: cycle used when computing implied outlives bounds for `<u8 as opaque::ToReuse>::opaque_ret::{anon_assoc#0}` (hack disabled = false)
14+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0391`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
//@ check-fail
5+
6+
// Regression test for trait-system-refactor-initiative#234. If we end up in a
7+
// query cycle, it should be okay as long as results are the same.
8+
9+
#![feature(fn_delegation)]
10+
#![allow(incomplete_features)]
11+
12+
mod opaque {
13+
trait Trait {}
14+
impl Trait for () {}
15+
16+
mod to_reuse {
17+
use super::Trait;
18+
pub fn opaque_ret() -> impl Trait { () }
19+
}
20+
21+
trait ToReuse {
22+
fn opaque_ret() -> impl Trait { () }
23+
}
24+
25+
impl ToReuse for u8 {
26+
reuse to_reuse::opaque_ret; //~ ERROR cycle detected when computing type
27+
}
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)