Skip to content

Commit

Permalink
Auto merge of rust-lang#106227 - bryangarza:ctfe-limit, r=oli-obk
Browse files Browse the repository at this point in the history
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: rust-lang#103877
  • Loading branch information
bors committed Jan 29, 2023
2 parents 7ef46c8 + 706d7ff commit ba7bb62
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ fn codegen_stmt<'tcx>(
StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::Deinit(_)
| StatementKind::ConstEvalCounter
| StatementKind::Nop
| StatementKind::FakeRead(..)
| StatementKind::Retag { .. }
Expand Down
1 change: 1 addition & 0 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
| StatementKind::Retag(_, _)
| StatementKind::AscribeUserType(_, _)
| StatementKind::Coverage(_)
| StatementKind::ConstEvalCounter
| StatementKind::Nop => {}
}
}
Expand Down

0 comments on commit ba7bb62

Please sign in to comment.