Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bail if there are too many non-region infer vars in the query response #130617

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ where
},
);

// HACK: We bail with overflow if the response would have too many non-region
// inference variables. This tends to only happen if we encounter a lot of
// ambiguous alias types which get replaced with fresh inference variables
// during generalization. This prevents a hang in nalgebra.
let num_non_region_vars = canonical.variables.iter().filter(|c| !c.is_region()).count();
lcnr marked this conversation as resolved.
Show resolved Hide resolved
if num_non_region_vars > self.cx().recursion_limit() {
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow {
suggest_increasing_limit: true,
}));
}

Ok(canonical)
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/traits/coherence-alias-hang.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ check-pass
//@ revisions: current next
//[next]@ compile-flags: -Znext-solver

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0275]: overflow evaluating the requirement `W<_>: Trait`
LL | impls::<W<_>>();
| ^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`fixpoint_exponential_growth`)
note: required by a bound in `impls`
--> $DIR/fixpoint-exponential-growth.rs:30:13
|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//~ ERROR overflow evaluating the requirement `Self: Trait`
//~^ ERROR overflow evaluating the requirement `Self well-formed`
// This is a non-regression test for issue #115351, where a recursion limit of 0 caused an ICE.
//@ compile-flags: -Znext-solver --crate-type=lib
//@ check-pass

#![recursion_limit = "0"]
trait Trait {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0275]: overflow evaluating the requirement `Self: Trait`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)

error[E0275]: overflow evaluating the requirement `Self well-formed`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0275`.
Loading