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

1000 fields + #derive(PartialEq) => stack overflow at compile time #40119

Closed
stepancheg opened this issue Feb 26, 2017 · 14 comments
Closed

1000 fields + #derive(PartialEq) => stack overflow at compile time #40119

stepancheg opened this issue Feb 26, 2017 · 14 comments
Labels
C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@stepancheg
Copy link
Contributor

Source

% rustup run stable rustc --version
rustc 1.15.1 (021bd294c 2017-02-08)
% rustup run stable rustc unittest_enormous_descriptor.rs
thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
zsh: exit 1
% rustup run nightly rustc --version
rustc 1.16.0-nightly (83c2d9523 2017-01-24)
% rustup run nightly rustc unittest_enormous_descriptor.rs
zsh: exit 1
% uname -a
Darwin MacBook-Pro-9.local 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64
@leonardo-m
Copy link

For me 654 fields suffice for overflow Rustc stack. The problem is more general: how to test/modify Rustc to be sure there aren't many other similar stack overflows?

@abonander
Copy link
Contributor

I suspect it's a recursion that's dependent on the number of fields. Recursion seems elegant, but in languages without TCO it's more of a liability than anything, I think.

@sinkuu
Copy link
Contributor

sinkuu commented Feb 27, 2017

Debugger pointed out hir::lowering::LoweringContext::lower_expr, that transforms expression tree using recursion.

@leonardo-m
Copy link

How do you fuzzy-test Rustc to discover many of such cases of possible stack overflow?

@abonander
Copy link
Contributor

abonander commented Feb 27, 2017

So this probably affects any long chain of binary operations, since I suspect the derive just expands to

self.field_1 == other.field_1 &&    
self.field_2 == other.field_2 &&
// etc. etc.

A simpler repro might just generate a long chain of expressions like this.

@ghost
Copy link

ghost commented Feb 27, 2017

@abonander you are right.

https://gist.github.com/Insomgla/573a162768a36163a0d9d17ab4fa3c41

And I get the same error.

@ghost
Copy link

ghost commented Feb 27, 2017

My gist is at the exact critical point where the overflow is reported by the compiler on my computer. If I remove 1 operation, I have another failure report. See :

https://gist.github.com/Insomgla/ef1de205f587ef64d3b3dd323903dd48

@abonander
Copy link
Contributor

Cargo likes to eat error messages. Since you've got just a single file and no dependencies you can just invoke rustc directly and see what it outputs: rustc repr2.rs

The exact point that it overflows is highly dependent on environment as each OS sets a different default stack size for new threads. If you set a much larger default stack size it'll probably compile successfully. That's the difference between deep and infinite recursion.

So it's looking like HIR expression lowering needs to be refactored to eliminate the recursion. Probably not a hard job, something that could be mentored maybe.

@leonardo-m
Copy link

leonardo-m commented Feb 27, 2017

So it's looking like HIR expression lowering needs to be refactored to eliminate the recursion.

It's also quite good to look for all the similar bugs in the codebase.

@abonander
Copy link
Contributor

Yeah, but these things can be addressed incrementally. It may be a good idea to form a metabug tracking deep recursion issues in the compiler.

@ghost
Copy link

ghost commented Feb 27, 2017

@abonander thanks for the information :p

@oli-obk
Copy link
Contributor

oli-obk commented Feb 27, 2017

How do you fuzzy-test Rustc to discover many of such cases of possible stack overflow?

You use a crate like syn and combine it with quicktest to generate arbitrary Crates and feed them into the compiler.

@Aatch Aatch added the I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Feb 28, 2017
@ghost
Copy link

ghost commented Feb 28, 2017

So how do we handle this ?

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 22, 2019
@qarmin
Copy link

qarmin commented Apr 6, 2021

I can't reproduce this with rustc 1.51.0 (2fd73fabe 2021-03-23)

@oli-obk oli-obk closed this as completed Apr 22, 2021
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-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants