1
Fork 0

rename InterpretCx -> InterpCx

That's more consistent with InterpResult and InterpError.
This commit is contained in:
Ralf Jung 2019-06-27 11:36:01 +02:00
parent d3e2cec292
commit fc918a395a
16 changed files with 71 additions and 71 deletions

View file

@ -178,7 +178,7 @@ pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'
/// up with a Rust-level backtrace of where the error occured. /// up with a Rust-level backtrace of where the error occured.
/// Thsese should always be constructed by calling `.into()` on /// Thsese should always be constructed by calling `.into()` on
/// a `InterpError`. In `librustc_mir::interpret`, we have the `err!` /// a `InterpError`. In `librustc_mir::interpret`, we have the `err!`
/// macro for this /// macro for this.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct InterpErrorInfo<'tcx> { pub struct InterpErrorInfo<'tcx> {
pub kind: InterpError<'tcx, u64>, pub kind: InterpError<'tcx, u64>,

View file

@ -22,7 +22,7 @@ use syntax::source_map::{Span, DUMMY_SP};
use crate::interpret::{self, use crate::interpret::{self,
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar, PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar,
RawConst, ConstValue, RawConst, ConstValue,
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpretCx, StackPopCleanup, InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpCx, StackPopCleanup,
Allocation, AllocId, MemoryKind, Memory, Allocation, AllocId, MemoryKind, Memory,
snapshot, RefTracking, intern_const_alloc_recursive, snapshot, RefTracking, intern_const_alloc_recursive,
}; };
@ -34,7 +34,7 @@ const STEPS_UNTIL_DETECTOR_ENABLED: isize = 1_000_000;
/// Should be a power of two for performance reasons. /// Should be a power of two for performance reasons.
const DETECTOR_SNAPSHOT_PERIOD: isize = 256; const DETECTOR_SNAPSHOT_PERIOD: isize = 256;
/// The `InterpretCx` is only meant to be used to do field and index projections into constants for /// The `InterpCx` is only meant to be used to do field and index projections into constants for
/// `simd_shuffle` and const patterns in match arms. /// `simd_shuffle` and const patterns in match arms.
/// ///
/// The function containing the `match` that is currently being analyzed may have generic bounds /// The function containing the `match` that is currently being analyzed may have generic bounds
@ -47,7 +47,7 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
) -> CompileTimeEvalContext<'mir, 'tcx> { ) -> CompileTimeEvalContext<'mir, 'tcx> {
debug!("mk_eval_cx: {:?}", param_env); debug!("mk_eval_cx: {:?}", param_env);
InterpretCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new()) InterpCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new())
} }
pub(crate) fn eval_promoted<'mir, 'tcx>( pub(crate) fn eval_promoted<'mir, 'tcx>(
@ -303,7 +303,7 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxHashMap<K, V> {
} }
crate type CompileTimeEvalContext<'mir, 'tcx> = crate type CompileTimeEvalContext<'mir, 'tcx> =
InterpretCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>; InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>;
impl interpret::MayLeak for ! { impl interpret::MayLeak for ! {
#[inline(always)] #[inline(always)]
@ -326,12 +326,12 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
const STATIC_KIND: Option<!> = None; // no copying of statics allowed const STATIC_KIND: Option<!> = None; // no copying of statics allowed
#[inline(always)] #[inline(always)]
fn enforce_validity(_ecx: &InterpretCx<'mir, 'tcx, Self>) -> bool { fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
false // for now, we don't enforce validity false // for now, we don't enforce validity
} }
fn find_fn( fn find_fn(
ecx: &mut InterpretCx<'mir, 'tcx, Self>, ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: ty::Instance<'tcx>, instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: Option<PlaceTy<'tcx>>, dest: Option<PlaceTy<'tcx>>,
@ -371,7 +371,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
} }
fn call_intrinsic( fn call_intrinsic(
ecx: &mut InterpretCx<'mir, 'tcx, Self>, ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: ty::Instance<'tcx>, instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: PlaceTy<'tcx>, dest: PlaceTy<'tcx>,
@ -387,7 +387,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
} }
fn ptr_op( fn ptr_op(
_ecx: &InterpretCx<'mir, 'tcx, Self>, _ecx: &InterpCx<'mir, 'tcx, Self>,
_bin_op: mir::BinOp, _bin_op: mir::BinOp,
_left: ImmTy<'tcx>, _left: ImmTy<'tcx>,
_right: ImmTy<'tcx>, _right: ImmTy<'tcx>,
@ -424,7 +424,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
} }
fn box_alloc( fn box_alloc(
_ecx: &mut InterpretCx<'mir, 'tcx, Self>, _ecx: &mut InterpCx<'mir, 'tcx, Self>,
_dest: PlaceTy<'tcx>, _dest: PlaceTy<'tcx>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
Err( Err(
@ -432,7 +432,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
) )
} }
fn before_terminator(ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { fn before_terminator(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
{ {
let steps = &mut ecx.machine.steps_since_detector_enabled; let steps = &mut ecx.machine.steps_since_detector_enabled;
@ -457,13 +457,13 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
} }
#[inline(always)] #[inline(always)]
fn stack_push(_ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
Ok(()) Ok(())
} }
/// Called immediately before a stack frame gets popped. /// Called immediately before a stack frame gets popped.
#[inline(always)] #[inline(always)]
fn stack_pop(_ecx: &mut InterpretCx<'mir, 'tcx, Self>, _extra: ()) -> InterpResult<'tcx> { fn stack_pop(_ecx: &mut InterpCx<'mir, 'tcx, Self>, _extra: ()) -> InterpResult<'tcx> {
Ok(()) Ok(())
} }
} }
@ -508,7 +508,7 @@ pub fn const_variant_index<'tcx>(
} }
pub fn error_to_const_error<'mir, 'tcx>( pub fn error_to_const_error<'mir, 'tcx>(
ecx: &InterpretCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>, ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
mut error: InterpErrorInfo<'tcx>, mut error: InterpErrorInfo<'tcx>,
) -> ConstEvalErr<'tcx> { ) -> ConstEvalErr<'tcx> {
error.print_backtrace(); error.print_backtrace();
@ -632,7 +632,7 @@ pub fn const_eval_raw_provider<'tcx>(
} }
let span = tcx.def_span(cid.instance.def_id()); let span = tcx.def_span(cid.instance.def_id());
let mut ecx = InterpretCx::new(tcx.at(span), key.param_env, CompileTimeInterpreter::new()); let mut ecx = InterpCx::new(tcx.at(span), key.param_env, CompileTimeInterpreter::new());
let res = ecx.load_mir(cid.instance.def); let res = ecx.load_mir(cid.instance.def);
res.map(|body| { res.map(|body| {

View file

@ -11,9 +11,9 @@ use rustc::mir::interpret::{
}; };
use rustc::mir::CastKind; use rustc::mir::CastKind;
use super::{InterpretCx, Machine, PlaceTy, OpTy, Immediate}; use super::{InterpCx, Machine, PlaceTy, OpTy, Immediate};
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool { fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool {
match ty.sty { match ty.sty {
ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::RawPtr(ty::TypeAndMut { ty, .. }) |

View file

@ -26,7 +26,7 @@ use super::{
Memory, Machine Memory, Machine
}; };
pub struct InterpretCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
/// Stores the `Machine` instance. /// Stores the `Machine` instance.
pub machine: M, pub machine: M,
@ -158,14 +158,14 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpCx<'mir, 'tcx, M> {
#[inline] #[inline]
fn data_layout(&self) -> &layout::TargetDataLayout { fn data_layout(&self) -> &layout::TargetDataLayout {
&self.tcx.data_layout &self.tcx.data_layout
} }
} }
impl<'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpretCx<'mir, 'tcx, M> impl<'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpCx<'mir, 'tcx, M>
where where
M: Machine<'mir, 'tcx>, M: Machine<'mir, 'tcx>,
{ {
@ -175,7 +175,7 @@ where
} }
} }
impl<'mir, 'tcx, M> layout::HasParamEnv<'tcx> for InterpretCx<'mir, 'tcx, M> impl<'mir, 'tcx, M> layout::HasParamEnv<'tcx> for InterpCx<'mir, 'tcx, M>
where where
M: Machine<'mir, 'tcx>, M: Machine<'mir, 'tcx>,
{ {
@ -184,7 +184,7 @@ where
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
type Ty = Ty<'tcx>; type Ty = Ty<'tcx>;
type TyLayout = InterpResult<'tcx, TyLayout<'tcx>>; type TyLayout = InterpResult<'tcx, TyLayout<'tcx>>;
@ -195,9 +195,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpretCx<'mir, 'tcx, M>
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
pub fn new(tcx: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self { pub fn new(tcx: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self {
InterpretCx { InterpCx {
machine, machine,
tcx, tcx,
param_env, param_env,

View file

@ -11,7 +11,7 @@ use rustc::mir::interpret::{
}; };
use super::{ use super::{
Machine, PlaceTy, OpTy, InterpretCx, Immediate, Machine, PlaceTy, OpTy, InterpCx, Immediate,
}; };
mod type_name; mod type_name;
@ -39,7 +39,7 @@ fn numeric_intrinsic<'tcx, Tag>(
Ok(Scalar::from_uint(bits_out, size)) Ok(Scalar::from_uint(bits_out, size))
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Returns `true` if emulation happened. /// Returns `true` if emulation happened.
pub fn emulate_intrinsic( pub fn emulate_intrinsic(
&mut self, &mut self,

View file

@ -11,7 +11,7 @@ use rustc::ty::{self, query::TyCtxtAt};
use super::{ use super::{
Allocation, AllocId, InterpResult, Scalar, AllocationExtra, Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory
}; };
/// Whether this kind of memory is allowed to leak /// Whether this kind of memory is allowed to leak
@ -95,11 +95,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
const STATIC_KIND: Option<Self::MemoryKinds>; const STATIC_KIND: Option<Self::MemoryKinds>;
/// Whether to enforce the validity invariant /// Whether to enforce the validity invariant
fn enforce_validity(ecx: &InterpretCx<'mir, 'tcx, Self>) -> bool; fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
/// Called before a basic block terminator is executed. /// Called before a basic block terminator is executed.
/// You can use this to detect endlessly running programs. /// You can use this to detect endlessly running programs.
fn before_terminator(ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>; fn before_terminator(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>;
/// Entry point to all function calls. /// Entry point to all function calls.
/// ///
@ -112,7 +112,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Passing `dest`and `ret` in the same `Option` proved very annoying when only one of them /// Passing `dest`and `ret` in the same `Option` proved very annoying when only one of them
/// was used. /// was used.
fn find_fn( fn find_fn(
ecx: &mut InterpretCx<'mir, 'tcx, Self>, ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: ty::Instance<'tcx>, instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Self::PointerTag>], args: &[OpTy<'tcx, Self::PointerTag>],
dest: Option<PlaceTy<'tcx, Self::PointerTag>>, dest: Option<PlaceTy<'tcx, Self::PointerTag>>,
@ -122,7 +122,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Directly process an intrinsic without pushing a stack frame. /// Directly process an intrinsic without pushing a stack frame.
/// If this returns successfully, the engine will take care of jumping to the next block. /// If this returns successfully, the engine will take care of jumping to the next block.
fn call_intrinsic( fn call_intrinsic(
ecx: &mut InterpretCx<'mir, 'tcx, Self>, ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: ty::Instance<'tcx>, instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Self::PointerTag>], args: &[OpTy<'tcx, Self::PointerTag>],
dest: PlaceTy<'tcx, Self::PointerTag>, dest: PlaceTy<'tcx, Self::PointerTag>,
@ -145,7 +145,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// ///
/// Returns a (value, overflowed) pair if the operation succeeded /// Returns a (value, overflowed) pair if the operation succeeded
fn ptr_op( fn ptr_op(
ecx: &InterpretCx<'mir, 'tcx, Self>, ecx: &InterpCx<'mir, 'tcx, Self>,
bin_op: mir::BinOp, bin_op: mir::BinOp,
left: ImmTy<'tcx, Self::PointerTag>, left: ImmTy<'tcx, Self::PointerTag>,
right: ImmTy<'tcx, Self::PointerTag>, right: ImmTy<'tcx, Self::PointerTag>,
@ -153,7 +153,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Heap allocations via the `box` keyword. /// Heap allocations via the `box` keyword.
fn box_alloc( fn box_alloc(
ecx: &mut InterpretCx<'mir, 'tcx, Self>, ecx: &mut InterpCx<'mir, 'tcx, Self>,
dest: PlaceTy<'tcx, Self::PointerTag>, dest: PlaceTy<'tcx, Self::PointerTag>,
) -> InterpResult<'tcx>; ) -> InterpResult<'tcx>;
@ -193,7 +193,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Executes a retagging operation /// Executes a retagging operation
#[inline] #[inline]
fn retag( fn retag(
_ecx: &mut InterpretCx<'mir, 'tcx, Self>, _ecx: &mut InterpCx<'mir, 'tcx, Self>,
_kind: mir::RetagKind, _kind: mir::RetagKind,
_place: PlaceTy<'tcx, Self::PointerTag>, _place: PlaceTy<'tcx, Self::PointerTag>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
@ -201,11 +201,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
} }
/// Called immediately before a new stack frame got pushed /// Called immediately before a new stack frame got pushed
fn stack_push(ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, Self::FrameExtra>; fn stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, Self::FrameExtra>;
/// Called immediately after a stack frame gets popped /// Called immediately after a stack frame gets popped
fn stack_pop( fn stack_pop(
ecx: &mut InterpretCx<'mir, 'tcx, Self>, ecx: &mut InterpCx<'mir, 'tcx, Self>,
extra: Self::FrameExtra, extra: Self::FrameExtra,
) -> InterpResult<'tcx>; ) -> InterpResult<'tcx>;

View file

@ -19,7 +19,7 @@ mod intern;
pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here
pub use self::eval_context::{ pub use self::eval_context::{
InterpretCx, Frame, StackPopCleanup, LocalState, LocalValue, InterpCx, Frame, StackPopCleanup, LocalState, LocalValue,
}; };
pub use self::place::{Place, PlaceTy, MemPlace, MPlaceTy}; pub use self::place::{Place, PlaceTy, MemPlace, MPlaceTy};

View file

@ -15,7 +15,7 @@ use rustc::mir::interpret::{
sign_extend, truncate, sign_extend, truncate,
}; };
use super::{ use super::{
InterpretCx, Machine, InterpCx, Machine,
MemPlace, MPlaceTy, PlaceTy, Place, MemPlace, MPlaceTy, PlaceTy, Place,
}; };
pub use rustc::mir::interpret::ScalarMaybeUndef; pub use rustc::mir::interpret::ScalarMaybeUndef;
@ -213,7 +213,7 @@ pub(super) fn from_known_layout<'tcx>(
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`. /// 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. /// Returns `None` if the layout does not permit loading this as a value.
fn try_read_immediate_from_mplace( fn try_read_immediate_from_mplace(

View file

@ -4,10 +4,10 @@ use syntax::ast::FloatTy;
use rustc_apfloat::Float; use rustc_apfloat::Float;
use rustc::mir::interpret::{InterpResult, Scalar}; use rustc::mir::interpret::{InterpResult, Scalar};
use super::{InterpretCx, PlaceTy, Immediate, Machine, ImmTy}; use super::{InterpCx, PlaceTy, Immediate, Machine, ImmTy};
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Applies the binary operation `op` to the two operands and writes a tuple of the result /// Applies the binary operation `op` to the two operands and writes a tuple of the result
/// and a boolean signifying the potential overflow to the destination. /// and a boolean signifying the potential overflow to the destination.
pub fn binop_with_overflow( pub fn binop_with_overflow(
@ -36,7 +36,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
fn binary_char_op( fn binary_char_op(
&self, &self,
bin_op: mir::BinOp, bin_op: mir::BinOp,

View file

@ -13,7 +13,7 @@ use rustc::ty::TypeFoldable;
use super::{ use super::{
GlobalId, AllocId, Allocation, Scalar, InterpResult, Pointer, PointerArithmetic, GlobalId, AllocId, Allocation, Scalar, InterpResult, Pointer, PointerArithmetic,
InterpretCx, Machine, AllocMap, AllocationExtra, InterpCx, Machine, AllocMap, AllocationExtra,
RawConst, Immediate, ImmTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind, LocalValue RawConst, Immediate, ImmTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind, LocalValue
}; };
@ -290,7 +290,7 @@ impl<'tcx, Tag: ::std::fmt::Debug> PlaceTy<'tcx, Tag> {
} }
// separating the pointer tag for `impl Trait`, see https://github.com/rust-lang/rust/issues/54385 // separating the pointer tag for `impl Trait`, see https://github.com/rust-lang/rust/issues/54385
impl<'mir, 'tcx, Tag, M> InterpretCx<'mir, 'tcx, M> impl<'mir, 'tcx, Tag, M> InterpCx<'mir, 'tcx, M>
where where
// FIXME: Working around https://github.com/rust-lang/rust/issues/54385 // FIXME: Working around https://github.com/rust-lang/rust/issues/54385
Tag: ::std::fmt::Debug + Copy + Eq + Hash + 'static, Tag: ::std::fmt::Debug + Copy + Eq + Hash + 'static,
@ -583,7 +583,7 @@ where
// global table but not in its local memory: It calls back into tcx through // global table but not in its local memory: It calls back into tcx through
// a query, triggering the CTFE machinery to actually turn this lazy reference // a query, triggering the CTFE machinery to actually turn this lazy reference
// into a bunch of bytes. IOW, statics are evaluated with CTFE even when // into a bunch of bytes. IOW, statics are evaluated with CTFE even when
// this InterpretCx uses another Machine (e.g., in miri). This is what we // this InterpCx uses another Machine (e.g., in miri). This is what we
// want! This way, computing statics works consistently between codegen // want! This way, computing statics works consistently between codegen
// and miri: They use the same query to eventually obtain a `ty::Const` // and miri: They use the same query to eventually obtain a `ty::Const`
// and use that for further computation. // and use that for further computation.

View file

@ -1,4 +1,4 @@
//! This module contains the `InterpretCx` methods for executing a single step of the interpreter. //! This module contains the `InterpCx` methods for executing a single step of the interpreter.
//! //!
//! The main entry point is the `step` method. //! The main entry point is the `step` method.
@ -6,7 +6,7 @@ use rustc::mir;
use rustc::ty::layout::LayoutOf; use rustc::ty::layout::LayoutOf;
use rustc::mir::interpret::{InterpResult, Scalar, PointerArithmetic}; use rustc::mir::interpret::{InterpResult, Scalar, PointerArithmetic};
use super::{InterpretCx, Machine}; use super::{InterpCx, Machine};
/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the /// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
/// same type as the result. /// same type as the result.
@ -35,7 +35,7 @@ fn binop_right_homogeneous(op: mir::BinOp) -> bool {
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
pub fn run(&mut self) -> InterpResult<'tcx> { pub fn run(&mut self) -> InterpResult<'tcx> {
while self.step()? {} while self.step()? {}
Ok(()) Ok(())

View file

@ -8,10 +8,10 @@ use rustc_target::spec::abi::Abi;
use rustc::mir::interpret::{InterpResult, PointerArithmetic, InterpError, Scalar}; use rustc::mir::interpret::{InterpResult, PointerArithmetic, InterpError, Scalar};
use super::{ use super::{
InterpretCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup
}; };
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
#[inline] #[inline]
pub fn goto_block(&mut self, target: Option<mir::BasicBlock>) -> InterpResult<'tcx> { pub fn goto_block(&mut self, target: Option<mir::BasicBlock>) -> InterpResult<'tcx> {
if let Some(target) = target { if let Some(target) = target {

View file

@ -2,9 +2,9 @@ use rustc::ty::{self, Ty, Instance};
use rustc::ty::layout::{Size, Align, LayoutOf}; use rustc::ty::layout::{Size, Align, LayoutOf};
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic}; use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic};
use super::{InterpretCx, InterpError, Machine, MemoryKind}; use super::{InterpCx, InterpError, Machine, MemoryKind};
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Creates a dynamic vtable for the given type and vtable origin. This is used only for /// Creates a dynamic vtable for the given type and vtable origin. This is used only for
/// objects. /// objects.
/// ///

View file

@ -13,7 +13,7 @@ use rustc::mir::interpret::{
use std::hash::Hash; use std::hash::Hash;
use super::{ use super::{
OpTy, Machine, InterpretCx, ValueVisitor, MPlaceTy, OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
}; };
macro_rules! validation_failure { macro_rules! validation_failure {
@ -174,7 +174,7 @@ struct ValidityVisitor<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> {
MPlaceTy<'tcx, M::PointerTag>, MPlaceTy<'tcx, M::PointerTag>,
Vec<PathElem>, Vec<PathElem>,
>>, >>,
ecx: &'rt InterpretCx<'mir, 'tcx, M>, ecx: &'rt InterpCx<'mir, 'tcx, M>,
} }
impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M> { impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M> {
@ -259,7 +259,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
type V = OpTy<'tcx, M::PointerTag>; type V = OpTy<'tcx, M::PointerTag>;
#[inline(always)] #[inline(always)]
fn ecx(&self) -> &InterpretCx<'mir, 'tcx, M> { fn ecx(&self) -> &InterpCx<'mir, 'tcx, M> {
&self.ecx &self.ecx
} }
@ -628,7 +628,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
} }
} }
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// This function checks the data at `op`. `op` is assumed to cover valid memory if it /// This function checks the data at `op`. `op` is assumed to cover valid memory if it
/// is an indirect operand. /// is an indirect operand.
/// It will error if the bits at the destination do not match the ones described by the layout. /// It will error if the bits at the destination do not match the ones described by the layout.

View file

@ -8,7 +8,7 @@ use rustc::mir::interpret::{
}; };
use super::{ use super::{
Machine, InterpretCx, MPlaceTy, OpTy, Machine, InterpCx, MPlaceTy, OpTy,
}; };
// A thing that we can project into, and that has a layout. // A thing that we can project into, and that has a layout.
@ -21,7 +21,7 @@ pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy {
/// Makes this into an `OpTy`. /// Makes this into an `OpTy`.
fn to_op( fn to_op(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>>; ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>>;
/// Creates this from an `MPlaceTy`. /// Creates this from an `MPlaceTy`.
@ -30,14 +30,14 @@ pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy {
/// Projects to the given enum variant. /// Projects to the given enum variant.
fn project_downcast( fn project_downcast(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
variant: VariantIdx, variant: VariantIdx,
) -> InterpResult<'tcx, Self>; ) -> InterpResult<'tcx, Self>;
/// Projects to the n-th field. /// Projects to the n-th field.
fn project_field( fn project_field(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
field: u64, field: u64,
) -> InterpResult<'tcx, Self>; ) -> InterpResult<'tcx, Self>;
} }
@ -53,7 +53,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M::
#[inline(always)] #[inline(always)]
fn to_op( fn to_op(
self, self,
_ecx: &InterpretCx<'mir, 'tcx, M>, _ecx: &InterpCx<'mir, 'tcx, M>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
Ok(self) Ok(self)
} }
@ -66,7 +66,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M::
#[inline(always)] #[inline(always)]
fn project_downcast( fn project_downcast(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
variant: VariantIdx, variant: VariantIdx,
) -> InterpResult<'tcx, Self> { ) -> InterpResult<'tcx, Self> {
ecx.operand_downcast(self, variant) ecx.operand_downcast(self, variant)
@ -75,7 +75,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M::
#[inline(always)] #[inline(always)]
fn project_field( fn project_field(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
field: u64, field: u64,
) -> InterpResult<'tcx, Self> { ) -> InterpResult<'tcx, Self> {
ecx.operand_field(self, field) ecx.operand_field(self, field)
@ -91,7 +91,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx,
#[inline(always)] #[inline(always)]
fn to_op( fn to_op(
self, self,
_ecx: &InterpretCx<'mir, 'tcx, M>, _ecx: &InterpCx<'mir, 'tcx, M>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
Ok(self.into()) Ok(self.into())
} }
@ -104,7 +104,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx,
#[inline(always)] #[inline(always)]
fn project_downcast( fn project_downcast(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
variant: VariantIdx, variant: VariantIdx,
) -> InterpResult<'tcx, Self> { ) -> InterpResult<'tcx, Self> {
ecx.mplace_downcast(self, variant) ecx.mplace_downcast(self, variant)
@ -113,7 +113,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx,
#[inline(always)] #[inline(always)]
fn project_field( fn project_field(
self, self,
ecx: &InterpretCx<'mir, 'tcx, M>, ecx: &InterpCx<'mir, 'tcx, M>,
field: u64, field: u64,
) -> InterpResult<'tcx, Self> { ) -> InterpResult<'tcx, Self> {
ecx.mplace_field(self, field) ecx.mplace_field(self, field)
@ -126,9 +126,9 @@ macro_rules! make_value_visitor {
pub trait $visitor_trait_name<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { pub trait $visitor_trait_name<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
type V: Value<'mir, 'tcx, M>; type V: Value<'mir, 'tcx, M>;
/// The visitor must have an `InterpretCx` in it. /// The visitor must have an `InterpCx` in it.
fn ecx(&$($mutability)? self) fn ecx(&$($mutability)? self)
-> &$($mutability)? InterpretCx<'mir, 'tcx, M>; -> &$($mutability)? InterpCx<'mir, 'tcx, M>;
// Recursive actions, ready to be overloaded. // Recursive actions, ready to be overloaded.
/// Visits the given value, dispatching as appropriate to more specialized visitors. /// Visits the given value, dispatching as appropriate to more specialized visitors.

View file

@ -23,7 +23,7 @@ use rustc::ty::layout::{
}; };
use crate::interpret::{ use crate::interpret::{
self, InterpretCx, ScalarMaybeUndef, Immediate, OpTy, self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
ImmTy, MemoryKind, StackPopCleanup, LocalValue, LocalState, ImmTy, MemoryKind, StackPopCleanup, LocalValue, LocalState,
}; };
use crate::const_eval::{ use crate::const_eval::{
@ -117,7 +117,7 @@ type Const<'tcx> = OpTy<'tcx>;
/// Finds optimization opportunities on the MIR. /// Finds optimization opportunities on the MIR.
struct ConstPropagator<'mir, 'tcx> { struct ConstPropagator<'mir, 'tcx> {
ecx: InterpretCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>, ecx: InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>, source: MirSource<'tcx>,
can_const_prop: IndexVec<Local, bool>, can_const_prop: IndexVec<Local, bool>,
@ -202,7 +202,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// If the local is `Unitialized` or `Dead` then we haven't propagated a value into it. // If the local is `Unitialized` or `Dead` then we haven't propagated a value into it.
// //
// `InterpretCx::access_local()` mostly takes care of this for us however, for ZSTs, // `InterpCx::access_local()` mostly takes care of this for us however, for ZSTs,
// it will synthesize a value for us. In doing so, that will cause the // it will synthesize a value for us. In doing so, that will cause the
// `get_const(l).is_empty()` assert right before we call `set_const()` in `visit_statement` // `get_const(l).is_empty()` assert right before we call `set_const()` in `visit_statement`
// to fail. // to fail.