Skip to main content

Module mir_utils

Module mir_utils 

Source

EnumsΒ§

RangeKind πŸ”’
The concrete core::ops::Range* struct a DefId denotes.

FunctionsΒ§

aggregate_op_is_nonzero πŸ”’
alloc_id_bytes πŸ”’
Read bytes from a global allocation.
arg_of_local
Return the zero-based argument index of local, if it is a MIR argument.
blocks_reachable_after_call
Collect all basic blocks reachable after a call block’s normal return, or β€” for a non-call block such as a raw-pointer deref statement β€” after the block itself (all of its successors).
call_destination
Return the destination local for a checkpoint’s call or deref.
call_name
Return a stable, human-readable name for a MIR call operand.
callee_param_index_for_local
Return the callee argument index represented by a MIR local.
catch_panic πŸ”’
Run f inside catch_unwind, returning either the result or the downcasted panic message.
collect_aggregate_const_bytes πŸ”’
collect_all_const_bytes_worklist
collect_as_ptr_const_bytes πŸ”’
collect_return_block_indices
Collect all return basic block indices for a function body.
const_bytes_for_local
const_bytes_from_call_dest πŸ”’
const_int_from_debug
Parse an integer from a MIR constant’s Debug text. Handles decimal, 0x hex, and Value(...) forms.
const_operand_bytes
Try to extract raw bytes from a MIR constant operand that is a reference to a byte array/slice (e.g. b"hello\0"). Returns the byte values. Used by the VM to populate byte-level tracking for constant C strings.
const_value_bytes πŸ”’
Extract raw bytes from a ConstValue, following reference indirection.
dep_callee_def_id πŸ”’
dep_callee_resolved_def_id πŸ”’
Like dep_callee_def_id, but resolves trait-method callees to their concrete impl so cross-crate Deref/DerefMut bodies β€” whose trait-method DefId has no available MIR β€” can still be inlined.
destination_stride
eval_array_len πŸ”’
Resolve an array length const (ty::Const) to a concrete u64. Unlike try_to_target_usize, this also evaluates unevaluated const expressions (e.g. [MaybeUninit<K>; CAPACITY] where CAPACITY = 2 * B - 1), so the VM can allocate the array with its true element count instead of a collapsed zero-size fallback.
eval_const_scalar_int
Resolve a MIR constant to a concrete integer, falling back from the cheap debug-text parse to full const evaluation.
extract_local
Extract the bare local from a Copy/Move operand with no projection.
field_offset_in_bytes
Byte offset of a struct field within its container type (0 on failure).
field_ty
Resolve a struct field’s type, normalizing where the rustc version requires it.
fn_always_returns_nonzero πŸ”’
fn_def_first_type_arg πŸ”’
Extract the first Type generic argument of an FnDef call operand.
follow_parents
Follow a parents map (built by verify::property_checker::cstr’s body_parents) from start to its root local, guarding against cycles.
generic_param_impl_layouts πŸ”’
Collect the layouts of every concrete implementor of a generic type parameter’s trait bounds (empty for non-param types).
has_crate
has_rapx_attr πŸ”’
Whether a local item carries a #[rapx::<name>(...)] attribute.
has_rapx_verify_attr
is_as_ptr_or_as_method πŸ”’
is_const_def_kind πŸ”’
Whether a DefId is a const-like item that mir_for_ctfe accepts.
is_constant_zero πŸ”’
is_diverging_call πŸ”’
Whether def_id is a diverging call target: a panic* lang item or the unreachable/abort intrinsics.
is_drop_in_place πŸ”’
Whether def_id is core::ptr::drop_in_place.
is_eq_call πŸ”’
Whether func is a call to PartialEq::eq (the equality comparison), determined from its DefId rather than by string-matching the callee path.
is_index_method πŸ”’
Whether def_id is the Index::index / IndexMut::index_mut trait method.
is_iter_ptr_adj πŸ”’
Whether def_id is one of post_inc_start / pre_dec_end.
is_post_inc_start πŸ”’
Whether def_id is slice::Iter/IterMut’s private post_inc_start helper (a pointer-advancing side effect that cannot be inlined because of its ZST SwitchInt branch).
is_pre_dec_end πŸ”’
Whether def_id is pre_dec_end (the end-decrementing sibling of post_inc_start).
is_range_type πŸ”’
Whether def_id is any core::ops::Range* struct.
is_raw_ptr_wrapper
Whether def_id is a single-field struct wrapping a raw pointer (i.e. NonNull-shaped). Used by alias/ownership reasoning to recognize pointer wrappers β€” including local re-implementations β€” by their structure rather than by a std DefId.
is_return_block
Whether block ends in a Return terminator (a normal exit point).
is_std_crate_def_id
is_trait_unsafe
is_u8_array_or_slice
Whether a type is a u8 array ([u8; N]) or u8 slice ([u8]).
layout_of_ty
Compute the full type layout, catching rustc panics and layout errors. Shared by type_layout and the symbolic VM’s size/align/field-offset queries so the layout_of call and its panic-guard live in one place.
max_align_of_generic_param
Max align_of over all implementors of a generic type parameter’s trait bounds (0 for non-param types or a parameter without a bounded set of implementors).
min_align_of_generic_param
Min align_of over all implementors of a generic type parameter’s trait bounds (0 for non-param types).
offset_of_container πŸ”’
If constant is a promoted offset_of!(Container, field) constant (an unevaluated Const whose body is a call to the offset_of intrinsic), return the container type.
offset_of_ty_from_func πŸ”’
operand_const_u64
Extract a constant u64 value from an operand, if it’s a known constant.
operand_mir_place
Extract the MIR Place from an operand.
operand_place
Extract a PlaceKey from a MIR operand.
operand_scalar_int πŸ”’
pointee_alignment
pointee_ty πŸ”’
range_kind πŸ”’
Classify a DefId as one of the core::ops::Range* structs.
resolve_callee_impl πŸ”’
Resolve a (possibly trait-method) callee to the concrete impl method that will actually be dispatched, given the caller context and the callee’s generic arguments. Returns None when the callee cannot be resolved to a distinct concrete item (e.g. still generic/virtual), or is not a trait method at all (callers should then keep the original DefId).
resolve_const_item_value πŸ”’
Resolve a const item (e.g. const CAPACITY: usize = 2 * B - 1) by name in the local crate to its evaluated unsigned-integer value, for use in the contract DSL (ValidNum(len <= CAPACITY)).
resolve_impl_self_ty_def_id
resolve_through_casts
Resolve a local through Cast assignments back to its non-cast source.
rvalue_any_place_matching
Check whether any MIR place used in an rvalue matches a predicate.
rvalue_const_bytes πŸ”’
rvalue_is_nonzero πŸ”’
rvalue_runtime_checks_value πŸ”’
Resolve a cfg!-style runtime-check flag (UbChecks, ContractChecks, OverflowChecks) to a constant u64. We fold to the no-check edge (0): the check only panics on a violated precondition, and its branchy body would otherwise corrupt field/Typed propagation during inlining. Older rustc lowers these to Rvalue::NullaryOp(NullOp::RuntimeChecks); newer rustc lowers them to Operand::RuntimeChecks.
rvalue_source_place
Extracts the source Place from an rvalue for simple forwarding operations (copy, move, cast, reference, raw-pointer, copy-for-deref).
size_of_generic_param
Max size_of over all implementors of a generic type parameter’s trait bounds (0 for non-param types).
switch_is_debug_assert πŸ”’
Whether a block’s SwitchInt is a debug_assert!-style dispatch (all non-otherwise targets are panic/unreachable), or has a constant / runtime-check discriminant that folds to a single live edge. Such a switch is dead on the normal path and is safe to ignore when inlining.
switch_targets_unreachable πŸ”’
Whether a SwitchInt’s non-otherwise targets all lead straight to panic/unreachable (a debug_assert!/assert! dispatch). Such a switch is dead on the normal path and can be inlined by following only the otherwise edge.
trace_const_bytes_from_operand πŸ”’
ty_has_param_const πŸ”’
True when a type transitively contains a const-generic parameter or an associated type alias (which may be layout-ambiguous).
ty_has_type_param πŸ”’
Whether ty mentions a (type) generic parameter anywhere in its structure, e.g. T, *mut T, Option<T>.
type_contains_raw_ptr
Whether a type transitively contains a raw pointer, recursing through tuple elements and Adt fields. Unlike type_contains_reference, this does not match references β€” a method returning &*self.raw re-borrows the pointee (safe) rather than leaking the raw pointer value itself (unsafe).
type_contains_reference
Whether a type transitively contains a reference.
type_layout