-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
fix coherence error for very large tuples™ #132001
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,7 +16,7 @@ use rustc_type_ir::fold::TypeFoldable; | |||||
use rustc_type_ir::inherent::*; | ||||||
use rustc_type_ir::relate::solver_relating::RelateExt; | ||||||
use rustc_type_ir::{self as ty, Canonical, CanonicalVarValues, InferCtxtLike, Interner}; | ||||||
use tracing::{instrument, trace}; | ||||||
use tracing::{debug, instrument, trace}; | ||||||
|
||||||
use crate::canonicalizer::{CanonicalizeMode, Canonicalizer}; | ||||||
use crate::delegate::SolverDelegate; | ||||||
|
@@ -165,12 +165,21 @@ 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(); | ||||||
if num_non_region_vars > self.cx().recursion_limit() { | ||||||
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow { | ||||||
suggest_increasing_limit: true, | ||||||
})); | ||||||
// during generalization. This prevents hangs caused by an exponential blowup, | ||||||
// see tests/ui/traits/next-solver/coherence-alias-hang.rs. | ||||||
// | ||||||
// We don't do so for `NormalizesTo` goals as we erased the expected term and | ||||||
// bailing with overflow here would prevent us from detecting a type-mismatch, | ||||||
// causing a coherence error in diesel, see #131969. We still bail with verflow | ||||||
// when later returning from the parent AliasRelate goal. | ||||||
if !self.is_normalizes_to_goal { | ||||||
let num_non_region_vars = canonical.variables.iter().filter(|c| !c.is_region()).count(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. army after this |
||||||
if num_non_region_vars > self.cx().recursion_limit() { | ||||||
debug!(?num_non_region_vars, "too many inference variables -> overflow"); | ||||||
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow { | ||||||
suggest_increasing_limit: true, | ||||||
})); | ||||||
} | ||||||
} | ||||||
|
||||||
Ok(canonical) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/ui/traits/next-solver/normalize/normalize-allow-too-many-vars.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//@ check-pass | ||
lcnr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// When canonicalizing a response in the trait solver, we bail with overflow | ||
// if there are too many non-region inference variables. Doing so in normalizes-to | ||
// goals ends up hiding inference constraints in cases which we want to support, | ||
// see #131969. To prevent this issue we do not check for too many inference | ||
// variables in normalizes-to goals. | ||
#![recursion_limit = "8"] | ||
|
||
trait Bound {} | ||
trait Trait { | ||
type Assoc; | ||
} | ||
|
||
|
||
impl<T0, T1, T2, T3, T4, T5, T6, T7> Trait for (T0, T1, T2, T3, T4, T5, T6, T7) | ||
where | ||
T0: Trait, | ||
T1: Trait, | ||
T2: Trait, | ||
T3: Trait, | ||
T4: Trait, | ||
T5: Trait, | ||
T6: Trait, | ||
T7: Trait, | ||
( | ||
T0::Assoc, | ||
T1::Assoc, | ||
T2::Assoc, | ||
T3::Assoc, | ||
T4::Assoc, | ||
T5::Assoc, | ||
T6::Assoc, | ||
T7::Assoc, | ||
): Clone, | ||
{ | ||
type Assoc = ( | ||
T0::Assoc, | ||
T1::Assoc, | ||
T2::Assoc, | ||
T3::Assoc, | ||
T4::Assoc, | ||
T5::Assoc, | ||
T6::Assoc, | ||
T7::Assoc, | ||
); | ||
} | ||
|
||
trait Overlap {} | ||
impl<T: Trait<Assoc = ()>> Overlap for T {} | ||
impl<T0, T1, T2, T3, T4, T5, T6, T7> Overlap for (T0, T1, T2, T3, T4, T5, T6, T7) {} | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i won't r-, you can if you want to or not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verflow is actually a type-system specific concept :clueless:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i see, it describes the way crates of different versions flow through the type system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed as part of #132026 :3