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

rustc hangs and leaks memory #79714

Closed
is8ac opened this issue Dec 5, 2020 · 4 comments · Fixed by #80246
Closed

rustc hangs and leaks memory #79714

is8ac opened this issue Dec 5, 2020 · 4 comments · Fixed by #80246
Assignees
Labels
A-traits Area: Trait system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-low Low priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@is8ac
Copy link

is8ac commented Dec 5, 2020

In stable, rustc 1.48.0 (7eac88abb 2020-11-16), rustc demo.rs promptly returns overflow evaluating the requirement and exits. This is expected behavior.

In nightly, rustc 1.50.0-nightly (5be3f9f10 2020-12-03), rustc demo.rs hangs indefinitely, using 100% of one core. Memory usage fluctuates but tends to grow over time at ~800 MB per minute on my machine.

Source

pub trait Baz {}
impl Baz for () {}
impl<T> Baz for [T; 3] {}

pub trait Fiz {}
impl Fiz for bool {}

pub trait Corge<S> {
    type Foo;
}

impl<W: Corge<()>> Corge<[(); 3]> for W {
    type Foo = [<W as Corge<()>>::Foo; 3];
}

pub trait Grault
where
    Self::B: Fiz,
{
    type A;
    type B;
}

impl<T: Grault> Grault for [T; 3]
where
    Self::A: Baz,
    Self::B: Fiz,
{
    type A = [T::A; 3];
    type B = T::B;
}

pub trait Quaks<S, W> {
    fn bar() {}
}

impl<S> Quaks<S, bool> for u8
where
    bool: Corge<S>,
    <bool as Corge<S>>::Foo: Grault,
{
}

fn main() {
    <u8 as Quaks<[(); 3], bool>>::bar();
}

rustc --version --verbose:

rustc 1.50.0-nightly (5be3f9f10 2020-12-03)
binary: rustc
commit-hash: 5be3f9f10e9fd59ea03816840a6051413fbdefae
commit-date: 2020-12-03
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
@is8ac is8ac added the C-bug Category: This is a bug. label Dec 5, 2020
@jonas-schievink jonas-schievink added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Dec 5, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 5, 2020
@JohnTitor JohnTitor added the I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. label Dec 5, 2020
@JohnTitor
Copy link
Member

This happens on beta as well.

@JohnTitor JohnTitor added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Dec 5, 2020
@JohnTitor
Copy link
Member

JohnTitor commented Dec 5, 2020

The regression introduced between nightly-2020-10-06 (a1dfd24) and nightly-2020-10-07 (98edd1f)

Possible culprit PRs: #77606, #73905 (UPDATE: confirmed #73905 is the cause)

@camelid camelid added A-traits Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 5, 2020
@camelid
Copy link
Member

camelid commented Dec 6, 2020

Assigning P-high and removing I-prioritize as discussed in the prioritization working group.

@Mark-Simulacrum Mark-Simulacrum added this to the 1.49.0 milestone Dec 11, 2020
@Mark-Simulacrum
Copy link
Member

I am going to move this to P-low as this isn't breaking working code, we have more urgent fall out from #73905 that needs to be fixed first.

@Mark-Simulacrum Mark-Simulacrum added P-low Low priority and removed P-high High priority labels Dec 11, 2020
@matthewjasper matthewjasper self-assigned this Dec 17, 2020
@Mark-Simulacrum Mark-Simulacrum changed the title rustc nightly hangs and leaks memory rustc hangs and leaks memory Dec 18, 2020
matthewjasper added a commit to matthewjasper/rust that referenced this issue Dec 20, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 26, 2020
…g, r=Mark-Simulacrum

Prevent caching normalization results with a cycle

When normalizing a projection which results in a cycle, we would cache the result of `project_type` without the nested obligations (because they're not needed for inference). This would result in the nested obligations only being handled once in fulfill, which would avoid the cycle error. `get_paranoid_cache_value_obligation` used to add an obligation that resulted in a cycle in this case previously, but was removed by rust-lang#73905.

This PR makes the projection cache not cache the value of a projection if it was ever normalized in a cycle (except in a snapshot that's rolled back).

Fixes rust-lang#79714.

r? `@nikomatsakis`
@bors bors closed this as completed in 2e92b13 Dec 26, 2020
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Dec 27, 2020
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Dec 27, 2020
When normalizing a projection which results in a cycle, we would
cache the result of `project_type` without the nested obligations
(because they're not needed for inference). This would result in
the nested obligations only being handled once in fulfill, which
would avoid the cycle error.

Fixes rust-lang#79714, a regresion from rust-lang#79305 caused by the removal of
`get_paranoid_cache_value_obligation`.
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Dec 31, 2020
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Dec 31, 2020
When normalizing a projection which results in a cycle, we would
cache the result of `project_type` without the nested obligations
(because they're not needed for inference). This would result in
the nested obligations only being handled once in fulfill, which
would avoid the cycle error.

Fixes rust-lang#79714, a regresion from rust-lang#79305 caused by the removal of
`get_paranoid_cache_value_obligation`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-low Low priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants