Rollup merge of #130665 - veera-sivarajan:fix-118612, r=compiler-errors

Prevent Deduplication of `LongRunningWarn`

Fixes #118612

As mention in the issue, `LongRunningWarn` is meant to be repeated multiple times.

Therefore, this PR stores a unique number in every instance of `LongRunningWarn` so that it's not hashed into the same value and omitted by the deduplication mechanism.
This commit is contained in:
Jubilee 2024-09-21 22:34:34 -07:00 committed by GitHub
commit b0208640c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 126 additions and 1 deletions

View File

@ -641,7 +641,14 @@ fn increment_const_eval_counter(ecx: &mut InterpCx<'tcx, Self>) -> InterpResult<
// current number of evaluated terminators is a power of 2. The latter gives us a cheap
// way to implement exponential backoff.
let span = ecx.cur_span();
ecx.tcx.dcx().emit_warn(LongRunningWarn { span, item_span: ecx.tcx.span });
// We store a unique number in `force_duplicate` to evade `-Z deduplicate-diagnostics`.
// `new_steps` is guaranteed to be unique because `ecx.machine.num_evaluated_steps` is
// always increasing.
ecx.tcx.dcx().emit_warn(LongRunningWarn {
span,
item_span: ecx.tcx.span,
force_duplicate: new_steps,
});
}
}

View File

@ -209,6 +209,8 @@ pub struct LongRunningWarn {
pub span: Span,
#[help]
pub item_span: Span,
// Used for evading `-Z deduplicate-diagnostics`.
pub force_duplicate: usize,
}
#[derive(Subdiagnostic)]

View File

@ -0,0 +1,24 @@
//@ check-pass
#![allow(long_running_const_eval)]
//@ compile-flags: -Z tiny-const-eval-limit -Z deduplicate-diagnostics=yes
const FOO: () = {
let mut i = 0;
loop {
//~^ WARN is taking a long time
//~| WARN is taking a long time
//~| WARN is taking a long time
//~| WARN is taking a long time
//~| WARN is taking a long time
if i == 1000 {
break;
} else {
i += 1;
}
}
};
fn main() {
FOO
}

View File

@ -0,0 +1,92 @@
warning: constant evaluation is taking a long time
--> $DIR/evade-deduplication-issue-118612.rs:8:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | | }
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
LL | const FOO: () = {
| ^^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/evade-deduplication-issue-118612.rs:8:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | | }
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
LL | const FOO: () = {
| ^^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/evade-deduplication-issue-118612.rs:8:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | | }
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
LL | const FOO: () = {
| ^^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/evade-deduplication-issue-118612.rs:8:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | | }
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
LL | const FOO: () = {
| ^^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/evade-deduplication-issue-118612.rs:8:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | | }
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
LL | const FOO: () = {
| ^^^^^^^^^^^^^
warning: 5 warnings emitted