-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Prevent caching normalization results with a cycle #80246
Merged
bors
merged 2 commits into
rust-lang:master
from
matthewjasper:projection-cycle-caching
Dec 26, 2020
Merged
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -90,6 +90,7 @@ impl ProjectionCacheKey<'tcx> { | |||||
pub enum ProjectionCacheEntry<'tcx> { | ||||||
InProgress, | ||||||
Ambiguous, | ||||||
Recur, | ||||||
Error, | ||||||
NormalizedTy(NormalizedTy<'tcx>), | ||||||
} | ||||||
|
@@ -143,7 +144,12 @@ impl<'tcx> ProjectionCache<'_, 'tcx> { | |||||
"ProjectionCacheEntry::insert_ty: adding cache entry: key={:?}, value={:?}", | ||||||
key, value | ||||||
); | ||||||
let fresh_key = self.map().insert(key, ProjectionCacheEntry::NormalizedTy(value)); | ||||||
let mut map = self.map(); | ||||||
if let Some(ProjectionCacheEntry::Recur) = map.get(&key) { | ||||||
debug!("Not overwriting Recur"); | ||||||
return; | ||||||
} | ||||||
let fresh_key = map.insert(key, ProjectionCacheEntry::NormalizedTy(value)); | ||||||
assert!(!fresh_key, "never started projecting `{:?}`", key); | ||||||
} | ||||||
|
||||||
|
@@ -197,6 +203,14 @@ impl<'tcx> ProjectionCache<'_, 'tcx> { | |||||
assert!(!fresh, "never started projecting `{:?}`", key); | ||||||
} | ||||||
|
||||||
/// Indicates that while trying to normalize `key`, `key` was required to | ||||||
/// be normalized again. Selection or evaluation should eventually report | ||||||
/// an error here. | ||||||
pub fn recur(&mut self, key: ProjectionCacheKey<'tcx>) { | ||||||
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
|
||||||
let fresh = self.map().insert(key, ProjectionCacheEntry::Recur); | ||||||
assert!(!fresh, "never started projecting `{:?}`", key); | ||||||
} | ||||||
|
||||||
/// Indicates that trying to normalize `key` resulted in | ||||||
/// error. | ||||||
pub fn error(&mut self, key: ProjectionCacheKey<'tcx>) { | ||||||
|
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
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
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
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
error[E0271]: type mismatch resolving `<bool as Tr>::B == _` | ||
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _` | ||
--> $DIR/defaults-cyclic-fail-1.rs:26:5 | ||
| | ||
LL | type A = Box<Self::B>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0271]: type mismatch resolving `<usize as Tr>::A == _` | ||
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _` | ||
--> $DIR/defaults-cyclic-fail-1.rs:32:5 | ||
| | ||
LL | type B = &'static Self::A; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. | ||
For more information about this error, try `rustc --explain E0275`. |
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
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
error[E0271]: type mismatch resolving `<bool as Tr>::B == _` | ||
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _` | ||
--> $DIR/defaults-cyclic-fail-2.rs:27:5 | ||
| | ||
LL | type A = Box<Self::B>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0271]: type mismatch resolving `<usize as Tr>::A == _` | ||
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _` | ||
--> $DIR/defaults-cyclic-fail-2.rs:33:5 | ||
| | ||
LL | type B = &'static Self::A; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. | ||
For more information about this error, try `rustc --explain E0275`. |
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,29 @@ | ||
// Regression test for #79714 | ||
|
||
trait Baz {} | ||
impl Baz for () {} | ||
impl<T> Baz for (T,) {} | ||
|
||
trait Fiz {} | ||
impl Fiz for bool {} | ||
|
||
trait Grault { | ||
type A; | ||
type B; | ||
} | ||
|
||
impl<T: Grault> Grault for (T,) | ||
where | ||
Self::A: Baz, | ||
Self::B: Fiz, | ||
{ | ||
type A = (); | ||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
type B = bool; | ||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
} | ||
//~^^^^^^^^^^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
|
||
fn main() { | ||
let x: <(_,) as Grault>::A = (); | ||
} |
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,39 @@ | ||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
--> $DIR/impl-wf-cycle-1.rs:15:1 | ||
| | ||
LL | / impl<T: Grault> Grault for (T,) | ||
LL | | where | ||
LL | | Self::A: Baz, | ||
LL | | Self::B: Fiz, | ||
... | | ||
LL | | | ||
LL | | } | ||
| |_^ | ||
| | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
= note: 1 redundant requirements hidden | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
|
||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
--> $DIR/impl-wf-cycle-1.rs:20:5 | ||
| | ||
LL | type A = (); | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
= note: 1 redundant requirements hidden | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
|
||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
--> $DIR/impl-wf-cycle-1.rs:22:5 | ||
| | ||
LL | type B = bool; | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
= note: 1 redundant requirements hidden | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
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,16 @@ | ||
// Regression test for #79714 | ||
|
||
trait Grault { | ||
type A; | ||
} | ||
|
||
impl<T: Grault> Grault for (T,) | ||
where | ||
Self::A: Copy, | ||
{ | ||
type A = (); | ||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
} | ||
//~^^^^^^^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
--> $DIR/impl-wf-cycle-2.rs:7:1 | ||
| | ||
LL | / impl<T: Grault> Grault for (T,) | ||
LL | | where | ||
LL | | Self::A: Copy, | ||
LL | | { | ||
LL | | type A = (); | ||
LL | | | ||
LL | | } | ||
| |_^ | ||
| | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
|
||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _` | ||
--> $DIR/impl-wf-cycle-2.rs:11:5 | ||
| | ||
LL | type A = (); | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: required because of the requirements on the impl of `Grault` for `(T,)` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
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
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 had to read the doc comment on the
recur
method to understand what this meant.