diff options
| author | Bryan Garza <1396101+bryangarza@users.noreply.github.com> | 2022-12-20 00:51:17 +0000 |
|---|---|---|
| committer | Bryan Garza <1396101+bryangarza@users.noreply.github.com> | 2023-01-23 23:56:22 +0000 |
| commit | 360db516ccf358bd4b35c483ae44634a74c66c0b (patch) | |
| tree | b93ee5a07bbfa3db492ba3baaa26f645b4252121 /compiler/rustc_const_eval/src/interpret | |
| parent | c8e6a9e8b6251bbc8276cb78cabe1998deecbed7 (diff) | |
| download | rust-360db516ccf358bd4b35c483ae44634a74c66c0b.tar.gz rust-360db516ccf358bd4b35c483ae44634a74c66c0b.zip | |
Create stable metric to measure long computation in Const Eval
This patch adds a `MirPass` that tracks the number of back-edges and function calls in the CFG, adds a new MIR instruction to increment a counter every time they are encountered during Const Eval, and emit a warning if a configured limit is breached.
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/eval_context.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/place.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/step.rs | 5 |
3 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index d13fed7a9c2..cc97564e8fc 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -46,6 +46,9 @@ pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// The recursion limit (cached from `tcx.recursion_limit(())`) pub recursion_limit: Limit, + + pub const_eval_limit: u32, + pub const_eval_counter: u32, } // The Phantomdata exists to prevent this type from being `Send`. If it were sent across a thread @@ -408,6 +411,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { param_env, memory: Memory::new(), recursion_limit: tcx.recursion_limit(), + const_eval_limit: 20, + const_eval_counter: 0, } } diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 274af61ee7c..271a3a74fe3 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -293,6 +293,17 @@ where Prov: Provenance + 'static, M: Machine<'mir, 'tcx, Provenance = Prov>, { + pub fn increment_const_eval_counter(&mut self) { + self.const_eval_counter = self.const_eval_counter + 1; + if self.const_eval_counter == self.const_eval_limit { + let mut warn = self.tcx.sess.struct_warn(format!( + "Const eval counter limit ({}) has been crossed", + self.const_eval_limit + )); + warn.emit(); + } + } + /// Take a value, which represents a (thin or wide) reference, and make it a place. /// Alignment is just based on the type. This is the inverse of `MemPlace::to_ref()`. /// diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index fad4cb06cd6..0f0eb5aadd7 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -129,6 +129,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // FIXME(#73156): Handle source code coverage in const eval Coverage(..) => {} + // FIXME(bryangarza): Update this to do some logic!!! + ConstEvalCounter => { + self.increment_const_eval_counter(); + } + // Defined to do nothing. These are added by optimization passes, to avoid changing the // size of MIR constantly. Nop => {} |
