pub struct InterpCx<'tcx, M: Machine<'tcx>> {
pub machine: M,
pub tcx: TyCtxtAt<'tcx>,
pub(crate) param_env: ParamEnv<'tcx>,
pub memory: Memory<'tcx, M>,
pub recursion_limit: Limit,
}
Fields§
§machine: M
Stores the Machine
instance.
Note: the stack is provided by the machine.
tcx: TyCtxtAt<'tcx>
The results of the type checker, from rustc. The span in this is the “root” of the evaluation, i.e., the const we are evaluating (if this is CTFE).
param_env: ParamEnv<'tcx>
Bounds in scope for polymorphic evaluations.
memory: Memory<'tcx, M>
The virtual memory system.
recursion_limit: Limit
The recursion limit (cached from tcx.recursion_limit(())
)
Implementations§
source§impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>>
impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>>
fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32)
sourcefn hook_special_const_fn(
&mut self,
instance: Instance<'tcx>,
args: &[FnArg<'tcx>],
dest: &MPlaceTy<'tcx>,
ret: Option<BasicBlock>,
) -> InterpResult<'tcx, Option<Instance<'tcx>>>
fn hook_special_const_fn( &mut self, instance: Instance<'tcx>, args: &[FnArg<'tcx>], dest: &MPlaceTy<'tcx>, ret: Option<BasicBlock>, ) -> InterpResult<'tcx, Option<Instance<'tcx>>>
“Intercept” a function call, because we have something special to do for it.
All #[rustc_do_not_const_check]
functions should be hooked here.
If this returns Some
function, which may be instance
or a different function with
compatible arguments, then evaluation should continue with that function.
If this returns None
, the function call has been handled and the function has returned.
sourcefn align_offset(
&mut self,
instance: Instance<'tcx>,
args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>,
ret: Option<BasicBlock>,
) -> InterpResult<'tcx, ControlFlow<()>>
fn align_offset( &mut self, instance: Instance<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ret: Option<BasicBlock>, ) -> InterpResult<'tcx, ControlFlow<()>>
align_offset(ptr, target_align)
needs special handling in const eval, because the pointer
may not have an address.
If ptr
does have a known address, then we return Continue(())
and the function call should
proceed as normal.
If ptr
doesn’t have an address, but its underlying allocation’s alignment is at most
target_align
, then we call the function again with an dummy address relative to the
allocation.
If ptr
doesn’t have an address and target_align
is stricter than the underlying
allocation’s alignment, then we return usize::MAX
immediately.
sourcefn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8>
fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8>
See documentation on the ptr_guaranteed_cmp
intrinsic.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn copy_fn_arg(
&self,
arg: &FnArg<'tcx, M::Provenance>,
) -> OpTy<'tcx, M::Provenance>
pub fn copy_fn_arg( &self, arg: &FnArg<'tcx, M::Provenance>, ) -> OpTy<'tcx, M::Provenance>
Make a copy of the given fn_arg. Any InPlace
are degenerated to copies, no protection of the
original memory occurs.
sourcepub fn copy_fn_args(
&self,
args: &[FnArg<'tcx, M::Provenance>],
) -> Vec<OpTy<'tcx, M::Provenance>>
pub fn copy_fn_args( &self, args: &[FnArg<'tcx, M::Provenance>], ) -> Vec<OpTy<'tcx, M::Provenance>>
Make a copy of the given fn_args. Any InPlace
are degenerated to copies, no protection of the
original memory occurs.
sourcepub(super) fn fn_arg_field(
&self,
arg: &FnArg<'tcx, M::Provenance>,
field: usize,
) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>>
pub(super) fn fn_arg_field( &self, arg: &FnArg<'tcx, M::Provenance>, field: usize, ) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>>
Helper function for argument untupling.
sourcefn unfold_transparent(
&self,
layout: TyAndLayout<'tcx>,
may_unfold: impl Fn(AdtDef<'tcx>) -> bool,
) -> TyAndLayout<'tcx>
fn unfold_transparent( &self, layout: TyAndLayout<'tcx>, may_unfold: impl Fn(AdtDef<'tcx>) -> bool, ) -> TyAndLayout<'tcx>
Find the wrapped inner type of a transparent wrapper. Must not be called on 1-ZST (as they don’t have a uniquely defined “wrapped field”).
We work with TyAndLayout
here since that makes it much easier to iterate over all fields.
sourcefn unfold_npo(
&self,
layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, TyAndLayout<'tcx>>
fn unfold_npo( &self, layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, TyAndLayout<'tcx>>
Unwrap types that are guaranteed a null-pointer-optimization
sourcefn layout_compat(
&self,
caller: TyAndLayout<'tcx>,
callee: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, bool>
fn layout_compat( &self, caller: TyAndLayout<'tcx>, callee: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, bool>
Check if these two layouts look like they are fn-ABI-compatible.
(We also compare the PassMode
, so this doesn’t have to check everything. But it turns out
that only checking the PassMode
is insufficient.)
fn check_argument_compat( &self, caller_abi: &ArgAbi<'tcx, Ty<'tcx>>, callee_abi: &ArgAbi<'tcx, Ty<'tcx>>, ) -> InterpResult<'tcx, bool>
sourcefn pass_argument<'x, 'y>(
&mut self,
caller_args: &mut impl Iterator<Item = (&'x FnArg<'tcx, M::Provenance>, &'y ArgAbi<'tcx, Ty<'tcx>>)>,
callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
callee_arg: &Place<'tcx>,
callee_ty: Ty<'tcx>,
already_live: bool,
) -> InterpResult<'tcx>where
'tcx: 'x + 'y,
fn pass_argument<'x, 'y>(
&mut self,
caller_args: &mut impl Iterator<Item = (&'x FnArg<'tcx, M::Provenance>, &'y ArgAbi<'tcx, Ty<'tcx>>)>,
callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
callee_arg: &Place<'tcx>,
callee_ty: Ty<'tcx>,
already_live: bool,
) -> InterpResult<'tcx>where
'tcx: 'x + 'y,
Initialize a single callee argument, checking the types for compatibility.
sourcepub fn init_stack_frame(
&mut self,
instance: Instance<'tcx>,
body: &'tcx Body<'tcx>,
caller_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[FnArg<'tcx, M::Provenance>],
with_caller_location: bool,
destination: &MPlaceTy<'tcx, M::Provenance>,
stack_pop: StackPopCleanup,
) -> InterpResult<'tcx>
pub fn init_stack_frame( &mut self, instance: Instance<'tcx>, body: &'tcx Body<'tcx>, caller_fn_abi: &FnAbi<'tcx, Ty<'tcx>>, args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, destination: &MPlaceTy<'tcx, M::Provenance>, stack_pop: StackPopCleanup, ) -> InterpResult<'tcx>
The main entry point for creating a new stack frame: performs ABI checks and initializes arguments.
sourcepub(super) fn init_fn_call(
&mut self,
fn_val: FnVal<'tcx, M::ExtraFnVal>,
(caller_abi, caller_fn_abi): (Abi, &FnAbi<'tcx, Ty<'tcx>>),
args: &[FnArg<'tcx, M::Provenance>],
with_caller_location: bool,
destination: &MPlaceTy<'tcx, M::Provenance>,
target: Option<BasicBlock>,
unwind: UnwindAction,
) -> InterpResult<'tcx>
pub(super) fn init_fn_call( &mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>, (caller_abi, caller_fn_abi): (Abi, &FnAbi<'tcx, Ty<'tcx>>), args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, destination: &MPlaceTy<'tcx, M::Provenance>, target: Option<BasicBlock>, unwind: UnwindAction, ) -> InterpResult<'tcx>
Initiate a call to this function – pushing the stack frame and initializing the arguments.
caller_fn_abi
is used to determine if all the arguments are passed the proper way.
However, we also need caller_abi
to determine if we need to do untupling of arguments.
with_caller_location
indicates whether the caller passed a caller location. Miri
implements caller locations without argument passing, but to match FnAbi
we need to know
when those arguments are present.
sourcepub(super) fn init_fn_tail_call(
&mut self,
fn_val: FnVal<'tcx, M::ExtraFnVal>,
(caller_abi, caller_fn_abi): (Abi, &FnAbi<'tcx, Ty<'tcx>>),
args: &[FnArg<'tcx, M::Provenance>],
with_caller_location: bool,
) -> InterpResult<'tcx>
pub(super) fn init_fn_tail_call( &mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>, (caller_abi, caller_fn_abi): (Abi, &FnAbi<'tcx, Ty<'tcx>>), args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, ) -> InterpResult<'tcx>
Initiate a tail call to this function – popping the current stack frame, pushing the new stack frame and initializing the arguments.
pub(super) fn init_drop_in_place_call( &mut self, place: &PlaceTy<'tcx, M::Provenance>, instance: Instance<'tcx>, target: BasicBlock, unwind: UnwindAction, ) -> InterpResult<'tcx>
sourcepub(super) fn return_from_current_stack_frame(
&mut self,
unwinding: bool,
) -> InterpResult<'tcx>
pub(super) fn return_from_current_stack_frame( &mut self, unwinding: bool, ) -> InterpResult<'tcx>
Pops the current frame from the stack, copies the return value to the caller, deallocates the memory for allocated locals, and jumps to an appropriate place.
If unwinding
is false
, then we are performing a normal return
from a function. In this case, we jump back into the frame of the caller,
and continue execution as normal.
If unwinding
is true
, then we are in the middle of a panic,
and need to unwind this frame. In this case, we jump to the
cleanup
block for the function, which is responsible for running
Drop
impls for any locals that have been initialized at this point.
The cleanup block ends with a special Resume
terminator, which will
cause us to continue unwinding.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
pub fn cast( &mut self, src: &OpTy<'tcx, M::Provenance>, cast_kind: CastKind, cast_ty: Ty<'tcx>, dest: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
sourcepub fn int_to_int_or_float(
&self,
src: &ImmTy<'tcx, M::Provenance>,
cast_to: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn int_to_int_or_float( &self, src: &ImmTy<'tcx, M::Provenance>, cast_to: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Handles ‘IntToInt’ and ‘IntToFloat’ casts.
sourcepub fn float_to_float_or_int(
&self,
src: &ImmTy<'tcx, M::Provenance>,
cast_to: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn float_to_float_or_int( &self, src: &ImmTy<'tcx, M::Provenance>, cast_to: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Handles ‘FloatToFloat’ and ‘FloatToInt’ casts.
sourcepub fn ptr_to_ptr(
&self,
src: &ImmTy<'tcx, M::Provenance>,
cast_to: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn ptr_to_ptr( &self, src: &ImmTy<'tcx, M::Provenance>, cast_to: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Handles ‘FnPtrToPtr’ and ‘PtrToPtr’ casts.
pub fn pointer_expose_provenance_cast( &mut self, src: &ImmTy<'tcx, M::Provenance>, cast_to: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn pointer_with_exposed_provenance_cast( &self, src: &ImmTy<'tcx, M::Provenance>, cast_to: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
sourcefn cast_from_int_like(
&self,
scalar: Scalar<M::Provenance>,
src_layout: TyAndLayout<'tcx>,
cast_ty: Ty<'tcx>,
) -> InterpResult<'tcx, Scalar<M::Provenance>>
fn cast_from_int_like( &self, scalar: Scalar<M::Provenance>, src_layout: TyAndLayout<'tcx>, cast_ty: Ty<'tcx>, ) -> InterpResult<'tcx, Scalar<M::Provenance>>
Low-level cast helper function. This works directly on scalars and can take ‘int-like’ input type (basically everything with a scalar layout) to int/float/char types.
sourcefn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::Provenance>where
F: Float + Into<Scalar<M::Provenance>> + FloatConvert<Half> + FloatConvert<Single> + FloatConvert<Double> + FloatConvert<Quad>,
fn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::Provenance>where
F: Float + Into<Scalar<M::Provenance>> + FloatConvert<Half> + FloatConvert<Single> + FloatConvert<Double> + FloatConvert<Quad>,
Low-level cast helper function. Converts an apfloat f
into int or float types.
sourcefn unsize_into_ptr(
&mut self,
src: &OpTy<'tcx, M::Provenance>,
dest: &PlaceTy<'tcx, M::Provenance>,
source_ty: Ty<'tcx>,
cast_ty: Ty<'tcx>,
) -> InterpResult<'tcx>
fn unsize_into_ptr( &mut self, src: &OpTy<'tcx, M::Provenance>, dest: &PlaceTy<'tcx, M::Provenance>, source_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, ) -> InterpResult<'tcx>
src
is a pointer to a source_ty
, and in dest
we should store a pointer to th same
data at type cast_ty
.
pub fn unsize_into( &mut self, src: &OpTy<'tcx, M::Provenance>, cast_ty: TyAndLayout<'tcx>, dest: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn write_discriminant(
&mut self,
variant_index: VariantIdx,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn write_discriminant( &mut self, variant_index: VariantIdx, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Writes the discriminant of the given variant.
If the variant is uninhabited, this is UB.
sourcepub fn read_discriminant(
&self,
op: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, VariantIdx>
pub fn read_discriminant( &self, op: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, VariantIdx>
Read discriminant, return the runtime value as well as the variant index. Can also legally be called on non-enums (e.g. through the discriminant_value intrinsic)!
Will never return an uninhabited variant.
pub fn discriminant_for_variant( &self, ty: Ty<'tcx>, variant: VariantIdx, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
sourcepub(crate) fn tag_for_variant(
&self,
ty: Ty<'tcx>,
variant_index: VariantIdx,
) -> InterpResult<'tcx, Option<(ScalarInt, usize)>>
pub(crate) fn tag_for_variant( &self, ty: Ty<'tcx>, variant_index: VariantIdx, ) -> InterpResult<'tcx, Option<(ScalarInt, usize)>>
Computes how to write the tag of a given variant of enum ty
:
None
means that nothing needs to be done as the variant is encoded implicitlySome((val, field_idx))
means that the given integer value needs to be stored at the given field index.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
pub fn new( tcx: TyCtxt<'tcx>, root_span: Span, param_env: ParamEnv<'tcx>, machine: M, ) -> Self
sourcepub fn cur_span(&self) -> Span
pub fn cur_span(&self) -> Span
Returns the span of the currently executed statement/terminator. This is the span typically used for error reporting.
pub(crate) fn stack(&self) -> &[Frame<'tcx, M::Provenance, M::FrameExtra>]
pub(crate) fn stack_mut( &mut self, ) -> &mut Vec<Frame<'tcx, M::Provenance, M::FrameExtra>>
pub fn frame_idx(&self) -> usize
pub fn frame(&self) -> &Frame<'tcx, M::Provenance, M::FrameExtra>
pub fn frame_mut(&mut self) -> &mut Frame<'tcx, M::Provenance, M::FrameExtra>
pub fn body(&self) -> &'tcx Body<'tcx>
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool
pub fn load_mir( &self, instance: InstanceKind<'tcx>, promoted: Option<Promoted>, ) -> InterpResult<'tcx, &'tcx Body<'tcx>>
sourcepub(super) fn instantiate_from_current_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>(
&self,
value: T,
) -> Result<T, ErrorHandled>
pub(super) fn instantiate_from_current_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>( &self, value: T, ) -> Result<T, ErrorHandled>
Call this on things you got out of the MIR (so it is as generic as the current stack frame), to bring it into the proper environment for this interpreter.
sourcepub(super) fn instantiate_from_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>(
&self,
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
value: T,
) -> Result<T, ErrorHandled>
pub(super) fn instantiate_from_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>( &self, frame: &Frame<'tcx, M::Provenance, M::FrameExtra>, value: T, ) -> Result<T, ErrorHandled>
Call this on things you got out of the MIR (so it is as generic as the provided stack frame), to bring it into the proper environment for this interpreter.
sourcepub(super) fn resolve(
&self,
def: DefId,
args: GenericArgsRef<'tcx>,
) -> InterpResult<'tcx, Instance<'tcx>>
pub(super) fn resolve( &self, def: DefId, args: GenericArgsRef<'tcx>, ) -> InterpResult<'tcx, Instance<'tcx>>
The args
are assumed to already be in our interpreter “universe” (param_env).
sourcepub(super) fn eq_in_param_env<T>(&self, a: T, b: T) -> bool
pub(super) fn eq_in_param_env<T>(&self, a: T, b: T) -> bool
Check if the two things are equal in the current param_env, using an infctx to get proper equality checks.
sourcepub(crate) fn find_closest_untracked_caller_location(&self) -> Span
pub(crate) fn find_closest_untracked_caller_location(&self) -> Span
Walks up the callstack from the intrinsic’s callsite, searching for the first callsite in a
frame which is not #[track_caller]
. This matches the caller_location
intrinsic,
and is primarily intended for the panic machinery.
sourcepub(super) fn size_and_align_of(
&self,
metadata: &MemPlaceMeta<M::Provenance>,
layout: &TyAndLayout<'tcx>,
) -> InterpResult<'tcx, Option<(Size, Align)>>
pub(super) fn size_and_align_of( &self, metadata: &MemPlaceMeta<M::Provenance>, layout: &TyAndLayout<'tcx>, ) -> InterpResult<'tcx, Option<(Size, Align)>>
Returns the actual dynamic size and alignment of the place at the given type. Only the “meta” (metadata) part of the place matters. This can fail to provide an answer for extern types.
pub fn size_and_align_of_mplace( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Option<(Size, Align)>>
sourcepub fn go_to_block(&mut self, target: BasicBlock)
pub fn go_to_block(&mut self, target: BasicBlock)
Jump to the given block.
sourcepub fn return_to_block(
&mut self,
target: Option<BasicBlock>,
) -> InterpResult<'tcx>
pub fn return_to_block( &mut self, target: Option<BasicBlock>, ) -> InterpResult<'tcx>
Return to the given target
basic block.
Do not use for unwinding! Use unwind_to_block
instead.
If target
is None
, that indicates the function cannot return, so we raise UB.
sourcepub fn unwind_to_block(&mut self, target: UnwindAction) -> InterpResult<'tcx>
pub fn unwind_to_block(&mut self, target: UnwindAction) -> InterpResult<'tcx>
Unwind to the given target
basic block.
Do not use for returning! Use return_to_block
instead.
If target
is UnwindAction::Continue
, that indicates the function does not need cleanup
during unwinding, and we will just keep propagating that upwards.
If target
is UnwindAction::Unreachable
, that indicates the function does not allow
unwinding, and doing so is UB.
sourcepub fn ctfe_query<T>(
&self,
query: impl FnOnce(TyCtxtAt<'tcx>) -> Result<T, ErrorHandled>,
) -> Result<T, ErrorHandled>
pub fn ctfe_query<T>( &self, query: impl FnOnce(TyCtxtAt<'tcx>) -> Result<T, ErrorHandled>, ) -> Result<T, ErrorHandled>
Call a query that can return ErrorHandled
. Should be used for statics and other globals.
(mir::Const
/ty::Const
have eval
methods that can be used directly instead.)
pub fn eval_global( &self, instance: Instance<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub fn eval_mir_constant( &self, val: &Const<'tcx>, span: Span, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
pub fn dump_place( &self, place: &PlaceTy<'tcx, M::Provenance>, ) -> PlacePrinter<'_, 'tcx, M>
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>>
source§impl<'tcx, M: CompileTimeMachine<'tcx, !>> InterpCx<'tcx, M>
impl<'tcx, M: CompileTimeMachine<'tcx, !>> InterpCx<'tcx, M>
sourcepub fn intern_with_temp_alloc(
&mut self,
layout: TyAndLayout<'tcx>,
f: impl FnOnce(&mut InterpCx<'tcx, M>, &PlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, ()>,
) -> InterpResult<'tcx, AllocId>
pub fn intern_with_temp_alloc( &mut self, layout: TyAndLayout<'tcx>, f: impl FnOnce(&mut InterpCx<'tcx, M>, &PlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, ()>, ) -> InterpResult<'tcx, AllocId>
A helper function that allocates memory for the layout given and gives you access to mutate
it. Once your own mutation code is done, the backing Allocation
is removed from the
current Memory
and interned as read-only into the global memory.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn eval_intrinsic(
&mut self,
instance: Instance<'tcx>,
args: &[OpTy<'tcx, M::Provenance>],
dest: &MPlaceTy<'tcx, M::Provenance>,
ret: Option<BasicBlock>,
) -> InterpResult<'tcx, bool>
pub fn eval_intrinsic( &mut self, instance: Instance<'tcx>, args: &[OpTy<'tcx, M::Provenance>], dest: &MPlaceTy<'tcx, M::Provenance>, ret: Option<BasicBlock>, ) -> InterpResult<'tcx, bool>
Returns true
if emulation happened.
Here we implement the intrinsics that are common to all Miri instances; individual machines can add their own
intrinsic handling.
pub(super) fn eval_nondiverging_intrinsic( &mut self, intrinsic: &NonDivergingIntrinsic<'tcx>, ) -> InterpResult<'tcx>
pub fn numeric_intrinsic( &self, name: Symbol, val: Scalar<M::Provenance>, layout: TyAndLayout<'tcx>, ret_layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, Scalar<M::Provenance>>
pub fn exact_div( &mut self, a: &ImmTy<'tcx, M::Provenance>, b: &ImmTy<'tcx, M::Provenance>, dest: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
pub fn saturating_arith( &self, mir_op: BinOp, l: &ImmTy<'tcx, M::Provenance>, r: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Scalar<M::Provenance>>
sourcepub fn ptr_offset_inbounds(
&self,
ptr: Pointer<Option<M::Provenance>>,
offset_bytes: i64,
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>>
pub fn ptr_offset_inbounds( &self, ptr: Pointer<Option<M::Provenance>>, offset_bytes: i64, ) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>>
Offsets a pointer by some multiple of its type, returning an error if the pointer leaves its allocation.
sourcepub(crate) fn copy_intrinsic(
&mut self,
src: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>,
dst: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>,
count: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>,
nonoverlapping: bool,
) -> InterpResult<'tcx>
pub(crate) fn copy_intrinsic( &mut self, src: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, dst: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, count: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, nonoverlapping: bool, ) -> InterpResult<'tcx>
Copy count*size_of::<T>()
many bytes from *src
to *dst
.
sourcefn typed_swap_intrinsic(
&mut self,
left: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>,
right: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>,
) -> InterpResult<'tcx>
fn typed_swap_intrinsic( &mut self, left: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, right: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, ) -> InterpResult<'tcx>
Does a typed swap of *left
and *right
.
pub fn write_bytes_intrinsic( &mut self, dst: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, byte: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, count: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, name: &'static str, ) -> InterpResult<'tcx>
pub(crate) fn compare_bytes_intrinsic( &mut self, left: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, right: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, byte_count: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, ) -> InterpResult<'tcx, Scalar<M::Provenance>>
pub(crate) fn raw_eq_intrinsic( &mut self, lhs: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, rhs: &OpTy<'tcx, <M as Machine<'tcx>>::Provenance>, ) -> InterpResult<'tcx, Scalar<M::Provenance>>
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn global_root_pointer(
&self,
ptr: Pointer<CtfeProvenance>,
) -> InterpResult<'tcx, Pointer<M::Provenance>>
pub fn global_root_pointer( &self, ptr: Pointer<CtfeProvenance>, ) -> InterpResult<'tcx, Pointer<M::Provenance>>
Call this to turn untagged “global” pointers (obtained via tcx
) into
the machine pointer to the allocation. Must never be used
for any other pointers, nor for TLS statics.
Using the resulting pointer represents a direct access to that memory
(e.g. by directly using a static
),
as opposed to access through a pointer that was created by the program.
This function can fail only if ptr
points to an extern static
.
pub fn fn_ptr( &mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>, ) -> Pointer<M::Provenance>
pub fn allocate_ptr( &mut self, size: Size, align: Align, kind: MemoryKind<M::MemoryKind>, ) -> InterpResult<'tcx, Pointer<M::Provenance>>
pub fn allocate_bytes_ptr( &mut self, bytes: &[u8], align: Align, kind: MemoryKind<M::MemoryKind>, mutability: Mutability, ) -> InterpResult<'tcx, Pointer<M::Provenance>>
pub fn insert_allocation( &mut self, alloc: Allocation<M::Provenance, (), M::Bytes>, kind: MemoryKind<M::MemoryKind>, ) -> InterpResult<'tcx, Pointer<M::Provenance>>
pub fn reallocate_ptr( &mut self, ptr: Pointer<Option<M::Provenance>>, old_size_and_align: Option<(Size, Align)>, new_size: Size, new_align: Align, kind: MemoryKind<M::MemoryKind>, ) -> InterpResult<'tcx, Pointer<M::Provenance>>
pub fn deallocate_ptr( &mut self, ptr: Pointer<Option<M::Provenance>>, old_size_and_align: Option<(Size, Align)>, kind: MemoryKind<M::MemoryKind>, ) -> InterpResult<'tcx>
sourcefn get_ptr_access(
&self,
ptr: Pointer<Option<M::Provenance>>,
size: Size,
) -> InterpResult<'tcx, Option<(AllocId, Size, M::ProvenanceExtra)>>
fn get_ptr_access( &self, ptr: Pointer<Option<M::Provenance>>, size: Size, ) -> InterpResult<'tcx, Option<(AllocId, Size, M::ProvenanceExtra)>>
Internal helper function to determine the allocation and offset of a pointer (if any).
sourcepub fn check_ptr_access(
&self,
ptr: Pointer<Option<M::Provenance>>,
size: Size,
msg: CheckInAllocMsg,
) -> InterpResult<'tcx>
pub fn check_ptr_access( &self, ptr: Pointer<Option<M::Provenance>>, size: Size, msg: CheckInAllocMsg, ) -> InterpResult<'tcx>
Check if the given pointer points to live memory of the given size
.
The caller can control the error message for the out-of-bounds case.
sourcepub fn check_ptr_access_signed(
&self,
ptr: Pointer<Option<M::Provenance>>,
size: i64,
msg: CheckInAllocMsg,
) -> InterpResult<'tcx>
pub fn check_ptr_access_signed( &self, ptr: Pointer<Option<M::Provenance>>, size: i64, msg: CheckInAllocMsg, ) -> InterpResult<'tcx>
Check whether the given pointer points to live memory for a signed amount of bytes. A negative amounts means that the given range of memory to the left of the pointer needs to be dereferenceable.
sourcefn check_and_deref_ptr<T, R: Borrow<Self>>(
this: R,
ptr: Pointer<Option<M::Provenance>>,
size: i64,
msg: CheckInAllocMsg,
alloc_size: impl FnOnce(R, AllocId, Size, M::ProvenanceExtra) -> InterpResult<'tcx, (Size, Align, T)>,
) -> InterpResult<'tcx, Option<T>>
fn check_and_deref_ptr<T, R: Borrow<Self>>( this: R, ptr: Pointer<Option<M::Provenance>>, size: i64, msg: CheckInAllocMsg, alloc_size: impl FnOnce(R, AllocId, Size, M::ProvenanceExtra) -> InterpResult<'tcx, (Size, Align, T)>, ) -> InterpResult<'tcx, Option<T>>
Low-level helper function to check if a ptr is in-bounds and potentially return a reference to the allocation it points to. Supports both shared and mutable references, as the actual checking is offloaded to a helper closure. Supports signed sizes for checks “to the left” of a pointer.
alloc_size
will only get called for non-zero-sized accesses.
Returns None
if and only if the size is 0.
pub(super) fn check_misalign( &self, misaligned: Option<Misalignment>, msg: CheckAlignMsg, ) -> InterpResult<'tcx>
pub(super) fn is_ptr_misaligned( &self, ptr: Pointer<Option<M::Provenance>>, align: Align, ) -> Option<Misalignment>
sourcepub fn check_ptr_align(
&self,
ptr: Pointer<Option<M::Provenance>>,
align: Align,
) -> InterpResult<'tcx>
pub fn check_ptr_align( &self, ptr: Pointer<Option<M::Provenance>>, align: Align, ) -> InterpResult<'tcx>
Checks a pointer for misalignment.
The error assumes this is checking the pointer used directly for an access.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn remove_unreachable_allocs(
&mut self,
reachable_allocs: &FxHashSet<AllocId>,
)
pub fn remove_unreachable_allocs( &mut self, reachable_allocs: &FxHashSet<AllocId>, )
This function is used by Miri’s provenance GC to remove unreachable entries from the dead_alloc_map.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
Allocation accessors
sourcefn get_global_alloc(
&self,
id: AllocId,
is_write: bool,
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::Provenance, M::AllocExtra, M::Bytes>>>
fn get_global_alloc( &self, id: AllocId, is_write: bool, ) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::Provenance, M::AllocExtra, M::Bytes>>>
Helper function to obtain a global (tcx) allocation.
This attempts to return a reference to an existing allocation if
one can be found in tcx
. That, however, is only possible if tcx
and
this machine use the same pointer provenance, so it is indirected through
M::adjust_allocation
.
sourcefn get_alloc_raw(
&self,
id: AllocId,
) -> InterpResult<'tcx, &Allocation<M::Provenance, M::AllocExtra, M::Bytes>>
fn get_alloc_raw( &self, id: AllocId, ) -> InterpResult<'tcx, &Allocation<M::Provenance, M::AllocExtra, M::Bytes>>
Gives raw access to the Allocation
, without bounds or alignment checks.
The caller is responsible for calling the access hooks!
You almost certainly want to use get_ptr_alloc
/get_ptr_alloc_mut
instead.
sourcepub fn get_alloc_bytes_unchecked_raw(
&self,
id: AllocId,
) -> InterpResult<'tcx, *const u8>
pub fn get_alloc_bytes_unchecked_raw( &self, id: AllocId, ) -> InterpResult<'tcx, *const u8>
Gives raw, immutable access to the Allocation
address, without bounds or alignment checks.
The caller is responsible for calling the access hooks!
sourcepub fn get_ptr_alloc<'a>(
&'a self,
ptr: Pointer<Option<M::Provenance>>,
size: Size,
) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
pub fn get_ptr_alloc<'a>( &'a self, ptr: Pointer<Option<M::Provenance>>, size: Size, ) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
Bounds-checked but not align-checked allocation access.
sourcepub fn get_alloc_extra<'a>(
&'a self,
id: AllocId,
) -> InterpResult<'tcx, &'a M::AllocExtra>
pub fn get_alloc_extra<'a>( &'a self, id: AllocId, ) -> InterpResult<'tcx, &'a M::AllocExtra>
Return the extra
field of the given allocation.
sourcepub fn get_alloc_mutability<'a>(
&'a self,
id: AllocId,
) -> InterpResult<'tcx, Mutability>
pub fn get_alloc_mutability<'a>( &'a self, id: AllocId, ) -> InterpResult<'tcx, Mutability>
Return the mutability
field of the given allocation.
sourcefn get_alloc_raw_mut(
&mut self,
id: AllocId,
) -> InterpResult<'tcx, (&mut Allocation<M::Provenance, M::AllocExtra, M::Bytes>, &mut M)>
fn get_alloc_raw_mut( &mut self, id: AllocId, ) -> InterpResult<'tcx, (&mut Allocation<M::Provenance, M::AllocExtra, M::Bytes>, &mut M)>
Gives raw mutable access to the Allocation
, without bounds or alignment checks.
The caller is responsible for calling the access hooks!
Also returns a ptr to self.extra
so that the caller can use it in parallel with the
allocation.
sourcepub fn get_alloc_bytes_unchecked_raw_mut(
&mut self,
id: AllocId,
) -> InterpResult<'tcx, *mut u8>
pub fn get_alloc_bytes_unchecked_raw_mut( &mut self, id: AllocId, ) -> InterpResult<'tcx, *mut u8>
Gives raw, mutable access to the Allocation
address, without bounds or alignment checks.
The caller is responsible for calling the access hooks!
sourcepub fn get_ptr_alloc_mut<'a>(
&'a mut self,
ptr: Pointer<Option<M::Provenance>>,
size: Size,
) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
pub fn get_ptr_alloc_mut<'a>( &'a mut self, ptr: Pointer<Option<M::Provenance>>, size: Size, ) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
Bounds-checked but not align-checked allocation access.
sourcepub fn get_alloc_extra_mut<'a>(
&'a mut self,
id: AllocId,
) -> InterpResult<'tcx, (&'a mut M::AllocExtra, &'a mut M)>
pub fn get_alloc_extra_mut<'a>( &'a mut self, id: AllocId, ) -> InterpResult<'tcx, (&'a mut M::AllocExtra, &'a mut M)>
Return the extra
field of the given allocation.
sourcepub fn is_alloc_live(&self, id: AllocId) -> bool
pub fn is_alloc_live(&self, id: AllocId) -> bool
Check whether an allocation is live. This is faster than calling
InterpCx::get_alloc_info
if all you need to check is whether the kind is
AllocKind::Dead
because it doesn’t have to look up the type and layout of statics.
sourcepub fn get_alloc_info(&self, id: AllocId) -> (Size, Align, AllocKind)
pub fn get_alloc_info(&self, id: AllocId) -> (Size, Align, AllocKind)
Obtain the size and alignment of an allocation, even if that allocation has been deallocated.
sourcefn get_live_alloc_size_and_align(
&self,
id: AllocId,
msg: CheckInAllocMsg,
) -> InterpResult<'tcx, (Size, Align)>
fn get_live_alloc_size_and_align( &self, id: AllocId, msg: CheckInAllocMsg, ) -> InterpResult<'tcx, (Size, Align)>
Obtain the size and alignment of a live allocation.
fn get_fn_alloc(&self, id: AllocId) -> Option<FnVal<'tcx, M::ExtraFnVal>>
pub fn get_ptr_fn( &self, ptr: Pointer<Option<M::Provenance>>, ) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>>
sourcepub fn get_ptr_vtable_ty(
&self,
ptr: Pointer<Option<M::Provenance>>,
expected_trait: Option<&'tcx List<PolyExistentialPredicate<'tcx>>>,
) -> InterpResult<'tcx, Ty<'tcx>>
pub fn get_ptr_vtable_ty( &self, ptr: Pointer<Option<M::Provenance>>, expected_trait: Option<&'tcx List<PolyExistentialPredicate<'tcx>>>, ) -> InterpResult<'tcx, Ty<'tcx>>
Get the dynamic type of the given vtable pointer.
If expected_trait
is Some
, it must be a vtable for the given trait.
pub fn alloc_mark_immutable(&mut self, id: AllocId) -> InterpResult<'tcx>
sourcepub fn dump_alloc<'a>(&'a self, id: AllocId) -> DumpAllocs<'a, 'tcx, M>
pub fn dump_alloc<'a>(&'a self, id: AllocId) -> DumpAllocs<'a, 'tcx, M>
Create a lazy debug printer that prints the given allocation and all allocations it points to, recursively.
sourcepub fn dump_allocs<'a>(
&'a self,
allocs: Vec<AllocId>,
) -> DumpAllocs<'a, 'tcx, M>
pub fn dump_allocs<'a>( &'a self, allocs: Vec<AllocId>, ) -> DumpAllocs<'a, 'tcx, M>
Create a lazy debug printer for a list of allocations and all allocations they point to, recursively.
sourcepub fn print_alloc_bytes_for_diagnostics(&self, id: AllocId) -> String
pub fn print_alloc_bytes_for_diagnostics(&self, id: AllocId) -> String
Print the allocation’s bytes, without any nested allocations.
sourcepub fn find_leaked_allocations(
&self,
static_roots: &[AllocId],
) -> Vec<(AllocId, MemoryKind<M::MemoryKind>, Allocation<M::Provenance, M::AllocExtra, M::Bytes>)>
pub fn find_leaked_allocations( &self, static_roots: &[AllocId], ) -> Vec<(AllocId, MemoryKind<M::MemoryKind>, Allocation<M::Provenance, M::AllocExtra, M::Bytes>)>
Find leaked allocations. Allocations reachable from static_roots
or a Global
allocation
are not considered leaked, as well as leaks whose kind’s may_leak()
returns true.
sourcepub fn run_for_validation<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R
pub fn run_for_validation<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R
Runs the closure in “validation” mode, which means the machine’s memory read hooks will be suppressed. Needless to say, this must only be set with great care! Cannot be nested.
We do this so Miri’s allocation access tracking does not show the validation reads as spurious accesses.
pub(super) fn validation_in_progress(&self) -> bool
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn read_bytes_ptr_strip_provenance(
&self,
ptr: Pointer<Option<M::Provenance>>,
size: Size,
) -> InterpResult<'tcx, &[u8]>
pub fn read_bytes_ptr_strip_provenance( &self, ptr: Pointer<Option<M::Provenance>>, size: Size, ) -> InterpResult<'tcx, &[u8]>
Reads the given number of bytes from memory, and strips their provenance if possible. Returns them as a slice.
Performs appropriate bounds checks.
sourcepub fn write_bytes_ptr(
&mut self,
ptr: Pointer<Option<M::Provenance>>,
src: impl IntoIterator<Item = u8>,
) -> InterpResult<'tcx>
pub fn write_bytes_ptr( &mut self, ptr: Pointer<Option<M::Provenance>>, src: impl IntoIterator<Item = u8>, ) -> InterpResult<'tcx>
Writes the given stream of bytes into memory.
Performs appropriate bounds checks.
pub fn mem_copy( &mut self, src: Pointer<Option<M::Provenance>>, dest: Pointer<Option<M::Provenance>>, size: Size, nonoverlapping: bool, ) -> InterpResult<'tcx>
sourcepub fn mem_copy_repeatedly(
&mut self,
src: Pointer<Option<M::Provenance>>,
dest: Pointer<Option<M::Provenance>>,
size: Size,
num_copies: u64,
nonoverlapping: bool,
) -> InterpResult<'tcx>
pub fn mem_copy_repeatedly( &mut self, src: Pointer<Option<M::Provenance>>, dest: Pointer<Option<M::Provenance>>, size: Size, num_copies: u64, nonoverlapping: bool, ) -> InterpResult<'tcx>
Performs num_copies
many copies of size
many bytes from src
to dest + i*size
(where
i
is the index of the copy).
Either nonoverlapping
must be true or num_copies
must be 1; doing repeated copies that
may overlap is not supported.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
Machine pointer introspection.
sourcepub fn scalar_may_be_null(
&self,
scalar: Scalar<M::Provenance>,
) -> InterpResult<'tcx, bool>
pub fn scalar_may_be_null( &self, scalar: Scalar<M::Provenance>, ) -> InterpResult<'tcx, bool>
Test if this value might be null. If the machine does not support ptr-to-int casts, this is conservative.
sourcepub fn ptr_try_get_alloc_id(
&self,
ptr: Pointer<Option<M::Provenance>>,
size: i64,
) -> Result<(AllocId, Size, M::ProvenanceExtra), u64>
pub fn ptr_try_get_alloc_id( &self, ptr: Pointer<Option<M::Provenance>>, size: i64, ) -> Result<(AllocId, Size, M::ProvenanceExtra), u64>
Turning a “maybe pointer” into a proper pointer (and some information about where it points), or an absolute address.
size
says how many bytes of memory are expected at that pointer. This is largely only used
for error messages; however, the sign of size
can be used to disambiguate situations
where a wildcard pointer sits right in between two allocations.
It is almost always okay to just set the size to 0; this will be treated like a positive size
for handling wildcard pointers.
The result must be used immediately; it is not allowed to convert
the returned data back into a Pointer
and store that in machine state.
(In fact that’s not even possible since M::ProvenanceExtra
is generic and
we don’t have an operation to turn it back into M::Provenance
.)
sourcepub fn ptr_get_alloc_id(
&self,
ptr: Pointer<Option<M::Provenance>>,
size: i64,
) -> InterpResult<'tcx, (AllocId, Size, M::ProvenanceExtra)>
pub fn ptr_get_alloc_id( &self, ptr: Pointer<Option<M::Provenance>>, size: i64, ) -> InterpResult<'tcx, (AllocId, Size, M::ProvenanceExtra)>
Turning a “maybe pointer” into a proper pointer (and some information about where it points).
size
says how many bytes of memory are expected at that pointer. This is largely only used
for error messages; however, the sign of size
can be used to disambiguate situations
where a wildcard pointer sits right in between two allocations.
It is almost always okay to just set the size to 0; this will be treated like a positive size
for handling wildcard pointers.
The result must be used immediately; it is not allowed to convert
the returned data back into a Pointer
and store that in machine state.
(In fact that’s not even possible since M::ProvenanceExtra
is generic and
we don’t have an operation to turn it back into M::Provenance
.)
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcefn read_immediate_from_mplace_raw(
&self,
mplace: &MPlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Option<ImmTy<'tcx, M::Provenance>>>
fn read_immediate_from_mplace_raw( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Option<ImmTy<'tcx, M::Provenance>>>
Try reading an immediate in memory; this is interesting particularly for ScalarPair
.
Returns None
if the layout does not permit loading this as a value.
This is an internal function; call read_immediate
instead.
sourcepub fn read_immediate_raw(
&self,
src: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, ImmTy<'tcx, M::Provenance>>>
pub fn read_immediate_raw( &self, src: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, ImmTy<'tcx, M::Provenance>>>
Try returning an immediate for the operand. If the layout does not permit loading this as an
immediate, return where in memory we can find the data.
Note that for a given layout, this operation will either always return Left or Right!
succeed! Whether it returns Left depends on whether the layout can be represented
in an Immediate
, not on which data is stored there currently.
This is an internal function that should not usually be used; call read_immediate
instead.
ConstProp needs it, though.
sourcepub fn read_immediate(
&self,
op: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn read_immediate( &self, op: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Read an immediate from a place, asserting that that is possible with the given layout.
If this succeeds, the ImmTy
is never Uninit
.
sourcepub fn read_scalar(
&self,
op: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Scalar<M::Provenance>>
pub fn read_scalar( &self, op: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Scalar<M::Provenance>>
Read a scalar from a place
sourcepub fn read_pointer(
&self,
op: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>>
pub fn read_pointer( &self, op: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>>
Read a pointer from a place.
sourcepub fn read_target_usize(
&self,
op: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, u64>
pub fn read_target_usize( &self, op: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, u64>
Read a pointer-sized unsigned integer from a place.
sourcepub fn read_target_isize(
&self,
op: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, i64>
pub fn read_target_isize( &self, op: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, i64>
Read a pointer-sized signed integer from a place.
sourcepub fn read_str(
&self,
mplace: &MPlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, &str>
pub fn read_str( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, &str>
Turn the wide MPlace into a string (must already be dereferenced!)
sourcepub fn local_to_op(
&self,
local: Local,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
pub fn local_to_op( &self, local: Local, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
Read from a local of the current frame.
Will not access memory, instead an indirect Operand
is returned.
This is public because it is used by priroda to get an OpTy from a local.
sourcepub fn place_to_op(
&self,
place: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
pub fn place_to_op( &self, place: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
Every place can be read from, so we can turn them into an operand.
This will definitely return Indirect
if the place is a Ptr
, i.e., this
will never actually read from memory.
sourcepub fn eval_place_to_op(
&self,
mir_place: Place<'tcx>,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
pub fn eval_place_to_op( &self, mir_place: Place<'tcx>, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
Evaluate a place with the goal of reading from it. This lets us sometimes avoid allocations.
sourcepub fn eval_operand(
&self,
mir_op: &Operand<'tcx>,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
pub fn eval_operand( &self, mir_op: &Operand<'tcx>, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
Evaluate the operand, returning a place where you can then find the data. If you already know the layout, you can save two table lookups by passing it in here.
pub(crate) fn const_val_to_op( &self, val_val: ConstValue<'tcx>, ty: Ty<'tcx>, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>>
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
fn three_way_compare<T: Ord>( &self, lhs: T, rhs: T, ) -> ImmTy<'tcx, M::Provenance>
fn binary_char_op( &self, bin_op: BinOp, l: char, r: char, ) -> ImmTy<'tcx, M::Provenance>
fn binary_bool_op( &self, bin_op: BinOp, l: bool, r: bool, ) -> ImmTy<'tcx, M::Provenance>
fn binary_float_op<F: Float + FloatConvert<F> + Into<Scalar<M::Provenance>>>( &self, bin_op: BinOp, layout: TyAndLayout<'tcx>, l: F, r: F, ) -> ImmTy<'tcx, M::Provenance>
fn binary_int_op( &self, bin_op: BinOp, left: &ImmTy<'tcx, M::Provenance>, right: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
sourcepub fn compute_size_in_bytes(&self, elem_size: Size, count: u64) -> Option<Size>
pub fn compute_size_in_bytes(&self, elem_size: Size, count: u64) -> Option<Size>
Computes the total size of this access, count * elem_size
,
checking for overflow beyond isize::MAX.
fn binary_ptr_op( &self, bin_op: BinOp, left: &ImmTy<'tcx, M::Provenance>, right: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
sourcepub fn binary_op(
&self,
bin_op: BinOp,
left: &ImmTy<'tcx, M::Provenance>,
right: &ImmTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn binary_op( &self, bin_op: BinOp, left: &ImmTy<'tcx, M::Provenance>, right: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Returns the result of the specified operation.
Whether this produces a scalar or a pair depends on the specific bin_op
.
sourcepub fn unary_op(
&self,
un_op: UnOp,
val: &ImmTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn unary_op( &self, un_op: UnOp, val: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Returns the result of the specified operation, whether it overflowed, and the result type.
pub fn nullary_op( &self, null_op: NullOp<'tcx>, arg_ty: Ty<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
source§impl<'tcx, Prov, M> InterpCx<'tcx, M>where
Prov: Provenance,
M: Machine<'tcx, Provenance = Prov>,
impl<'tcx, Prov, M> InterpCx<'tcx, M>where
Prov: Provenance,
M: Machine<'tcx, Provenance = Prov>,
fn ptr_with_meta_to_mplace( &self, ptr: Pointer<Option<M::Provenance>>, meta: MemPlaceMeta<M::Provenance>, layout: TyAndLayout<'tcx>, unaligned: bool, ) -> MPlaceTy<'tcx, M::Provenance>
pub fn ptr_to_mplace( &self, ptr: Pointer<Option<M::Provenance>>, layout: TyAndLayout<'tcx>, ) -> MPlaceTy<'tcx, M::Provenance>
pub fn ptr_to_mplace_unaligned( &self, ptr: Pointer<Option<M::Provenance>>, layout: TyAndLayout<'tcx>, ) -> MPlaceTy<'tcx, M::Provenance>
sourcepub fn ref_to_mplace(
&self,
val: &ImmTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub fn ref_to_mplace( &self, val: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
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 mplace_to_ref()
.
Only call this if you are sure the place is “valid” (aligned and inbounds), or do not
want to ever use the place for memory access!
Generally prefer deref_pointer
.
sourcepub fn mplace_to_ref(
&self,
mplace: &MPlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
pub fn mplace_to_ref( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>>
Turn a mplace into a (thin or wide) mutable raw pointer, pointing to the same space.
align
information is lost!
This is the inverse of ref_to_mplace
.
sourcepub fn deref_pointer(
&self,
src: &impl Projectable<'tcx, M::Provenance>,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub fn deref_pointer( &self, src: &impl Projectable<'tcx, M::Provenance>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
Take an operand, representing a pointer, and dereference it to a place.
Corresponds to the *
operator in Rust.
pub(super) fn get_place_alloc( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
pub(super) fn get_place_alloc_mut( &mut self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
sourcepub fn local_to_place(
&self,
local: Local,
) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>>
pub fn local_to_place( &self, local: Local, ) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>>
Turn a local in the current frame into a place.
sourcepub fn eval_place(
&self,
mir_place: Place<'tcx>,
) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>>
pub fn eval_place( &self, mir_place: Place<'tcx>, ) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>>
Computes a place. You should only use this if you intend to write into this
place; for reading, a more efficient alternative is eval_place_to_op
.
sourcefn as_mplace_or_mutable_local(
&mut self,
place: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, (&mut Immediate<M::Provenance>, TyAndLayout<'tcx>, Local)>>
fn as_mplace_or_mutable_local( &mut self, place: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, (&mut Immediate<M::Provenance>, TyAndLayout<'tcx>, Local)>>
Given a place, returns either the underlying mplace or a reference to where the value of this place is stored.
sourcepub fn write_immediate(
&mut self,
src: Immediate<M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn write_immediate( &mut self, src: Immediate<M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Write an immediate to a place
sourcepub fn write_scalar(
&mut self,
val: impl Into<Scalar<M::Provenance>>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn write_scalar( &mut self, val: impl Into<Scalar<M::Provenance>>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Write a scalar to a place
sourcepub fn write_pointer(
&mut self,
ptr: impl Into<Pointer<Option<M::Provenance>>>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn write_pointer( &mut self, ptr: impl Into<Pointer<Option<M::Provenance>>>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Write a pointer to a place
sourcepub(super) fn write_immediate_no_validate(
&mut self,
src: Immediate<M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub(super) fn write_immediate_no_validate( &mut self, src: Immediate<M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Write an immediate to a place. If you use this you are responsible for validating that things got copied at the right type.
sourcefn write_immediate_to_mplace_no_validate(
&mut self,
value: Immediate<M::Provenance>,
layout: TyAndLayout<'tcx>,
dest: MemPlace<M::Provenance>,
) -> InterpResult<'tcx>
fn write_immediate_to_mplace_no_validate( &mut self, value: Immediate<M::Provenance>, layout: TyAndLayout<'tcx>, dest: MemPlace<M::Provenance>, ) -> InterpResult<'tcx>
Write an immediate to memory. If you use this you are responsible for validating that things got copied at the right layout.
pub fn write_uninit( &mut self, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
sourcepub fn clear_provenance(
&mut self,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn clear_provenance( &mut self, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Remove all provenance in the given place.
sourcepub(super) fn copy_op_no_dest_validation(
&mut self,
src: &impl Projectable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub(super) fn copy_op_no_dest_validation( &mut self, src: &impl Projectable<'tcx, M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Copies the data from an operand to a place.
The layouts of the src
and dest
may disagree.
Does not perform validation of the destination.
The only known use case for this function is checking the return
value of a static during stack frame popping.
sourcepub fn copy_op_allow_transmute(
&mut self,
src: &impl Projectable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn copy_op_allow_transmute( &mut self, src: &impl Projectable<'tcx, M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Copies the data from an operand to a place.
The layouts of the src
and dest
may disagree.
sourcepub fn copy_op(
&mut self,
src: &impl Projectable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
pub fn copy_op( &mut self, src: &impl Projectable<'tcx, M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Copies the data from an operand to a place.
src
and dest
must have the same layout and the copied value will be validated.
sourcefn copy_op_inner(
&mut self,
src: &impl Projectable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
allow_transmute: bool,
validate_dest: bool,
) -> InterpResult<'tcx>
fn copy_op_inner( &mut self, src: &impl Projectable<'tcx, M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, allow_transmute: bool, validate_dest: bool, ) -> InterpResult<'tcx>
Copies the data from an operand to a place.
allow_transmute
indicates whether the layouts may disagree.
sourcefn copy_op_no_validate(
&mut self,
src: &impl Projectable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
allow_transmute: bool,
) -> InterpResult<'tcx>
fn copy_op_no_validate( &mut self, src: &impl Projectable<'tcx, M::Provenance>, dest: &impl Writeable<'tcx, M::Provenance>, allow_transmute: bool, ) -> InterpResult<'tcx>
Copies the data from an operand to a place.
allow_transmute
indicates whether the layouts may disagree.
Also, if you use this you are responsible for validating that things get copied at the
right type.
sourcepub fn force_allocation(
&mut self,
place: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub fn force_allocation( &mut self, place: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
Ensures that a place is in memory, and returns where it is.
If the place currently refers to a local that doesn’t yet have a matching allocation,
create such an allocation.
This is essentially force_to_memplace
.
pub fn allocate_dyn( &mut self, layout: TyAndLayout<'tcx>, kind: MemoryKind<M::MemoryKind>, meta: MemPlaceMeta<M::Provenance>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub fn allocate( &mut self, layout: TyAndLayout<'tcx>, kind: MemoryKind<M::MemoryKind>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
sourcepub fn allocate_str(
&mut self,
str: &str,
kind: MemoryKind<M::MemoryKind>,
mutbl: Mutability,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub fn allocate_str( &mut self, str: &str, kind: MemoryKind<M::MemoryKind>, mutbl: Mutability, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
Returns a wide MPlace of type str
to a new 1-aligned allocation.
Immutable strings are deduplicated and stored in global memory.
pub fn raw_const_to_mplace( &self, raw: ConstAlloc<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
source§impl<'tcx, Prov, M> InterpCx<'tcx, M>where
Prov: Provenance,
M: Machine<'tcx, Provenance = Prov>,
impl<'tcx, Prov, M> InterpCx<'tcx, M>where
Prov: Provenance,
M: Machine<'tcx, Provenance = Prov>,
sourcepub fn project_field<P: Projectable<'tcx, M::Provenance>>(
&self,
base: &P,
field: usize,
) -> InterpResult<'tcx, P>
pub fn project_field<P: Projectable<'tcx, M::Provenance>>( &self, base: &P, field: usize, ) -> InterpResult<'tcx, P>
Offset a pointer to project to a field of a struct/union. Unlike place_field
, this is
always possible without allocating, so it can take &self
. Also return the field’s layout.
This supports both struct and array fields, but not slices!
This also works for arrays, but then the usize
index type is restricting.
For indexing into arrays, use mplace_index
.
sourcepub fn project_downcast<P: Projectable<'tcx, M::Provenance>>(
&self,
base: &P,
variant: VariantIdx,
) -> InterpResult<'tcx, P>
pub fn project_downcast<P: Projectable<'tcx, M::Provenance>>( &self, base: &P, variant: VariantIdx, ) -> InterpResult<'tcx, P>
Downcasting to an enum variant.
sourcepub fn project_index<P: Projectable<'tcx, M::Provenance>>(
&self,
base: &P,
index: u64,
) -> InterpResult<'tcx, P>
pub fn project_index<P: Projectable<'tcx, M::Provenance>>( &self, base: &P, index: u64, ) -> InterpResult<'tcx, P>
Compute the offset and field layout for accessing the given index.
sourcepub fn project_to_simd<P: Projectable<'tcx, M::Provenance>>(
&self,
base: &P,
) -> InterpResult<'tcx, (P, u64)>
pub fn project_to_simd<P: Projectable<'tcx, M::Provenance>>( &self, base: &P, ) -> InterpResult<'tcx, (P, u64)>
Converts a repr(simd) value into an array of the right size, such that project_index
accesses the SIMD elements. Also returns the number of elements.
fn project_constant_index<P: Projectable<'tcx, M::Provenance>>( &self, base: &P, offset: u64, min_length: u64, from_end: bool, ) -> InterpResult<'tcx, P>
sourcepub fn project_array_fields<'a, P: Projectable<'tcx, M::Provenance>>(
&self,
base: &'a P,
) -> InterpResult<'tcx, ArrayIterator<'a, 'tcx, M::Provenance, P>>
pub fn project_array_fields<'a, P: Projectable<'tcx, M::Provenance>>( &self, base: &'a P, ) -> InterpResult<'tcx, ArrayIterator<'a, 'tcx, M::Provenance, P>>
Iterates over all fields of an array. Much more efficient than doing the
same by repeatedly calling project_index
.
sourcefn project_subslice<P: Projectable<'tcx, M::Provenance>>(
&self,
base: &P,
from: u64,
to: u64,
from_end: bool,
) -> InterpResult<'tcx, P>
fn project_subslice<P: Projectable<'tcx, M::Provenance>>( &self, base: &P, from: u64, to: u64, from_end: bool, ) -> InterpResult<'tcx, P>
Subslicing
sourcepub fn project<P>(
&self,
base: &P,
proj_elem: PlaceElem<'tcx>,
) -> InterpResult<'tcx, P>
pub fn project<P>( &self, base: &P, proj_elem: PlaceElem<'tcx>, ) -> InterpResult<'tcx, P>
Applying a general projection
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub(crate) fn push_stack_frame_raw(
&mut self,
instance: Instance<'tcx>,
body: &'tcx Body<'tcx>,
return_place: &MPlaceTy<'tcx, M::Provenance>,
return_to_block: StackPopCleanup,
) -> InterpResult<'tcx>
pub(crate) fn push_stack_frame_raw( &mut self, instance: Instance<'tcx>, body: &'tcx Body<'tcx>, return_place: &MPlaceTy<'tcx, M::Provenance>, return_to_block: StackPopCleanup, ) -> InterpResult<'tcx>
Very low-level helper that pushes a stack frame without initializing the arguments or local variables.
The high-level version of this is init_stack_frame
.
sourcepub(super) fn pop_stack_frame_raw(
&mut self,
unwinding: bool,
) -> InterpResult<'tcx, StackPopInfo<'tcx, M::Provenance>>
pub(super) fn pop_stack_frame_raw( &mut self, unwinding: bool, ) -> InterpResult<'tcx, StackPopInfo<'tcx, M::Provenance>>
Low-level helper that pops a stack frame from the stack and returns some information about it.
This also deallocates locals, if necessary.
M::before_stack_pop
should be called before calling this function.
M::after_stack_pop
is called by this function automatically.
The high-level version of this is return_from_current_stack_frame
.
sourcefn cleanup_current_frame_locals(&mut self) -> InterpResult<'tcx, bool>
fn cleanup_current_frame_locals(&mut self) -> InterpResult<'tcx, bool>
A private helper for pop_stack_frame_raw
.
Returns true
if cleanup has been done, false
otherwise.
sourcepub(crate) fn storage_live_for_always_live_locals(
&mut self,
) -> InterpResult<'tcx>
pub(crate) fn storage_live_for_always_live_locals( &mut self, ) -> InterpResult<'tcx>
In the current stack frame, mark all locals as live that are not arguments and don’t have
Storage*
annotations (this includes the return place).
pub fn storage_live_dyn( &mut self, local: Local, meta: MemPlaceMeta<M::Provenance>, ) -> InterpResult<'tcx>
sourcepub fn storage_live(&mut self, local: Local) -> InterpResult<'tcx>
pub fn storage_live(&mut self, local: Local) -> InterpResult<'tcx>
Mark a storage as live, killing the previous content.
pub fn storage_dead(&mut self, local: Local) -> InterpResult<'tcx>
fn deallocate_local( &mut self, local: LocalValue<M::Provenance>, ) -> InterpResult<'tcx>
pub(super) fn layout_of_local( &self, frame: &Frame<'tcx, M::Provenance, M::FrameExtra>, local: Local, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, TyAndLayout<'tcx>>
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn step(&mut self) -> InterpResult<'tcx, bool>
pub fn step(&mut self) -> InterpResult<'tcx, bool>
Returns true
as long as there are more things to do.
This is used by priroda
This is marked #inline(always)
to work around adversarial codegen when opt-level = 3
sourcepub fn eval_statement(&mut self, stmt: &Statement<'tcx>) -> InterpResult<'tcx>
pub fn eval_statement(&mut self, stmt: &Statement<'tcx>) -> InterpResult<'tcx>
Runs the interpretation logic for the given mir::Statement
at the current frame and
statement counter.
This does NOT move the statement counter forward, the caller has to do that!
sourcepub fn eval_rvalue_into_place(
&mut self,
rvalue: &Rvalue<'tcx>,
place: Place<'tcx>,
) -> InterpResult<'tcx>
pub fn eval_rvalue_into_place( &mut self, rvalue: &Rvalue<'tcx>, place: Place<'tcx>, ) -> InterpResult<'tcx>
Evaluate an assignment statement.
There is no separate eval_rvalue
function. Instead, the code for handling each rvalue
type writes its results directly into the memory specified by the place.
sourcefn write_aggregate(
&mut self,
kind: &AggregateKind<'tcx>,
operands: &IndexSlice<FieldIdx, Operand<'tcx>>,
dest: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
fn write_aggregate( &mut self, kind: &AggregateKind<'tcx>, operands: &IndexSlice<FieldIdx, Operand<'tcx>>, dest: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Writes the aggregate to the destination.
sourcefn write_repeat(
&mut self,
operand: &Operand<'tcx>,
dest: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx>
fn write_repeat( &mut self, operand: &Operand<'tcx>, dest: &PlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx>
Repeats operand
into the destination. dest
must have array type, and that type
determines how often operand
is repeated.
sourcefn eval_fn_call_argument(
&self,
op: &Operand<'tcx>,
) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>>
fn eval_fn_call_argument( &self, op: &Operand<'tcx>, ) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>>
Evaluate the arguments of a function call
sourcefn eval_callee_and_args(
&self,
terminator: &Terminator<'tcx>,
func: &Operand<'tcx>,
args: &[Spanned<Operand<'tcx>>],
) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, M>>
fn eval_callee_and_args( &self, terminator: &Terminator<'tcx>, func: &Operand<'tcx>, args: &[Spanned<Operand<'tcx>>], ) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, M>>
Shared part of Call
and TailCall
implementation — finding and evaluating all the
necessary information about callee and arguments to make a call.
fn eval_terminator( &mut self, terminator: &Terminator<'tcx>, ) -> InterpResult<'tcx>
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
sourcepub fn get_vtable_ptr(
&self,
ty: Ty<'tcx>,
dyn_ty: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>>
pub fn get_vtable_ptr( &self, ty: Ty<'tcx>, dyn_ty: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>>
Creates a dynamic vtable for the given type and vtable origin. This is used only for objects.
The dyn_ty
encodes the erased self type. Hence, if we are making an object
Foo<dyn Trait<Assoc = A> + Send>
from a value of type Foo<T>
, then dyn_ty
would be Trait<Assoc = A> + Send
. If this list doesn’t have a principal trait ref,
we only need the basic vtable prefix (drop, size, align).
pub fn get_vtable_size_and_align( &self, vtable: Pointer<Option<M::Provenance>>, expected_trait: Option<&'tcx List<PolyExistentialPredicate<'tcx>>>, ) -> InterpResult<'tcx, (Size, Align)>
pub(super) fn vtable_entries( &self, trait_: Option<PolyExistentialTraitRef<'tcx>>, dyn_ty: Ty<'tcx>, ) -> &'tcx [VtblEntry<'tcx>]
sourcepub(super) fn check_vtable_for_type(
&self,
vtable_dyn_type: &'tcx List<PolyExistentialPredicate<'tcx>>,
expected_dyn_type: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> InterpResult<'tcx>
pub(super) fn check_vtable_for_type( &self, vtable_dyn_type: &'tcx List<PolyExistentialPredicate<'tcx>>, expected_dyn_type: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> InterpResult<'tcx>
Check that the given vtable trait is valid for a pointer/reference/place with the given expected trait type.
sourcepub(super) fn unpack_dyn_trait(
&self,
mplace: &MPlaceTy<'tcx, M::Provenance>,
expected_trait: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
pub(super) fn unpack_dyn_trait( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, expected_trait: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>>
Turn a place with a dyn Trait
type into a place with the actual dynamic type.
sourcepub(super) fn unpack_dyn_star<P: Projectable<'tcx, M::Provenance>>(
&self,
val: &P,
expected_trait: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> InterpResult<'tcx, P>
pub(super) fn unpack_dyn_star<P: Projectable<'tcx, M::Provenance>>( &self, val: &P, expected_trait: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> InterpResult<'tcx, P>
Turn a dyn* Trait
type into an value with the actual dynamic type.
source§impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M>
fn validate_operand_internal( &mut self, val: &PlaceTy<'tcx, M::Provenance>, path: Vec<PathElem>, ref_tracking: Option<&mut RefTracking<MPlaceTy<'tcx, M::Provenance>, Vec<PathElem>>>, ctfe_mode: Option<CtfeValidationMode>, reset_provenance_and_padding: bool, ) -> InterpResult<'tcx>
sourcepub(crate) fn const_validate_operand(
&mut self,
val: &PlaceTy<'tcx, M::Provenance>,
path: Vec<PathElem>,
ref_tracking: &mut RefTracking<MPlaceTy<'tcx, M::Provenance>, Vec<PathElem>>,
ctfe_mode: CtfeValidationMode,
) -> InterpResult<'tcx>
pub(crate) fn const_validate_operand( &mut self, val: &PlaceTy<'tcx, M::Provenance>, path: Vec<PathElem>, ref_tracking: &mut RefTracking<MPlaceTy<'tcx, M::Provenance>, Vec<PathElem>>, ctfe_mode: CtfeValidationMode, ) -> InterpResult<'tcx>
This function checks the data at op
to be const-valid.
op
is assumed to cover valid memory if it is an indirect operand.
It will error if the bits at the destination do not match the ones described by the layout.
ref_tracking
is used to record references that we encounter so that they
can be checked recursively by an outside driving loop.
constant
controls whether this must satisfy the rules for constants:
- no pointers to statics.
- no
UnsafeCell
or non-ZST&mut
.
sourcepub fn validate_operand(
&mut self,
val: &PlaceTy<'tcx, M::Provenance>,
recursive: bool,
reset_provenance_and_padding: bool,
) -> InterpResult<'tcx>
pub fn validate_operand( &mut self, val: &PlaceTy<'tcx, M::Provenance>, recursive: bool, reset_provenance_and_padding: bool, ) -> InterpResult<'tcx>
This function checks the data at op
to be runtime-valid.
op
is assumed to cover valid memory if it is an indirect operand.
It will error if the bits at the destination do not match the ones described by the layout.
Trait Implementations§
source§impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M>
source§type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpError<'tcx>>
type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpError<'tcx>>
&FnAbi
-wrapping type (or &FnAbi
itself), which will be
returned from fn_abi_of_*
(see also handle_fn_abi_err
).source§fn handle_fn_abi_err(
&self,
err: FnAbiError<'tcx>,
_span: Span,
_fn_abi_request: FnAbiRequest<'tcx>,
) -> InterpError<'tcx>
fn handle_fn_abi_err( &self, err: FnAbiError<'tcx>, _span: Span, _fn_abi_request: FnAbiRequest<'tcx>, ) -> InterpError<'tcx>
fn_abi_of_*
, to adapt tcx.fn_abi_of_*(...)
into a
Self::FnAbiOfResult
(which does not need to be a Result<...>
). Read moresource§impl<'tcx, M: Machine<'tcx>> HasDataLayout for InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> HasDataLayout for InterpCx<'tcx, M>
fn data_layout(&self) -> &TargetDataLayout
source§impl<'tcx, M> HasParamEnv<'tcx> for InterpCx<'tcx, M>where
M: Machine<'tcx>,
impl<'tcx, M> HasParamEnv<'tcx> for InterpCx<'tcx, M>where
M: Machine<'tcx>,
source§impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M>
impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M>
source§type LayoutOfResult = Result<TyAndLayout<'tcx, Ty<'tcx>>, InterpError<'tcx>>
type LayoutOfResult = Result<TyAndLayout<'tcx, Ty<'tcx>>, InterpError<'tcx>>
TyAndLayout
-wrapping type (or TyAndLayout
itself), which will be
returned from layout_of
(see also handle_layout_err
).source§fn layout_tcx_at_span(&self) -> Span
fn layout_tcx_at_span(&self) -> Span
Span
to use for tcx.at(span)
, from layout_of
.source§fn handle_layout_err(
&self,
err: LayoutError<'tcx>,
_: Span,
_: Ty<'tcx>,
) -> InterpError<'tcx>
fn handle_layout_err( &self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>, ) -> InterpError<'tcx>
layout_of
, to adapt tcx.layout_of(...)
into a
Self::LayoutOfResult
(which does not need to be a Result<...>
). Read moreAuto Trait Implementations§
impl<'tcx, M> DynSend for InterpCx<'tcx, M>
impl<'tcx, M> DynSync for InterpCx<'tcx, M>
impl<'tcx, M> Freeze for InterpCx<'tcx, M>
impl<'tcx, M> !RefUnwindSafe for InterpCx<'tcx, M>
impl<'tcx, M> !Send for InterpCx<'tcx, M>
impl<'tcx, M> !Sync for InterpCx<'tcx, M>
impl<'tcx, M> Unpin for InterpCx<'tcx, M>
impl<'tcx, M> !UnwindSafe for InterpCx<'tcx, M>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<'tcx, C> FnAbiOf<'tcx> for Cwhere
C: FnAbiOfHelpers<'tcx>,
impl<'tcx, C> FnAbiOf<'tcx> for Cwhere
C: FnAbiOfHelpers<'tcx>,
source§fn fn_abi_of_fn_ptr(
&self,
sig: Binder<TyCtxt<'tcx>, FnSig<TyCtxt<'tcx>>>,
extra_args: &'tcx RawList<(), Ty<'tcx>>,
) -> Self::FnAbiOfResult
fn fn_abi_of_fn_ptr( &self, sig: Binder<TyCtxt<'tcx>, FnSig<TyCtxt<'tcx>>>, extra_args: &'tcx RawList<(), Ty<'tcx>>, ) -> Self::FnAbiOfResult
source§fn fn_abi_of_instance(
&self,
instance: Instance<'tcx>,
extra_args: &'tcx RawList<(), Ty<'tcx>>,
) -> Self::FnAbiOfResult
fn fn_abi_of_instance( &self, instance: Instance<'tcx>, extra_args: &'tcx RawList<(), Ty<'tcx>>, ) -> Self::FnAbiOfResult
FnAbi
suitable for declaring/defining an fn
instance, and for
direct calls to an fn
. Read moresource§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<'tcx, C> LayoutOf<'tcx> for Cwhere
C: LayoutOfHelpers<'tcx>,
impl<'tcx, C> LayoutOf<'tcx> for Cwhere
C: LayoutOfHelpers<'tcx>,
source§fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult
fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult
source§fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::LayoutOfResult
fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::LayoutOfResult
span
. Note that this implicitly
executes in “reveal all” mode, and will normalize the input type.source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> PointerArithmetic for Twhere
T: HasDataLayout,
impl<T> PointerArithmetic for Twhere
T: HasDataLayout,
fn pointer_size(&self) -> Size
fn max_size_of_val(&self) -> Size
fn target_usize_max(&self) -> u64
fn target_isize_min(&self) -> i64
fn target_isize_max(&self) -> i64
fn truncate_to_target_usize(&self, val: u64) -> u64
fn sign_extend_to_target_isize(&self, val: u64) -> i64
source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.