mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
rename CompileTimeInterpreter -> CompileTimeMachine, CompileTimeEvalContext -> CompileTimeInterpCx
to match the terms used in the shared interpreter infrastructure
This commit is contained in:
parent
b6e5e3ffbb
commit
b316033dd8
@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::{layout::LayoutError, ConstInt};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use super::CompileTimeInterpreter;
|
||||
use super::CompileTimeMachine;
|
||||
use crate::errors::{self, FrameNote, ReportErrorExt};
|
||||
use crate::interpret::{err_inval, err_machine_stop};
|
||||
use crate::interpret::{ErrorHandled, Frame, InterpError, InterpErrorInfo, MachineStopType};
|
||||
@ -160,7 +160,7 @@ where
|
||||
// Even if this is unused, please don't remove it -- chances are we will need to emit a lint during const-eval again in the future!
|
||||
pub(super) fn lint<'tcx, L>(
|
||||
tcx: TyCtxtAt<'tcx>,
|
||||
machine: &CompileTimeInterpreter<'tcx>,
|
||||
machine: &CompileTimeMachine<'tcx>,
|
||||
lint: &'static rustc_session::lint::Lint,
|
||||
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
|
||||
) where
|
||||
|
@ -17,7 +17,7 @@ use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{self, Abi};
|
||||
|
||||
use super::{CanAccessMutGlobal, CompileTimeEvalContext, CompileTimeInterpreter};
|
||||
use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine};
|
||||
use crate::const_eval::CheckAlignment;
|
||||
use crate::errors::ConstEvalError;
|
||||
use crate::errors::{self, DanglingPtrInFinal};
|
||||
@ -32,7 +32,7 @@ use crate::CTRL_C_RECEIVED;
|
||||
// Returns a pointer to where the result lives
|
||||
#[instrument(level = "trace", skip(ecx, body))]
|
||||
fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
|
||||
ecx: &mut CompileTimeEvalContext<'tcx>,
|
||||
ecx: &mut CompileTimeInterpCx<'tcx>,
|
||||
cid: GlobalId<'tcx>,
|
||||
body: &'tcx mir::Body<'tcx>,
|
||||
) -> InterpResult<'tcx, R> {
|
||||
@ -139,13 +139,13 @@ pub(crate) fn mk_eval_cx_to_read_const_val<'tcx>(
|
||||
root_span: Span,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
can_access_mut_global: CanAccessMutGlobal,
|
||||
) -> CompileTimeEvalContext<'tcx> {
|
||||
) -> CompileTimeInterpCx<'tcx> {
|
||||
debug!("mk_eval_cx: {:?}", param_env);
|
||||
InterpCx::new(
|
||||
tcx,
|
||||
root_span,
|
||||
param_env,
|
||||
CompileTimeInterpreter::new(can_access_mut_global, CheckAlignment::No),
|
||||
CompileTimeMachine::new(can_access_mut_global, CheckAlignment::No),
|
||||
)
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ pub fn mk_eval_cx_for_const_val<'tcx>(
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
val: mir::ConstValue<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Option<(CompileTimeEvalContext<'tcx>, OpTy<'tcx>)> {
|
||||
) -> Option<(CompileTimeInterpCx<'tcx>, OpTy<'tcx>)> {
|
||||
let ecx = mk_eval_cx_to_read_const_val(tcx.tcx, tcx.span, param_env, CanAccessMutGlobal::No);
|
||||
let op = ecx.const_val_to_op(val, ty, None).ok()?;
|
||||
Some((ecx, op))
|
||||
@ -170,7 +170,7 @@ pub fn mk_eval_cx_for_const_val<'tcx>(
|
||||
/// encounter an `Indirect` they cannot handle.
|
||||
#[instrument(skip(ecx), level = "debug")]
|
||||
pub(super) fn op_to_const<'tcx>(
|
||||
ecx: &CompileTimeEvalContext<'tcx>,
|
||||
ecx: &CompileTimeInterpCx<'tcx>,
|
||||
op: &OpTy<'tcx>,
|
||||
for_diagnostics: bool,
|
||||
) -> ConstValue<'tcx> {
|
||||
@ -328,14 +328,14 @@ pub trait InterpretationResult<'tcx> {
|
||||
/// evaluation query.
|
||||
fn make_result(
|
||||
mplace: MPlaceTy<'tcx>,
|
||||
ecx: &mut InterpCx<'tcx, CompileTimeInterpreter<'tcx>>,
|
||||
ecx: &mut InterpCx<'tcx, CompileTimeMachine<'tcx>>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
|
||||
fn make_result(
|
||||
mplace: MPlaceTy<'tcx>,
|
||||
_ecx: &mut InterpCx<'tcx, CompileTimeInterpreter<'tcx>>,
|
||||
_ecx: &mut InterpCx<'tcx, CompileTimeMachine<'tcx>>,
|
||||
) -> Self {
|
||||
ConstAlloc { alloc_id: mplace.ptr().provenance.unwrap().alloc_id(), ty: mplace.layout.ty }
|
||||
}
|
||||
@ -383,7 +383,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
|
||||
// they do not have to behave "as if" they were evaluated at runtime.
|
||||
// For consts however we want to ensure they behave "as if" they were evaluated at runtime,
|
||||
// so we have to reject reading mutable global memory.
|
||||
CompileTimeInterpreter::new(CanAccessMutGlobal::from(is_static), CheckAlignment::Error),
|
||||
CompileTimeMachine::new(CanAccessMutGlobal::from(is_static), CheckAlignment::Error),
|
||||
);
|
||||
let res = ecx.load_mir(cid.instance.def, cid.promoted);
|
||||
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, body)).map_err(|error| {
|
||||
@ -417,7 +417,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
|
||||
|
||||
#[inline(always)]
|
||||
fn const_validate_mplace<'tcx>(
|
||||
ecx: &InterpCx<'tcx, CompileTimeInterpreter<'tcx>>,
|
||||
ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>,
|
||||
mplace: &MPlaceTy<'tcx>,
|
||||
cid: GlobalId<'tcx>,
|
||||
) -> Result<(), ErrorHandled> {
|
||||
@ -447,7 +447,7 @@ fn const_validate_mplace<'tcx>(
|
||||
|
||||
#[inline(always)]
|
||||
fn report_validation_error<'tcx>(
|
||||
ecx: &InterpCx<'tcx, CompileTimeInterpreter<'tcx>>,
|
||||
ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>,
|
||||
error: InterpErrorInfo<'tcx>,
|
||||
alloc_id: AllocId,
|
||||
) -> ErrorHandled {
|
||||
|
@ -44,7 +44,7 @@ const TINY_LINT_TERMINATOR_LIMIT: usize = 20;
|
||||
const PROGRESS_INDICATOR_START: usize = 4_000_000;
|
||||
|
||||
/// Extra machine state for CTFE, and the Machine instance
|
||||
pub struct CompileTimeInterpreter<'tcx> {
|
||||
pub struct CompileTimeMachine<'tcx> {
|
||||
/// The number of terminators that have been evaluated.
|
||||
///
|
||||
/// This is used to produce lints informing the user that the compiler is not stuck.
|
||||
@ -89,12 +89,12 @@ impl From<bool> for CanAccessMutGlobal {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> CompileTimeInterpreter<'tcx> {
|
||||
impl<'tcx> CompileTimeMachine<'tcx> {
|
||||
pub(crate) fn new(
|
||||
can_access_mut_global: CanAccessMutGlobal,
|
||||
check_alignment: CheckAlignment,
|
||||
) -> Self {
|
||||
CompileTimeInterpreter {
|
||||
CompileTimeMachine {
|
||||
num_evaluated_steps: 0,
|
||||
stack: Vec::new(),
|
||||
can_access_mut_global,
|
||||
@ -163,7 +163,7 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxIndexMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type CompileTimeEvalContext<'tcx> = InterpCx<'tcx, CompileTimeInterpreter<'tcx>>;
|
||||
pub(crate) type CompileTimeInterpCx<'tcx> = InterpCx<'tcx, CompileTimeMachine<'tcx>>;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum MemoryKind {
|
||||
@ -195,7 +195,7 @@ impl interpret::MayLeak for ! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> CompileTimeEvalContext<'tcx> {
|
||||
impl<'tcx> CompileTimeInterpCx<'tcx> {
|
||||
fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
|
||||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
@ -369,7 +369,7 @@ impl<'tcx> CompileTimeEvalContext<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> interpret::Machine<'tcx> for CompileTimeInterpreter<'tcx> {
|
||||
impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
|
||||
compile_time_machine!(<'tcx>);
|
||||
|
||||
type MemoryKind = MemoryKind;
|
||||
|
@ -9,7 +9,7 @@ use rustc_target::abi::{Abi, VariantIdx};
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use super::eval_queries::{mk_eval_cx_to_read_const_val, op_to_const};
|
||||
use super::machine::CompileTimeEvalContext;
|
||||
use super::machine::CompileTimeInterpCx;
|
||||
use super::{ValTreeCreationError, ValTreeCreationResult, VALTREE_MAX_NODES};
|
||||
use crate::const_eval::CanAccessMutGlobal;
|
||||
use crate::errors::MaxNumNodesInConstErr;
|
||||
@ -21,7 +21,7 @@ use crate::interpret::{
|
||||
|
||||
#[instrument(skip(ecx), level = "debug")]
|
||||
fn branches<'tcx>(
|
||||
ecx: &CompileTimeEvalContext<'tcx>,
|
||||
ecx: &CompileTimeInterpCx<'tcx>,
|
||||
place: &MPlaceTy<'tcx>,
|
||||
n: usize,
|
||||
variant: Option<VariantIdx>,
|
||||
@ -59,7 +59,7 @@ fn branches<'tcx>(
|
||||
|
||||
#[instrument(skip(ecx), level = "debug")]
|
||||
fn slice_branches<'tcx>(
|
||||
ecx: &CompileTimeEvalContext<'tcx>,
|
||||
ecx: &CompileTimeInterpCx<'tcx>,
|
||||
place: &MPlaceTy<'tcx>,
|
||||
num_nodes: &mut usize,
|
||||
) -> ValTreeCreationResult<'tcx> {
|
||||
@ -77,7 +77,7 @@ fn slice_branches<'tcx>(
|
||||
|
||||
#[instrument(skip(ecx), level = "debug")]
|
||||
fn const_to_valtree_inner<'tcx>(
|
||||
ecx: &CompileTimeEvalContext<'tcx>,
|
||||
ecx: &CompileTimeInterpCx<'tcx>,
|
||||
place: &MPlaceTy<'tcx>,
|
||||
num_nodes: &mut usize,
|
||||
) -> ValTreeCreationResult<'tcx> {
|
||||
@ -219,7 +219,7 @@ fn reconstruct_place_meta<'tcx>(
|
||||
|
||||
#[instrument(skip(ecx), level = "debug", ret)]
|
||||
fn create_valtree_place<'tcx>(
|
||||
ecx: &mut CompileTimeEvalContext<'tcx>,
|
||||
ecx: &mut CompileTimeInterpCx<'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
valtree: ty::ValTree<'tcx>,
|
||||
) -> MPlaceTy<'tcx> {
|
||||
@ -364,7 +364,7 @@ pub fn valtree_to_const_value<'tcx>(
|
||||
|
||||
/// Put a valtree into memory and return a reference to that.
|
||||
fn valtree_to_ref<'tcx>(
|
||||
ecx: &mut CompileTimeEvalContext<'tcx>,
|
||||
ecx: &mut CompileTimeInterpCx<'tcx>,
|
||||
valtree: ty::ValTree<'tcx>,
|
||||
pointee_ty: Ty<'tcx>,
|
||||
) -> Immediate {
|
||||
@ -380,7 +380,7 @@ fn valtree_to_ref<'tcx>(
|
||||
|
||||
#[instrument(skip(ecx), level = "debug")]
|
||||
fn valtree_into_mplace<'tcx>(
|
||||
ecx: &mut CompileTimeEvalContext<'tcx>,
|
||||
ecx: &mut CompileTimeInterpCx<'tcx>,
|
||||
place: &MPlaceTy<'tcx>,
|
||||
valtree: ty::ValTree<'tcx>,
|
||||
) {
|
||||
@ -457,6 +457,6 @@ fn valtree_into_mplace<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
fn dump_place<'tcx>(ecx: &CompileTimeEvalContext<'tcx>, place: &MPlaceTy<'tcx>) {
|
||||
fn dump_place<'tcx>(ecx: &CompileTimeInterpCx<'tcx>, place: &MPlaceTy<'tcx>) {
|
||||
trace!("{:?}", ecx.dump_place(&PlaceTy::from(place.clone())));
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ pub trait HasStaticRootDefId {
|
||||
fn static_def_id(&self) -> Option<LocalDefId>;
|
||||
}
|
||||
|
||||
impl HasStaticRootDefId for const_eval::CompileTimeInterpreter<'_> {
|
||||
impl HasStaticRootDefId for const_eval::CompileTimeMachine<'_> {
|
||||
fn static_def_id(&self) -> Option<LocalDefId> {
|
||||
Some(self.static_root_ids?.1)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::const_eval::{CompileTimeEvalContext, CompileTimeInterpreter, InterpretationResult};
|
||||
use crate::const_eval::{CompileTimeInterpCx, CompileTimeMachine, InterpretationResult};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer};
|
||||
@ -84,7 +84,7 @@ where
|
||||
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
|
||||
fn make_result(
|
||||
mplace: MPlaceTy<'tcx>,
|
||||
ecx: &mut InterpCx<'tcx, CompileTimeInterpreter<'tcx>>,
|
||||
ecx: &mut InterpCx<'tcx, CompileTimeMachine<'tcx>>,
|
||||
) -> Self {
|
||||
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
|
||||
let alloc = ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1;
|
||||
@ -93,7 +93,7 @@ impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx>
|
||||
}
|
||||
|
||||
pub(crate) fn create_static_alloc<'tcx>(
|
||||
ecx: &mut CompileTimeEvalContext<'tcx>,
|
||||
ecx: &mut CompileTimeInterpCx<'tcx>,
|
||||
static_def_id: LocalDefId,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
|
||||
|
@ -7,12 +7,12 @@ use rustc_middle::ty::{self, Mutability};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use tracing::trace;
|
||||
|
||||
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext};
|
||||
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeInterpCx};
|
||||
use crate::interpret::*;
|
||||
|
||||
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.
|
||||
fn alloc_caller_location<'tcx>(
|
||||
ecx: &mut CompileTimeEvalContext<'tcx>,
|
||||
ecx: &mut CompileTimeInterpCx<'tcx>,
|
||||
filename: Symbol,
|
||||
line: u32,
|
||||
col: u32,
|
||||
|
@ -3,7 +3,7 @@ use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout, Val
|
||||
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants};
|
||||
|
||||
use crate::const_eval::{CanAccessMutGlobal, CheckAlignment, CompileTimeInterpreter};
|
||||
use crate::const_eval::{CanAccessMutGlobal, CheckAlignment, CompileTimeMachine};
|
||||
use crate::interpret::{InterpCx, MemoryKind, OpTy};
|
||||
|
||||
/// Determines if this type permits "raw" initialization by just transmuting some memory into an
|
||||
@ -45,7 +45,7 @@ fn might_permit_raw_init_strict<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
kind: ValidityRequirement,
|
||||
) -> Result<bool, &'tcx LayoutError<'tcx>> {
|
||||
let machine = CompileTimeInterpreter::new(CanAccessMutGlobal::No, CheckAlignment::Error);
|
||||
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
|
||||
|
||||
let mut cx = InterpCx::new(tcx, rustc_span::DUMMY_SP, ParamEnv::reveal_all(), machine);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user