Skip to main content

Module mir_utils

Module mir_utils 

Source

Re-exportsΒ§

use crate::analysis::dataflow::call_summary::effects::has_registered_effect; πŸ”’
use crate::analysis::dataflow::call_summary::function_var::supports_result; πŸ”’
use crate::compat::FxHashMap; πŸ”’
use crate::compat::GenericArgsRef; πŸ”’
use crate::def_ids::diagnostic_api; πŸ”’
use crate::def_ids::intrinsic_api; πŸ”’
use crate::def_ids::lang_api; πŸ”’
use crate::def_ids::lang_api::LangItem; πŸ”’
use crate::def_ids::type_ids; πŸ”’
use rustc_hir::ItemKind; πŸ”’
use rustc_hir::def::DefKind; πŸ”’
use rustc_hir::def_id::DefId; πŸ”’
use rustc_hir::def_id::LocalDefId; πŸ”’
use rustc_middle::ty::ShimKind; πŸ”’
use rustc_middle::ty::AliasConstKind; πŸ”’
use rustc_middle::mir::interpret::AllocId; πŸ”’
use rustc_middle::mir::interpret::GlobalAlloc; πŸ”’
use rustc_middle::mir::BasicBlock; πŸ”’
use rustc_middle::mir::Body; πŸ”’
use rustc_middle::mir::ConstValue; πŸ”’
use rustc_middle::mir::Local; πŸ”’
use rustc_middle::mir::Operand; πŸ”’
use rustc_middle::mir::Place; πŸ”’
use rustc_middle::mir::Rvalue; πŸ”’
use rustc_middle::mir::StatementKind; πŸ”’
use rustc_middle::mir::SwitchTargets; πŸ”’
use rustc_middle::mir::TerminatorKind; πŸ”’
use rustc_middle::ty::Const; πŸ”’
use rustc_middle::ty::ConstKind; πŸ”’
use rustc_middle::ty::FieldDef; πŸ”’
use rustc_middle::ty::GenericArgKind; πŸ”’
use rustc_middle::ty::GenericArgs; πŸ”’
use rustc_middle::ty::GenericParamDefKind; πŸ”’
use rustc_middle::ty::Instance; πŸ”’
use rustc_middle::ty::InstanceKind; πŸ”’
use rustc_middle::ty::PseudoCanonicalInput; πŸ”’
use rustc_middle::ty::ScalarInt; πŸ”’
use rustc_middle::ty::Ty; πŸ”’
use rustc_middle::ty::TyCtxt; πŸ”’
use rustc_middle::ty::TyKind; πŸ”’
use rustc_middle::ty::TypeFlags; πŸ”’
use rustc_middle::ty::TypeSuperVisitable; πŸ”’
use rustc_middle::ty::TypeVisitable; πŸ”’
use rustc_middle::ty::TypeVisitableExt; πŸ”’
use rustc_middle::ty::TypeVisitor; πŸ”’
use rustc_middle::ty::TypingEnv; πŸ”’
use rustc_span::DUMMY_SP; πŸ”’
use rustc_span::Symbol; πŸ”’
use std::collections::HashSet; πŸ”’
use std::ops::ControlFlow; πŸ”’
use super::def_use::PlaceKey; πŸ”’

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_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_return_block_indices
Collect all return basic block indices for a function body.
const_bytes_for_local
const_destructure πŸ”’
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.
ctfe_mir_available πŸ”’
Whether mir_for_ctfe can query this locally available const-like definition.
dep_callee_def_id πŸ”’
enumerate_mono_instances πŸ”’
Enumerate up to limit instances of a generic function using concrete implementors of one type parameter bound, including containing impl bounds.
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
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_direct_unmodeled_generic_call πŸ”’
A callee may need its own MIR instantiated when an immediate trait call can change target after substituting the caller’s type arguments.
has_function_var_effect πŸ”’
has_generic_const_call_argument πŸ”’
has_rapx_attr πŸ”’
Whether a local item carries a #[rapx::<name>(...)] attribute.
has_rapx_verify_attr
has_unmodeled_generic_call πŸ”’
Whether def_id’s body (or any callee it would inline) contains a trait-method call with no executable MIR (a still-generic T: Bound or virtual dispatch) and no symbolic model β€” i.e. a call whose opaque fallback would lose dataflow and therefore benefits from caller monomorphization.
has_unmodeled_generic_call_rec πŸ”’
has_unresolved_const_args πŸ”’
instance_def_id πŸ”’
Map a resolved [Instance] to its concrete target DefId and whether the dispatch is virtual. None for kinds with no single target (e.g. a closure’s Clone shim).
is_const_def_kind πŸ”’
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_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_sized_type_property πŸ”’
Whether def is a SizedTypeProperties::<ASSOC> associated const β€” a compiler-internal layout constant (SIZE, ALIGN, IS_ZST) that has no lang/diagnostic item, so it is matched by its def-path suffix.
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_align_bytes
ABI alignment in bytes across rustc layout API versions.
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).
monomorphize_instance πŸ”’
Build a partially-monomorphized [Instance] for def_id, replacing one type parameter and leaving the others as parameters.
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_const_u128
Extract a scalar constant’s full bit pattern for typed interpretation.
operand_mir_place
Extract the MIR Place from an operand.
operand_place
Extract a PlaceKey from a MIR operand.
operand_scalar_int πŸ”’
pointee_ty πŸ”’
projected_field_ty πŸ”’
Resolve a field-index path against its root type, including Some/Ok wrappers.
range_kind πŸ”’
Classify a DefId as one of the core::ops::Range* structs.
resolve_callee_def_id πŸ”’
Return the call’s DefId, using the selected impl method’s DefId when available. Otherwise return the DefId from the operand.
resolve_callee_instance πŸ”’
Resolve a call func operand to its monomorphized [Instance].
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_instance πŸ”’
Resolve a FnDef(def_id, args) (already skip_binderd by the caller) to its monomorphized [Instance] in caller’s post-analysis typing env.
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. Rustc lowers these 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).
scalar_int_value πŸ”’
size_of_generic_param
Max size_of over all implementors of a generic type parameter’s trait bounds (0 for non-param types).
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.
trait_impl_candidates πŸ”’
Enumerate the concrete impl methods that could be dispatched for a trait method (the set of targets behind a trait-object / virtual call). Each returned DefId is an impl’s override of method_def_id.
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
type_param_impl_tys πŸ”’
Enumerate the concrete self types implementing a type parameter’s trait bounds. Chooses the bound with the fewest concrete (non-generic) impls β€” the β€œsmall” helper trait that usually pins the supported types (e.g. GetDisjointMutIndex over the generic SliceIndex/Clone bounds) β€” and returns its concrete impl self types.