Skip to content

CTFE: nullary function memoization munges backtraces #75390

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
RalfJung opened this issue Aug 11, 2020 · 2 comments · Fixed by #79594
Closed

CTFE: nullary function memoization munges backtraces #75390

RalfJung opened this issue Aug 11, 2020 · 2 comments · Fixed by #79594
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

This code:

#![feature(const_panic)]
#![feature(const_fn)]

const fn foo(x: i32) {
    panic!();
}

const fn bar(x: i32) { foo(x) }

const _:() = bar(13);

produces a fairly reasonable error:

error: any use of this value will cause an error
  --> src/lib.rs:5:5
   |
5  |     panic!();
   |     ^^^^^^^^^
   |     |
   |     the evaluated program panicked at 'explicit panic', src/lib.rs:5:5
   |     inside `foo` at /rustc/770bd3d1d03f0de2e27b1ae6a0604597d0e26f84/library/std/src/macros.rs:13:23
   |     inside `bar` at src/lib.rs:8:24
   |     inside `_` at src/lib.rs:10:14
...
10 | const _:() = bar(13);
   | ---------------------
   |
   = note: `#[deny(const_err)]` on by default
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

However, when I remove the dummy argument x, I get the following set of three separate errors:

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:5:5
  |
5 |     panic!();
  |     ^^^^^^^^^ the evaluated program panicked at 'explicit panic', src/lib.rs:5:5
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:8:18
  |
8 | const fn bar() { foo() }
  |                  ^^^^^ referenced constant has errors

error: any use of this value will cause an error
  --> src/lib.rs:10:14
   |
10 | const _:() = bar();
   | -------------^^^^^-
   |              |
   |              referenced constant has errors
   |
   = note: `#[deny(const_err)]` on by default

All the information is still there, but it is now not clear at all that this is in fact just a single const-eval stacktrace we are seeing here.

Cc @rust-lang/wg-const-eval

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2020
@bors bors closed this as completed in d015f0d Dec 3, 2020
@RalfJung
Copy link
Member Author

RalfJung commented Dec 3, 2020

Argumentless intrinsics are still being memoized, but I guess the point is that none of them can fail so there cannot be strange errors due to that?

@oli-obk
Copy link
Contributor

oli-obk commented Dec 4, 2020

Also none of them call any other functions or intrinsics, so there are no backtrace situations either

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants