]> git.lizzy.rs Git - rust.git/commit
Auto merge of #51702 - ecstatic-morse:infinite-loop-detection, r=oli-obk
authorbors <bors@rust-lang.org>
Wed, 11 Jul 2018 16:24:46 +0000 (16:24 +0000)
committerbors <bors@rust-lang.org>
Wed, 11 Jul 2018 16:24:46 +0000 (16:24 +0000)
commitd573fe17786b9c2f5a766498d411d54eee5fa19f
tree03d5b85004a849dff84569e88063e24b4826f8f2
parent66787e05242d86e0bcfa227265559330c45cdc42
parentcf5eaa75bb171f00d6baa475333b741b86f93f72
Auto merge of #51702 - ecstatic-morse:infinite-loop-detection, r=oli-obk

Infinite loop detection for const evaluation

Resolves #50637.

An `EvalContext` stores the transient state (stack, heap, etc.) of the MIRI virtual machine while it executing code. As long as MIRI only executes pure functions, we can detect if a program is in a state where it will never terminate by periodically taking a "snapshot" of this transient state and comparing it to previous ones. If any two states are exactly equal, the machine must be in an infinite loop.

Instead of fully cloning a snapshot every time the detector is run, we store a snapshot's hash. Only when a hash collision occurs do we fully clone the interpreter state. Future snapshots which cause a collision will be compared against this clone, causing the interpreter to abort if they are equal.

At the moment, snapshots are not taken until MIRI has progressed a certain amount. After this threshold, snapshots are taken every `DETECTOR_SNAPSHOT_PERIOD` steps. This means that an infinite loop with period `P` will be detected after a maximum of `2 * P * DETECTOR_SNAPSHOT_PERIOD` interpreter steps. The factor of 2 arises because we only clone a snapshot after it causes a hash collision.
src/librustc/mir/mod.rs