Open theemathas opened 1 month ago
NB: This only affects polymorphically recursive calls (i.e., calls where the generic args change at each step). Normal recursive calls lead to cycle errors.
Hmm... The immediate solution I can come up with is to use the recursion limit to limit query depth, but that's going to be hard to tune to a good value without breaking random crates (most likely binary crates that we don't see on crater).
The immediate solution I can come up with is to use the recursion limit to limit query depth
That would also solve #114192.
I think there might be something else going on here. If I try to compile this reproducer I get a freeze with growing memory usage, which is what I would expect.
But if I try to ctrl-c the process, I... get a segfault?
╭ ➜ ben@archlinux:/tmp
╰ ➤ rustc +nightly ice.rs --crate-type=lib
^Cerror: rustc interrupted by SIGSEGV, printing backtrace
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x3150996)[0x7de413b50996]
/usr/lib/libc.so.6(+0x3cae0)[0x7de410850ae0]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-45288dcc88911a1f.so(_ZN4core3fmt5write17hd4702675b19bc4d7E+0x8)[0x7de417308518]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c169)[0x7de41615c169]
### cycle encountered after 4 frames with period 6
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575b40d)[0x7de41615b40d]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c19b)[0x7de41615c19b]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575b40d)[0x7de41615b40d]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c19b)[0x7de41615c19b]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575b40d)[0x7de41615b40d]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c19b)[0x7de41615c19b]
### recursed 42 times
note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
Segmentation fault (core dumped)
It probably tries to run the Ctrl-C handler and emit a mir interpreter backtrace, but that logic doesn't use ensure_sufficient_stack
and hits the stack overflow protection. Queries on the other band just allocate more stack when necessary
The above code causes the compiler to hang, apparently in an infinite loop. I expected it to report an error due to a recursion limit or a timeout.
Note that removing the const block causes the compiler to correctly report an error.
Code without the const block
```rust const fn fooChanging the infinite recursion into an infinite loop correctly causes a timeout.
Code with an infinite loop instead of an infinite recursion
```rust const fn foo() { const { loop {} } } const X: () = foo(); ``` This code results in the following error: ``` Compiling playground v0.0.1 (/playground) warning: unreachable expression --> src/lib.rs:2:5 | 2 | const { loop {} } | ^^^^^^^^-------^^ | | | | | any code following this expression is unreachable | unreachable expression | = note: `#[warn(unreachable_code)]` on by default error: constant evaluation is taking a long time --> src/lib.rs:2:13 | 2 | const { loop {} } | ^^^^^^^ | = note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval. If your compilation actually takes a long time, you can safely allow the lint. help: the constant being evaluated --> src/lib.rs:2:5 | 2 | const { loop {} } | ^^^^^^^^^^^^^^^^^ = note: `#[deny(long_running_const_eval)]` on by default note: erroneous constant encountered --> src/lib.rs:2:5 | 2 | const { loop {} } | ^^^^^^^^^^^^^^^^^ warning: function `foo` is never used --> src/lib.rs:1:10 | 1 | const fn foo() { | ^^^ | = note: `#[warn(dead_code)]` on by default warning: constant `X` is never used --> src/lib.rs:5:7 | 5 | const X: () = foo(); | ^ warning: `playground` (lib) generated 3 warnings error: could not compile `playground` (lib) due to 1 previous error; 3 warnings emitted ```See also #125713
Meta
rustc --version --verbose
: