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 on a non-regular ADT #36827

Closed
matklad opened this issue Sep 29, 2016 · 4 comments
Closed

rustc hangs on a non-regular ADT #36827

matklad opened this issue Sep 29, 2016 · 4 comments
Labels
A-typesystem Area: The type system

Comments

@matklad
Copy link
Member

matklad commented Sep 29, 2016

This will keep CPU on 100% while slowly eating all the memory:

struct S<T> {
    a: Option<Box<S<(T, T)>>>,
    b: T,
}

fn main() {
    S { a: None, b: 0i32 };
}

It's interesting that if I don't try to construct an instance of S, the program will compile just fine.

1.11.0 stable and 1.13.0 nightly are affected.

@matklad matklad changed the title rustc hangs on non-regular ADT rustc hangs on a non-regular ADT Sep 29, 2016
@TimNN
Copy link
Contributor

TimNN commented Sep 29, 2016

Using a one element tuple ((T,)) produces the following error:

error[E0320]: overflow while adding drop-check rules for S<i32>
 --> <anon>:7:5
  |
7 |     S { a: None, b: 0i32 };
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
note: overflowed on struct S field a type: std::option::Option<Box<S<((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((i32,),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),)>>>
 --> <anon>:7:5
  |
7 |     S { a: None, b: 0i32 };
  |     ^^^^^^^^^^^^^^^^^^^^^^

error[E0320]: overflow while adding drop-check rules for std::option::Option<Box<S<(i32,)>>>
 --> <anon>:7:12
  |
7 |     S { a: None, b: 0i32 };
  |            ^^^^
  |
note: overflowed on enum std::option::Option variant Some field 0 type: Box<S<((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((i32,),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),)>>
 --> <anon>:7:12
  |
7 |     S { a: None, b: 0i32 };
  |            ^^^^

error: aborting due to 2 previous errors

@TimNN
Copy link
Contributor

TimNN commented Sep 29, 2016

So the problem here seems to be, that due to the two element tuple, the type is growing exponentially and will probably consume all available ram long before the recursion limit has been reached.

For those interested, here's a (truncated) log file: https://gist.github.com/4ea8b6207bd2b66e0899d90f8e30dfb7

@steveklabnik steveklabnik added the A-typesystem Area: The type system label Oct 7, 2016
@isabelmu
Copy link
Contributor

I'm not sure, but it's possible that the underlying problem of issue 4363, infinite type generation, was never addressed. @nikomatsakis mentioned the possible need for an additional admission test for types in this comment from 2013. At the time the compiler was checking whether types are 'representable' (is the size finite?), 'instantiable' (can we write a finite-length instantiating expression?), but not whether they were 'monomorphizable' (will a finite amount of nested types be generated?).

I think such an is_monomorphizable check should catch this problem.

@Mark-Simulacrum
Copy link
Member

Closing.

error[E0320]: overflow while adding drop-check rules for S<i32>
 --> test.rs:7:5
  |
7 |     S { a: None, b: 0i32 };
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: overflowed on i32

error[E0320]: overflow while adding drop-check rules for std::option::Option<std::boxed::Box<S<(i32, i32)>>>
 --> test.rs:7:12
  |
7 |     S { a: None, b: 0i32 };
  |            ^^^^
  |
  = note: overflowed on i32

error: aborting due to 2 previous errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

5 participants