Skip to content

Commit 49f578a

Browse files
Inform the solver if evaluation is concurrent
Parallel compilation of a program can cause unexpected event sequencing. Inform the solver when this is true so it can skip invalid asserts.
1 parent 12b26c1 commit 49f578a

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
181181
}
182182
}
183183

184+
fn evaluation_is_concurrent(&self) -> bool {
185+
self.sess.threads() > 1
186+
}
187+
184188
fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
185189
self.expand_abstract_consts(t)
186190
}

compiler/rustc_type_ir/src/interner.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ pub trait Interner:
137137
f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R,
138138
) -> R;
139139

140+
fn evaluation_is_concurrent(&self) -> bool;
141+
140142
fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;
141143

142144
type GenericsOf: GenericsOf<Self>;
@@ -404,4 +406,7 @@ impl<I: Interner> search_graph::Cx for I {
404406
) -> R {
405407
I::with_global_cache(self, mode, f)
406408
}
409+
fn evaluation_is_concurrent(&self) -> bool {
410+
self.evaluation_is_concurrent()
411+
}
407412
}

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,21 @@ impl<X: Cx> GlobalCache<X> {
5050
additional_depth: usize,
5151
encountered_overflow: bool,
5252
nested_goals: NestedGoals<X>,
53+
concurrency_is_real: bool,
5354
) {
5455
let result = cx.mk_tracked(result, dep_node);
5556
let entry = self.map.entry(input).or_default();
5657
if encountered_overflow {
5758
let with_overflow = WithOverflow { nested_goals, result };
5859
let prev = entry.with_overflow.insert(additional_depth, with_overflow);
59-
assert!(prev.is_none());
60+
if !concurrency_is_real {
61+
assert!(prev.is_none());
62+
}
6063
} else {
6164
let prev = entry.success.replace(Success { additional_depth, nested_goals, result });
62-
assert!(prev.is_none());
65+
if !concurrency_is_real {
66+
assert!(prev.is_none());
67+
}
6368
}
6469
}
6570

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub trait Cx: Copy {
5353
mode: SolverMode,
5454
f: impl FnOnce(&mut GlobalCache<Self>) -> R,
5555
) -> R;
56+
57+
fn evaluation_is_concurrent(&self) -> bool;
5658
}
5759

5860
pub trait Delegate {
@@ -1035,6 +1037,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10351037
result: X::Result,
10361038
dep_node: X::DepNodeIndex,
10371039
) {
1040+
let concurrency_is_real = cx.evaluation_is_concurrent();
10381041
let additional_depth = final_entry.reached_depth.as_usize() - self.stack.len();
10391042
debug!(?final_entry, ?result, "insert global cache");
10401043
cx.with_global_cache(self.mode, |cache| {
@@ -1046,6 +1049,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10461049
additional_depth,
10471050
final_entry.encountered_overflow,
10481051
final_entry.nested_goals,
1052+
concurrency_is_real,
10491053
)
10501054
})
10511055
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ compile-flags: -Zthreads=16
2+
3+
#[derive(Clone, Eq)] //~ ERROR [E0277]
4+
pub struct Struct<T>(T);
5+
6+
impl<T: Clone, U> PartialEq<U> for Struct<T>
7+
where
8+
U: Into<Struct<T>> + Clone
9+
{
10+
fn eq(&self, _other: &U) -> bool {
11+
todo!()
12+
}
13+
}
14+
15+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0277]: the trait bound `T: Clone` is not satisfied
2+
--> $DIR/global-cache-and-parallel-frontend.rs:3:17
3+
|
4+
LL | #[derive(Clone, Eq)]
5+
| ^^ the trait `Clone` is not implemented for `T`, which is required by `Struct<T>: PartialEq`
6+
|
7+
note: required for `Struct<T>` to implement `PartialEq`
8+
--> $DIR/global-cache-and-parallel-frontend.rs:6:19
9+
|
10+
LL | impl<T: Clone, U> PartialEq<U> for Struct<T>
11+
| ----- ^^^^^^^^^^^^ ^^^^^^^^^
12+
| |
13+
| unsatisfied trait bound introduced here
14+
note: required by a bound in `Eq`
15+
--> $SRC_DIR/core/src/cmp.rs:LL:COL
16+
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
17+
help: consider restricting type parameter `T`
18+
|
19+
LL | pub struct Struct<T: std::clone::Clone>(T);
20+
| +++++++++++++++++++
21+
22+
error: aborting due to 1 previous error
23+
24+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)