Skip to content

Commit

Permalink
Unrolled build for rust-lang#130665
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#130665 - veera-sivarajan:fix-118612, r=compiler-errors

Prevent Deduplication of `LongRunningWarn`

Fixes rust-lang#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.
  • Loading branch information
rust-timer authored Sep 22, 2024
2 parents 1f9a018 + 669f610 commit 78af392
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,14 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
// 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,
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 78af392

Please sign in to comment.