Skip to content

Commit ebd9a0f

Browse files
authored
Unrolled build for rust-lang#130617
Rollup merge of rust-lang#130617 - lcnr:nalgebra-hang-3, r=compiler-errors bail if there are too many non-region infer vars in the query response A minimal fix for the hang in nalgebra. If the query response would result in too many distinct non-region inference variables, simply overwrite the result with overflow. This should either happen if the result already has too many distinct type inference variables, or if evaluating the query encountered a lot of ambiguous associated types. In both cases it's straightforward to wait until the aliases are no longer ambiguous and then try again. r? `@compiler-errors`
2 parents 5ba6db1 + a6aeba8 commit ebd9a0f

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

+11
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ where
157157
},
158158
);
159159

160+
// HACK: We bail with overflow if the response would have too many non-region
161+
// inference variables. This tends to only happen if we encounter a lot of
162+
// ambiguous alias types which get replaced with fresh inference variables
163+
// during generalization. This prevents a hang in nalgebra.
164+
let num_non_region_vars = canonical.variables.iter().filter(|c| !c.is_region()).count();
165+
if num_non_region_vars > self.cx().recursion_limit() {
166+
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow {
167+
suggest_increasing_limit: true,
168+
}));
169+
}
170+
160171
Ok(canonical)
161172
}
162173

tests/ui/traits/coherence-alias-hang.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ check-pass
2+
//@ revisions: current next
3+
//[next]@ compile-flags: -Znext-solver
24

35
// Regression test for nalgebra hang <https://github.com/rust-lang/rust/issues/130056>.
46

tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0275]: overflow evaluating the requirement `W<_>: Trait`
44
LL | impls::<W<_>>();
55
| ^^^^
66
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`fixpoint_exponential_growth`)
78
note: required by a bound in `impls`
89
--> $DIR/fixpoint-exponential-growth.rs:30:13
910
|

tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
//~ ERROR overflow evaluating the requirement `Self: Trait`
2+
//~^ ERROR overflow evaluating the requirement `Self well-formed`
13
// This is a non-regression test for issue #115351, where a recursion limit of 0 caused an ICE.
24
//@ compile-flags: -Znext-solver --crate-type=lib
3-
//@ check-pass
45

56
#![recursion_limit = "0"]
67
trait Trait {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0275]: overflow evaluating the requirement `Self: Trait`
2+
|
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)
4+
5+
error[E0275]: overflow evaluating the requirement `Self well-formed`
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)
8+
9+
error: aborting due to 2 previous errors
10+
11+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)