rust/src/librustc_interface
bors 97f3eeec82 Auto merge of #55617 - oli-obk:stacker, r=nagisa,oli-obk
Prevent compiler stack overflow for deeply recursive code

I was unable to write a test that

1. runs in under 1s
2. overflows on my machine without this patch

The following reproduces the issue, but I don't think it's sensible to include a test that takes 30s to compile. We can now easily squash newly appearing overflows by the strategic insertion of calls to `ensure_sufficient_stack`.

```rust
// compile-pass

#![recursion_limit="1000000"]

macro_rules! chain {
    (EE $e:expr) => {$e.sin()};
    (RECURSE $i:ident $e:expr) => {chain!($i chain!($i chain!($i chain!($i $e))))};
    (Z $e:expr) => {chain!(RECURSE EE $e)};
    (Y $e:expr) => {chain!(RECURSE Z $e)};
    (X $e:expr) => {chain!(RECURSE Y $e)};
    (A $e:expr) => {chain!(RECURSE X $e)};
    (B $e:expr) => {chain!(RECURSE A $e)};
    (C $e:expr) => {chain!(RECURSE B $e)};
    // causes overflow on x86_64 linux
    // less than 1 second until overflow on test machine
    // after overflow has been fixed, takes 30s to compile :/
    (D $e:expr) => {chain!(RECURSE C $e)};
    (E $e:expr) => {chain!(RECURSE D $e)};
    (F $e:expr) => {chain!(RECURSE E $e)};
    // more than 10 seconds
    (G $e:expr) => {chain!(RECURSE F $e)};
    (H $e:expr) => {chain!(RECURSE G $e)};
    (I $e:expr) => {chain!(RECURSE H $e)};
    (J $e:expr) => {chain!(RECURSE I $e)};
    (K $e:expr) => {chain!(RECURSE J $e)};
    (L $e:expr) => {chain!(RECURSE L $e)};
}

fn main() {
    let x = chain!(D 42.0_f32);
}
```

fixes #55471
fixes #41884
fixes #40161
fixes #34844
fixes #32594

cc @alexcrichton @rust-lang/compiler

I looked at all code that checks the recursion limit and inserted stack growth calls where appropriate.
2020-05-07 00:03:23 +00:00
..
build.rs Locate rustc binary similarly to codegen backend loading 2019-09-10 16:57:14 -04:00
callbacks.rs Query-ify Instance::resolve 2020-04-05 01:21:36 -04:00
Cargo.toml Remove unused dependencies 2020-04-20 17:59:27 +09:00
interface.rs fix miri-unleash delayed sanity checking 2020-05-02 14:39:19 +02:00
lib.rs Depend on libc from crates.io 2020-04-11 11:07:04 -04:00
passes.rs cleanup: config::CrateType -> CrateType 2020-05-02 11:57:23 +03:00
proc_macro_decls.rs librustc_middle: return LocalDefId instead of DefId in local_def_id 2020-04-23 23:14:07 +01:00
queries.rs Change return type of entry_fn query to return a LocalDefId 2020-04-27 23:58:11 +01:00
tests.rs Rollup merge of #71269 - Mark-Simulacrum:sat-float-casts, r=nikic 2020-05-06 16:58:50 +02:00
util.rs Auto merge of #55617 - oli-obk:stacker, r=nagisa,oli-obk 2020-05-07 00:03:23 +00:00