Skip to content
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

OOM during type collection #111729

Closed
matthiaskrgr opened this issue May 18, 2023 · 1 comment · Fixed by #111754
Closed

OOM during type collection #111729

matthiaskrgr opened this issue May 18, 2023 · 1 comment · Fixed by #111754
Assignees
Labels
C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.

Comments

@matthiaskrgr
Copy link
Member

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
@matthiaskrgr matthiaskrgr added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. C-bug Category: This is a bug. labels May 18, 2023
@matthewjasper matthewjasper self-assigned this May 18, 2023
@matthewjasper matthewjasper added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label May 18, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 18, 2023
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 19, 2023
@bors bors closed this as completed in cfcde24 May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants