Skip to content

Commit 8d9db57

Browse files
committed
Auto merge of #1335 - vakaras:add-threads-noop, r=RalfJung
Move the stack to the evaluator. (no-op PR for 70598) The changes to Miri to make it to compile with Rustc PR rust-lang/rust#70598.
2 parents 763782a + 7406c12 commit 8d9db57

File tree

23 files changed

+60
-43
lines changed

23 files changed

+60
-43
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b2c1a606feb1fbdb0ac0acba76f881ef172ed474
1+
9b2f8dbba39dd4167f22a7026674a585c3d907d8

src/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum NonHaltingDiagnostic {
4747

4848
/// Emit a custom diagnostic without going through the miri-engine machinery
4949
pub fn report_error<'tcx, 'mir>(
50-
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
50+
ecx: &InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
5151
mut e: InterpErrorInfo<'tcx>,
5252
) -> Option<i64> {
5353
use InterpError::*;
@@ -121,13 +121,13 @@ pub fn report_error<'tcx, 'mir>(
121121
/// Report an error or note (depending on the `error` argument) at the current frame's current statement.
122122
/// Also emits a full stacktrace of the interpreter stack.
123123
fn report_msg<'tcx, 'mir>(
124-
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
124+
ecx: &InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
125125
title: &str,
126126
span_msg: String,
127127
mut helps: Vec<String>,
128128
error: bool,
129129
) -> Option<i64> {
130-
let span = if let Some(frame) = ecx.stack().last() {
130+
let span = if let Some(frame) = ecx.machine.stack.last() {
131131
frame.current_source_info().unwrap().span
132132
} else {
133133
DUMMY_SP
@@ -159,7 +159,7 @@ fn report_msg<'tcx, 'mir>(
159159

160160
err.emit();
161161

162-
for (i, frame) in ecx.stack().iter().enumerate() {
162+
for (i, frame) in ecx.machine.stack.iter().enumerate() {
163163
trace!("-------------------");
164164
trace!("Frame {}", i);
165165
trace!(" return: {:?}", frame.return_place.map(|p| *p));
@@ -181,7 +181,7 @@ pub fn register_diagnostic(e: NonHaltingDiagnostic) {
181181
DIAGNOSTICS.with(|diagnostics| diagnostics.borrow_mut().push(e));
182182
}
183183

184-
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
184+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
185185
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
186186
/// Emit all diagnostics that were registed with `register_diagnostics`
187187
fn process_diagnostics(&self) {

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
6262
tcx: TyCtxt<'tcx>,
6363
main_id: DefId,
6464
config: MiriConfig,
65-
) -> InterpResult<'tcx, (InterpCx<'mir, 'tcx, Evaluator<'tcx>>, MPlaceTy<'tcx, Tag>)> {
65+
) -> InterpResult<'tcx, (InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>, MPlaceTy<'tcx, Tag>)> {
6666
let tcx_at = tcx.at(rustc_span::source_map::DUMMY_SP);
6767
let param_env = ty::ParamEnv::reveal_all();
6868
let layout_cx = LayoutCx { tcx, param_env };

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rand::RngCore;
1313

1414
use crate::*;
1515

16-
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
16+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
1717

1818
/// Gets an instance for a path.
1919
fn try_resolve_did<'mir, 'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId> {
@@ -265,7 +265,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
265265
unsafe_cell_action: F,
266266
}
267267

268-
impl<'ecx, 'mir, 'tcx, F> ValueVisitor<'mir, 'tcx, Evaluator<'tcx>>
268+
impl<'ecx, 'mir, 'tcx: 'mir, F> ValueVisitor<'mir, 'tcx, Evaluator<'mir, 'tcx>>
269269
for UnsafeCellVisitor<'ecx, 'mir, 'tcx, F>
270270
where
271271
F: FnMut(MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx>,

src/intptrcast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Default for GlobalState {
4141
impl<'mir, 'tcx> GlobalState {
4242
pub fn int_to_ptr(
4343
int: u64,
44-
memory: &Memory<'mir, 'tcx, Evaluator<'tcx>>,
44+
memory: &Memory<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
4545
) -> InterpResult<'tcx, Pointer<Tag>> {
4646
let global_state = memory.extra.intptrcast.borrow();
4747
let pos = global_state.int_to_ptr_map.binary_search_by_key(&int, |(addr, _)| *addr);
@@ -73,7 +73,7 @@ impl<'mir, 'tcx> GlobalState {
7373

7474
pub fn ptr_to_int(
7575
ptr: Pointer<Tag>,
76-
memory: &Memory<'mir, 'tcx, Evaluator<'tcx>>,
76+
memory: &Memory<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
7777
) -> InterpResult<'tcx, u64> {
7878
let mut global_state = memory.extra.intptrcast.borrow_mut();
7979
let global_state = &mut *global_state;

src/machine.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
215215
}
216216

217217
/// The machine itself.
218-
pub struct Evaluator<'tcx> {
218+
pub struct Evaluator<'mir, 'tcx> {
219219
/// Environment variables set by `setenv`.
220220
/// Miri does not expose env vars from the host to the emulated program.
221221
pub(crate) env_vars: EnvVars<'tcx>,
@@ -251,11 +251,14 @@ pub struct Evaluator<'tcx> {
251251
/// The "time anchor" for this machine's monotone clock (for `Instant` simulation).
252252
pub(crate) time_anchor: Instant,
253253

254+
/// The call stack.
255+
pub(crate) stack: Vec<Frame<'mir, 'tcx, Tag, FrameData<'tcx>>>,
256+
254257
/// Precomputed `TyLayout`s for primitive data types that are commonly used inside Miri.
255258
pub(crate) layouts: PrimitiveLayouts<'tcx>,
256259
}
257260

258-
impl<'tcx> Evaluator<'tcx> {
261+
impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
259262
pub(crate) fn new(
260263
communicate: bool,
261264
validate: bool,
@@ -279,12 +282,13 @@ impl<'tcx> Evaluator<'tcx> {
279282
panic_payload: None,
280283
time_anchor: Instant::now(),
281284
layouts,
285+
stack: Vec::default(),
282286
}
283287
}
284288
}
285289

286290
/// A rustc InterpCx for Miri.
287-
pub type MiriEvalContext<'mir, 'tcx> = InterpCx<'mir, 'tcx, Evaluator<'tcx>>;
291+
pub type MiriEvalContext<'mir, 'tcx> = InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>;
288292

289293
/// A little trait that's useful to be inherited by extension traits.
290294
pub trait MiriEvalContextExt<'mir, 'tcx> {
@@ -303,7 +307,7 @@ impl<'mir, 'tcx> MiriEvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx>
303307
}
304308

305309
/// Machine hook implementations.
306-
impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
310+
impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
307311
type MemoryKind = MiriMemoryKind;
308312

309313
type FrameExtra = FrameData<'tcx>;
@@ -521,6 +525,20 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
521525
Ok(frame.with_extra(extra))
522526
}
523527

528+
#[inline(always)]
529+
fn stack<'a>(
530+
ecx: &'a InterpCx<'mir, 'tcx, Self>,
531+
) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
532+
&ecx.machine.stack
533+
}
534+
535+
#[inline(always)]
536+
fn stack_mut<'a>(
537+
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
538+
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> {
539+
&mut ecx.machine.stack
540+
}
541+
524542
#[inline(always)]
525543
fn after_stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
526544
if ecx.memory.extra.stacked_borrows.is_some() {

src/shims/dlsym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Dlsym {
2020
}
2121
}
2222

23-
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
23+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
2424
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
2525
fn call_dlsym(
2626
&mut self,

src/shims/env.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct EnvVars<'tcx> {
3535

3636
impl<'tcx> EnvVars<'tcx> {
3737
pub(crate) fn init<'mir>(
38-
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
38+
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
3939
mut excluded_env_vars: Vec<String>,
4040
) -> InterpResult<'tcx> {
4141
let target_os = ecx.tcx.sess.target.target.target_os.as_str();
@@ -61,7 +61,7 @@ impl<'tcx> EnvVars<'tcx> {
6161
}
6262

6363
pub(crate) fn cleanup<'mir>(
64-
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
64+
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
6565
) -> InterpResult<'tcx> {
6666
// Deallocate individual env vars.
6767
for (_name, ptr) in ecx.machine.env_vars.map.drain() {
@@ -78,7 +78,7 @@ impl<'tcx> EnvVars<'tcx> {
7878
fn alloc_env_var_as_c_str<'mir, 'tcx>(
7979
name: &OsStr,
8080
value: &OsStr,
81-
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
81+
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
8282
) -> InterpResult<'tcx, Pointer<Tag>> {
8383
let mut name_osstring = name.to_os_string();
8484
name_osstring.push("=");
@@ -89,15 +89,15 @@ fn alloc_env_var_as_c_str<'mir, 'tcx>(
8989
fn alloc_env_var_as_wide_str<'mir, 'tcx>(
9090
name: &OsStr,
9191
value: &OsStr,
92-
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
92+
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>,
9393
) -> InterpResult<'tcx, Pointer<Tag>> {
9494
let mut name_osstring = name.to_os_string();
9595
name_osstring.push("=");
9696
name_osstring.push(value);
9797
Ok(ecx.alloc_os_str_as_wide_str(name_osstring.as_os_str(), MiriMemoryKind::Env.into()))
9898
}
9999

100-
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
100+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
101101
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
102102
fn getenv(&mut self, name_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Tag>> {
103103
let this = self.eval_context_mut();

src/shims/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::attr;
1212

1313
use crate::*;
1414

15-
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
15+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
1616
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
1717
/// Returns the minimum alignment for the target architecture for allocations of the given size.
1818
fn min_align(&self, size: u64, kind: MiriMemoryKind) -> Align {

src/shims/foreign_items/posix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::*;
99
use rustc_middle::mir;
1010
use rustc_target::abi::{Align, LayoutOf, Size};
1111

12-
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
12+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
1313
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
1414
fn emulate_foreign_item_by_name(
1515
&mut self,

0 commit comments

Comments
 (0)