Closed
Description
I tried this code:
This is modification of tests/ui/traits/cycle-cache-err-60010.rs
with the difference being
@@ -41,7 +41,7 @@
{
type Data = RootDatabase;
}
-impl<T> SourceDatabase for T
+impl<T> Database for T
where
T: RefUnwindSafe,
T: HasQueryGroup,
Rust OOM'd here after eating at least 20 gb of memory 😅
// 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 {
// This would also be an error if we didn't abort compilation on the error
// above.
type Storage = SalsaStorage;
}
impl HasQueryGroup for RootDatabase {}
impl<DB> Query<DB> for ParseQuery
where
DB: SourceDatabase,
DB: Database,
{
type Data = RootDatabase;
}
impl<T> Database 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() {}
I expected to see this happen: explanation
NO OOM, maybe an error
Instead, this happened: explanation
OOM
Meta
rustc --version --verbose
:
rustc 1.71.0-nightly (e9e1bbc7a 2023-05-17)
binary: rustc
commit-hash: e9e1bbc7a820c472b39d3de54b3049bf14050655
commit-date: 2023-05-17
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2