-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
forego caching for all participants in cycles, apart from root node #60444
Merged
bors
merged 2 commits into
rust-lang:master
from
nikomatsakis:issue-60010-cycle-error-investigation
May 14, 2019
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
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,71 @@ | ||
// Test that we properly detect the cycle amongst the traits | ||
// here and report an error. | ||
|
||
use std::panic::RefUnwindSafe; | ||
|
||
trait Database { | ||
type Storage; | ||
} | ||
trait HasQueryGroup {} | ||
trait Query<DB> { | ||
type Data; | ||
} | ||
trait SourceDatabase { | ||
fn parse(&self) { | ||
loop {} | ||
} | ||
} | ||
|
||
struct ParseQuery; | ||
struct RootDatabase { | ||
_runtime: Runtime<RootDatabase>, | ||
} | ||
struct Runtime<DB: Database> { | ||
_storage: Box<DB::Storage>, | ||
} | ||
struct SalsaStorage { | ||
_parse: <ParseQuery as Query<RootDatabase>>::Data, //~ ERROR overflow | ||
} | ||
|
||
impl Database for RootDatabase { //~ ERROR overflow | ||
type Storage = SalsaStorage; | ||
} | ||
impl HasQueryGroup for RootDatabase {} | ||
impl<DB> Query<DB> for ParseQuery | ||
where | ||
DB: SourceDatabase, | ||
DB: Database, | ||
{ | ||
type Data = RootDatabase; | ||
} | ||
impl<T> SourceDatabase for T | ||
where | ||
T: RefUnwindSafe, | ||
T: HasQueryGroup, | ||
{ | ||
} | ||
|
||
pub(crate) fn goto_implementation(db: &RootDatabase) -> u32 { | ||
// This is not satisfied: | ||
// | ||
// - `RootDatabase: SourceDatabase` | ||
// - requires `RootDatabase: RefUnwindSafe` + `RootDatabase: HasQueryGroup` | ||
// - `RootDatabase: RefUnwindSafe` | ||
// - requires `Runtime<RootDatabase>: RefUnwindSafe` | ||
// - `Runtime<RootDatabase>: RefUnwindSafe` | ||
// - requires `DB::Storage: RefUnwindSafe` (`SalsaStorage: RefUnwindSafe`) | ||
// - `SalsaStorage: RefUnwindSafe` | ||
// - requires `<ParseQuery as Query<RootDatabase>>::Data: RefUnwindSafe`, | ||
// which means `ParseQuery: Query<RootDatabase>` | ||
// - `ParseQuery: Query<RootDatabase>` | ||
// - requires `RootDatabase: SourceDatabase`, | ||
// - `RootDatabase: SourceDatabase` is already on the stack, so we have a | ||
// cycle with non-coinductive participants | ||
// | ||
// we used to fail to report an error here because we got the | ||
// caching wrong. | ||
SourceDatabase::parse(db); | ||
22 | ||
} | ||
|
||
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,20 @@ | ||
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase` | ||
--> $DIR/cycle-cache-err-60010.rs:27:5 | ||
| | ||
LL | _parse: <ParseQuery as Query<RootDatabase>>::Data, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery` | ||
|
||
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase` | ||
--> $DIR/cycle-cache-err-60010.rs:30:6 | ||
| | ||
LL | impl Database for RootDatabase { | ||
| ^^^^^^^^ | ||
| | ||
= note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery` | ||
= note: required because it appears within the type `SalsaStorage` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0275`. |
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.
in what sense are you using the word "correct" here?
Is this use of "correct" meant to imply that there are cases of unsound code that on master we currently incorrectly accept, and a correct fix would reject, but this targeted fix continues to accept?
Or is this use of "correct" just meant to emphasize that this fix is not ideal with respect to compiler efficiency?
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.
Oh, the latter -- efficiency.