Skip to content

Infinite memory use on invalid program #18418

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

Closed
det opened this issue Oct 29, 2014 · 5 comments
Closed

Infinite memory use on invalid program #18418

det opened this issue Oct 29, 2014 · 5 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@det
Copy link

det commented Oct 29, 2014

struct Pair<A, B>
{
    a : A,
    b : B
}

fn pair<A, B>(a: A, b: B) -> Pair<A, B>
{
    Pair{ a : a, b: b }
}

trait Printable
{
    fn print(&self)
    {
        print!("{}", self)
    }
}


impl<A: Printable, B: Printable> Printable for Pair<A, B>
{
    fn print(&self)
    {
        self.a.print();
        self.b.print();
    }
}

fn print<A: Printable, B: Printable>(t: Pair<A, B>)
{
    t.print();
}

fn main()
{
    print(pair(1, 2));
}
@huonw huonw added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 29, 2014
@huonw
Copy link
Member

huonw commented Oct 29, 2014

I think this reduced example displays the problem more clearly: the compiler is trying to instantiate Pair<...> infinitely deeply. I guess the version with Pair<A, B> has exponential memory use due to doubling at each level.

struct Pair<A> {
    a: A,
}

trait Printable {
    fn print(&self) {}
}

impl<A: Printable> Printable for Pair<A> {}

// inlining/removing these stops the error
fn pair<A>(a: A) -> Pair<A> {
    Pair{ a : a }
}
fn print<A: Printable>(t: Pair<A>) {}

fn main() {
    print(pair(1));
}
<anon>:18:5: 18:10 error: overflow evaluating the trait `core::kinds::Sized` for the type `<generic #65>`
<anon>:18     print(pair(1));
              ^~~~~
<anon>:18:5: 18:10 note: the trait `core::kinds::Sized` must be implemented because it is required by `print`
<anon>:18     print(pair(1));
              ^~~~~
<anon>:18:5: 18:10 error: overflow evaluating the trait `Printable` for the type `<generic #65>`
<anon>:18     print(pair(1));
              ^~~~~
<anon>:18:5: 18:10 note: the trait `Printable` must be implemented because it is required by `print`
<anon>:18     print(pair(1));
              ^~~~~
<anon>:18:11: 18:18 error: mismatched types: expected `Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<<generic #65>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`, found `Pair<<generic integer #0>>` (expected struct Pair, found integral variable)
<anon>:18     print(pair(1));
                    ^~~~~~~
error: aborting due to 3 previous errors
playpen: application terminated with error code 101

This happens even with a suffix on the 1, but does not happen if any other impl Printable is added, e.g. impl Printable for () {} will hit a proper (finite) type error, and impl Printable for uint {] will compile successfully. This makes me think it is caused by the new defaulting rules.

cc @nikomatsakis

@huonw
Copy link
Member

huonw commented Oct 29, 2014

This looks like it may be a dupe of #18400.

@arielb1
Copy link
Contributor

arielb1 commented Oct 29, 2014

This code properly gives an error on 0.12.

@nikomatsakis
Copy link
Contributor

So, I don't see infinite memory use. I do see errors about overflow, which seems appropriate -- there is only one impl, and the compiler is trying to give the benefit of the doubt here.

@nikomatsakis
Copy link
Contributor

I agree this is a dup of #18400

lnicola pushed a commit to lnicola/rust that referenced this issue Oct 29, 2024
…sable

feat: Split `macro-error` diagnostic so users can ignore only parts of it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants