-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forego caching for all participants in cycles, apart from root node
- Loading branch information
1 parent
47e0803
commit bd005a2
Showing
3 changed files
with
139 additions
and
2 deletions.
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`. |