Skip to content

CTFE: LongRunningWarn is getting implicitly deduplicated  #118612

Closed
@lcnr

Description

@lcnr

I tried the following code:

#![allow(long_running_const_eval)]
const FOO: () = loop {};

fn main() {
    FOO
}

output after running for a very long time:

warning: constant evaluation is taking a long time
 --> src/main.rs:2:17
  |
2 | const FOO: () = loop {};
  |                 ^^^^^^^ the const evaluator is currently interpreting this expression
  |
help: the constant being evaluated
 --> src/main.rs:2:1
  |
2 | const FOO: () = loop {};
  | ^^^^^^^^^^^^^

modify rustc as follows results in the following output:

diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs
index 2d8ca67c3a5..1bf7949725b 100644
--- a/compiler/rustc_const_eval/src/const_eval/machine.rs
+++ b/compiler/rustc_const_eval/src/const_eval/machine.rs
@@ -593,6 +593,9 @@ fn increment_const_eval_counter(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpR
             };
 
             ecx.machine.num_evaluated_steps = new_steps;
+            if new_steps.is_power_of_two() {
+                eprintln!("power of two : {new_steps}");
+            }
             // By default, we have a *deny* lint kicking in after some time
             // to ensure `loop {}` doesn't just go forever.
             // In case that lint got reduced, in particular for `--cap-lint` situations, we also
   Compiling test1 v0.1.0 (/home/lcnr/test1)
power of two : 1
power of two : 2
power of two : 4
power of two : 8
power of two : 16
power of two : 32
power of two : 64
power of two : 128
power of two : 256
power of two : 512
power of two : 1024
power of two : 2048
power of two : 4096
power of two : 8192
power of two : 16384
power of two : 32768
power of two : 65536
power of two : 131072
power of two : 262144
power of two : 524288
power of two : 1048576
power of two : 2097152
power of two : 4194304
warning: constant evaluation is taking a long time
 --> src/main.rs:2:17
  |
2 | const FOO: () = loop {};
  |                 ^^^^^^^ the const evaluator is currently interpreting this expression
  |
help: the constant being evaluated
 --> src/main.rs:2:1
  |
2 | const FOO: () = loop {};
  | ^^^^^^^^^^^^^

power of two : 8388608
power of two : 16777216
power of two : 33554432
power of two : 67108864
power of two : 134217728

changing the invocation to cargo rustc -- -Zdeduplicate-diagnostics=no actually prints the warning at each power of two of steps.

This warning should not be affected by deduplicate-diagnostics. It's whole point is to be repeated multiple times.

cc @oli-obk @RalfJung

Metadata

Metadata

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.D-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions