Skip to content

Commit ba7bb62

Browse files
committed
Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obk
Use stable metric for const eval limit instead of current terminator-based logic This patch adds a `MirPass` that inserts a new MIR instruction `ConstEvalCounter` to any loops and function calls in the CFG. This instruction is used during Const Eval to count against the `const_eval_limit`, and emit the `StepLimitReached` error, replacing the current logic which uses Terminators only. The new method of counting loops and function calls should be more stable across compiler versions (i.e., not cause crates that compiled successfully before, to no longer compile when changes to the MIR generation/optimization are made). Also see: #103877
2 parents 7ef46c8 + 706d7ff commit ba7bb62

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ fn codegen_stmt<'tcx>(
794794
StatementKind::StorageLive(_)
795795
| StatementKind::StorageDead(_)
796796
| StatementKind::Deinit(_)
797+
| StatementKind::ConstEvalCounter
797798
| StatementKind::Nop
798799
| StatementKind::FakeRead(..)
799800
| StatementKind::Retag { .. }

src/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
530530
| StatementKind::Retag(_, _)
531531
| StatementKind::AscribeUserType(_, _)
532532
| StatementKind::Coverage(_)
533+
| StatementKind::ConstEvalCounter
533534
| StatementKind::Nop => {}
534535
}
535536
}

0 commit comments

Comments
 (0)