rust/src/librustc_data_structures
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
..
base_n Format the world 2019-12-22 17:42:47 -05:00
binary_search_util Galloping search for binary_search_util 2020-01-12 01:38:07 +01:00
graph sccs are computed in dependency order 2020-04-21 08:57:14 +00:00
obligation_forest fix rustdoc warnings 2020-05-02 10:41:04 +02:00
owning_ref Format the world 2019-12-22 17:42:47 -05:00
sip128 Format the world 2019-12-22 17:42:47 -05:00
small_c_str librustc_data_structures: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
snapshot_map perf: Lazily recive the Rollback argument in rollback_to 2020-05-05 11:24:36 +02:00
sorted_map Implement an insertion-order preserving, efficient multi-map 2020-02-19 10:51:40 -08:00
tiny_list Format the world 2019-12-22 17:42:47 -05:00
transitive_relation Format the world 2019-12-22 17:42:47 -05:00
atomic_ref.rs Store callbacks in global statics 2019-12-25 14:10:46 -05:00
base_n.rs Format the world 2019-12-22 17:42:47 -05:00
box_region.rs Replace thread_local with generator resume arguments in box_region. 2020-04-25 18:19:27 +02:00
captures.rs {rustc::util -> rustc_data_structures}::captures 2020-01-09 08:57:24 +01:00
Cargo.toml Auto merge of #55617 - oli-obk:stacker, r=nagisa,oli-obk 2020-05-07 00:03:23 +00:00
const_cstr.rs Format the world 2019-12-22 17:42:47 -05:00
fingerprint.rs Format the world 2019-12-22 17:42:47 -05:00
flock.rs use winapi for non-stdlib Windows bindings 2020-01-11 20:56:46 -05:00
frozen.rs update rustdocs for frozen 2020-03-13 13:36:16 -05:00
fx.rs define_id_collections -> rustc_data_structures 2020-01-04 18:57:22 +01:00
jobserver.rs Re-export Client from rustc_data_structures::jobserver 2019-12-03 12:19:16 -05:00
lib.rs Auto merge of #55617 - oli-obk:stacker, r=nagisa,oli-obk 2020-05-07 00:03:23 +00:00
macros.rs Move macro enum_from_u32 to rustc_data_structures. 2020-02-11 23:03:53 +01:00
map_in_place.rs Move MapInPlace to rustc_data_structures 2020-04-18 13:02:33 +09:00
profiling.rs remove some extra } 2020-04-22 09:18:54 -06:00
ptr_key.rs Format the world 2019-12-22 17:42:47 -05:00
sharded.rs remove redundant closures (clippy::redundant_closure) 2020-03-22 12:43:19 +01:00
sip128.rs clarify operator precedence 2020-02-26 12:43:37 +01:00
small_c_str.rs Format the world 2019-12-22 17:42:47 -05:00
sorted_map.rs Enable --blessing of MIR dumps 2020-03-26 15:26:33 +01:00
stable_hasher.rs rustc_target::abi: add Primitive variant to FieldsShape. 2020-04-16 15:15:51 +00:00
stable_map.rs Format the world 2019-12-22 17:42:47 -05:00
stable_set.rs data_structures: Add deterministic FxHashMap and FxHashSet wrappers 2019-09-28 14:35:20 +05:30
stack.rs Move ensure_sufficient_stack to data_structures 2020-05-02 16:47:52 +02:00
svh.rs Format the world 2019-12-22 17:42:47 -05:00
sync.rs Simplify the signature of par_for_each_in 2020-02-26 15:08:21 -08:00
thin_vec.rs Format the world 2019-12-22 17:42:47 -05:00
tiny_list.rs Make TinyList::remove iterate instead of recurse 2019-12-11 21:05:28 +01:00
transitive_relation.rs fix rustdoc warnings 2020-05-02 10:41:04 +02:00
vec_linked_list.rs Format the world 2019-12-22 17:42:47 -05:00
work_queue.rs Format the world 2019-12-22 17:42:47 -05:00