Skip to content

Commit 788c5f3

Browse files
Revert "Refactor EvalContext stack and heap into inner struct"
This reverts commit 59d21c526c036d7097d05edd6dffdad9c5b1cb62, and uses tuple to store the mutable parts of an EvalContext (which now includes `Machine`). This requires that `Machine` be `Clone`.
1 parent 7f9b01a commit 788c5f3

File tree

8 files changed

+131
-173
lines changed

8 files changed

+131
-173
lines changed

src/librustc_mir/interpret/cast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
7676
// No alignment check needed for raw pointers. But we have to truncate to target ptr size.
7777
TyRawPtr(_) => {
7878
Ok(Scalar::Bits {
79-
bits: self.memory().truncate_to_ptr(v).0 as u128,
80-
defined: self.memory().pointer_size().bits() as u8,
79+
bits: self.memory.truncate_to_ptr(v).0 as u128,
80+
defined: self.memory.pointer_size().bits() as u8,
8181
})
8282
},
8383

@@ -92,7 +92,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
9292
match dest_ty.sty {
9393
// float -> uint
9494
TyUint(t) => {
95-
let width = t.bit_width().unwrap_or(self.memory().pointer_size().bits() as usize);
95+
let width = t.bit_width().unwrap_or(self.memory.pointer_size().bits() as usize);
9696
match fty {
9797
FloatTy::F32 => Ok(Scalar::Bits {
9898
bits: Single::from_bits(bits).to_u128(width).value,
@@ -106,7 +106,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
106106
},
107107
// float -> int
108108
TyInt(t) => {
109-
let width = t.bit_width().unwrap_or(self.memory().pointer_size().bits() as usize);
109+
let width = t.bit_width().unwrap_or(self.memory.pointer_size().bits() as usize);
110110
match fty {
111111
FloatTy::F32 => Ok(Scalar::Bits {
112112
bits: Single::from_bits(bits).to_i128(width).value as u128,

src/librustc_mir/interpret/const_eval.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn value_to_const_value<'tcx>(
8888
Value::ScalarPair(a, b) => Ok(ConstValue::ScalarPair(a, b)),
8989
Value::ByRef(ptr, align) => {
9090
let ptr = ptr.to_ptr().unwrap();
91-
let alloc = ecx.memory().get(ptr.alloc_id)?;
91+
let alloc = ecx.memory.get(ptr.alloc_id)?;
9292
assert!(alloc.align.abi() >= align.abi());
9393
assert!(alloc.bytes.len() as u64 - ptr.offset.bytes() >= layout.size.bytes());
9494
let mut alloc = alloc.clone();
@@ -149,7 +149,7 @@ fn eval_body_using_ecx<'a, 'mir, 'tcx>(
149149
}
150150
let layout = ecx.layout_of(mir.return_ty().subst(tcx, cid.instance.substs))?;
151151
assert!(!layout.is_unsized());
152-
let ptr = ecx.memory_mut().allocate(
152+
let ptr = ecx.memory.allocate(
153153
layout.size,
154154
layout.align,
155155
MemoryKind::Stack,
@@ -185,6 +185,7 @@ fn eval_body_using_ecx<'a, 'mir, 'tcx>(
185185
Ok((value, ptr, layout.ty))
186186
}
187187

188+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
188189
pub struct CompileTimeEvaluator;
189190

190191
impl<'tcx> Into<EvalError<'tcx>> for ConstEvalError {
@@ -486,7 +487,7 @@ pub fn const_variant_index<'a, 'tcx>(
486487
let (ptr, align) = match value {
487488
Value::ScalarPair(..) | Value::Scalar(_) => {
488489
let layout = ecx.layout_of(val.ty)?;
489-
let ptr = ecx.memory_mut().allocate(layout.size, layout.align, MemoryKind::Stack)?.into();
490+
let ptr = ecx.memory.allocate(layout.size, layout.align, MemoryKind::Stack)?.into();
490491
ecx.write_value_to_ptr(value, ptr, layout.align, val.ty)?;
491492
(ptr, layout.align)
492493
},
@@ -515,9 +516,9 @@ pub fn const_value_to_allocation_provider<'a, 'tcx>(
515516
());
516517
let value = ecx.const_to_value(val.val)?;
517518
let layout = ecx.layout_of(val.ty)?;
518-
let ptr = ecx.memory_mut().allocate(layout.size, layout.align, MemoryKind::Stack)?;
519+
let ptr = ecx.memory.allocate(layout.size, layout.align, MemoryKind::Stack)?;
519520
ecx.write_value_to_ptr(value, ptr.into(), layout.align, val.ty)?;
520-
let alloc = ecx.memory().get(ptr.alloc_id)?;
521+
let alloc = ecx.memory.get(ptr.alloc_id)?;
521522
Ok(tcx.intern_const_alloc(alloc.clone()))
522523
};
523524
result().expect("unable to convert ConstValue to Allocation")

0 commit comments

Comments
 (0)