Skip to main content

Module reconstruct_fallible_operations

Module reconstruct_fallible_operations 

Source
Expand description

Β§Micro-pass: remove the dynamic checks for array/slice bounds, overflow, and division by zero.

Note that from a semantic point of view, an out-of-bound access or a division by zero must lead to a panic in Rust (which is why those checks are always present, even when compiling for release). In our case, we take this into account in the semantics of our array/slice manipulation and arithmetic functions, on the verification side.

StructsΒ§

PendingShiftCheck πŸ”’
A shift overflow check whose shift operation is not in the same block: rustc evaluates the shift operands (which is when it emits the overflow check) before computing the destination place, so when that computation involves a function call (e.g. out[i] = x >> y through an overloaded IndexMut), the check ends up separated from the shift by the call terminator. See issue #1041. These asserts are only ever emitted by the compiler, so instead of following the control flow we record the check and find the matching shift over the whole body in resolve_pending_shift_check.
Transform

FunctionsΒ§

compute_uses πŸ”’
Compute for each block the locals that are assumed to have been initialized/defined before entering it.
equiv_op πŸ”’
Check if the two operands are equivalent: either they’re the same constant, or they represent the same place (regardless of whether the operand is a move or a copy)
make_binop_overflow_panic πŸ”’
make_unop_overflow_panic πŸ”’
remove_dynamic_checks πŸ”’
Rustc inserts dynamic checks during MIR lowering. They all end in an Assert statement (and this is the only use of this statement).
resolve_pending_shift_check πŸ”’
Resolve a PendingShiftCheck whose shift landed in a different block. We remove the check and compute the shift early, promoted to panic-on-overflow, into a fresh local placed where the check used to be; the fresh local then carries the result to the original destination.
uses_local πŸ”’
Whether the value uses the given local in a place.

Type AliasesΒ§

LocalUses πŸ”’