Skip to content

Commit 5aa0f5c

Browse files
committed
Cleanup dead code
1 parent 2155f7a commit 5aa0f5c

File tree

3 files changed

+1
-149
lines changed

3 files changed

+1
-149
lines changed

src/fn_call.rs

-136
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
222222
return err!(MachineError("the evaluated program panicked".to_string()));
223223
}
224224

225-
//this.machine.unwinding = true;
226-
227225
// This part is tricky - we need to call BoxMeUp::box_me_up
228226
// on the vtable.
229227
//
@@ -287,12 +285,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
287285
let temp_ptr = this.allocate(dyn_ptr_layout, MiriMemoryKind::UnwindHelper.into());
288286
this.machine.box_me_up_tmp_ptr = Some(temp_ptr.clone());
289287

290-
291-
// Keep track of our current frame
292-
// This allows us to step throgh the exection of 'box_me_up',
293-
// exiting when we get back to this frame
294-
let cur_frame = this.cur_frame();
295-
296288
this.push_stack_frame(
297289
box_me_up_fn,
298290
box_me_up_mir.span,
@@ -310,52 +302,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
310302
let arg_0 = this.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
311303
this.write_scalar(data_ptr, arg_0)?;
312304

313-
/*// Step through execution of 'box_me_up'
314-
// We know that we're finished when our stack depth
315-
// returns to where it was before.
316-
//
317-
// Note that everything will get completely screwed up
318-
// if 'box_me_up' panics. This is fine, since this
319-
// function should never panic, as it's part of the core
320-
// panic handling infrastructure
321-
//
322-
// Normally, we would just let Miri drive
323-
// the execution of this stack frame.
324-
// However, we need to access its return value
325-
// in order to properly unwind.
326-
//
327-
// When we 'return' from '__rustc_start_panic',
328-
// we need to be executing the panic catch handler.
329-
// Therefore, we take care all all of the unwinding logic
330-
// here, instead of letting the Miri main loop do it
331-
while this.cur_frame() != cur_frame {
332-
this.step()?;
333-
}
334-
335-
// 'box_me_up' has finished. 'temp_ptr' now holds
336-
// a '*mut (dyn Any + Send)'
337-
// We want to split this into its consituient parts -
338-
// the data and vtable pointers - and store them back
339-
// into the panic handler frame
340-
let real_ret = this.read_immediate(temp_ptr.into())?;
341-
let real_ret_data = real_ret.to_scalar_ptr()?;
342-
let real_ret_vtable = real_ret.to_meta()?.expect("Expected fat pointer");
343-
344-
// We're in panic unwind mode. We pop off stack
345-
// frames until one of two things happens: we reach
346-
// a frame with 'catch_panic' set, or we pop of all frames
347-
//
348-
// If we pop off all frames without encountering 'catch_panic',
349-
// we exit.
350-
//
351-
// If we encounter 'catch_panic', we continue execution at that
352-
// frame, filling in data from the panic
353-
//
354-
unwind_stack(this, real_ret_data, real_ret_vtable)?;
355-
356-
this.memory_mut().deallocate(temp_ptr.to_ptr()?, None, MiriMemoryKind::UnwindHelper.into())?;
357-
this.dump_place(*dest.expect("dest is None!"));*/
358-
359305
return Ok(None)
360306

361307
}
@@ -1165,85 +1111,3 @@ fn gen_random<'a, 'mir, 'tcx>(
11651111
this.memory_mut().get_mut(ptr.alloc_id)?
11661112
.write_bytes(tcx, ptr, &data)
11671113
}
1168-
1169-
/// A helper method to unwind the stack.
1170-
///
1171-
/// We execute the 'unwind' blocks associated with frame
1172-
/// terminators as we go along (these blocks are responsible
1173-
/// for dropping frame locals in the event of a panic)
1174-
///
1175-
/// When we find our target frame, we write the panic payload
1176-
/// directly into its locals, and jump to it.
1177-
/// After that, panic handling is done - from the perspective
1178-
/// of the caller of '__rust_maybe_catch_panic', the function
1179-
/// has 'returned' normally, after which point Miri excecution
1180-
/// can proceeed normally.
1181-
fn unwind_stack<'a, 'mir, 'tcx>(
1182-
this: &mut MiriEvalContext<'a, 'mir, 'tcx>,
1183-
payload_data_ptr: Scalar<Tag>,
1184-
payload_vtable_ptr: Scalar<Tag>
1185-
) -> EvalResult<'tcx> {
1186-
while !this.stack().is_empty() {
1187-
// When '__rust_maybe_catch_panic' is called, it marks is frame
1188-
// with 'catch_panic'. When we find this marker, we've found
1189-
// our target frame to jump to.
1190-
if let Some(unwind_data) = this.frame_mut().extra.catch_panic.take() {
1191-
1192-
trace!("unwinding: found target frame: {:?}", this.frame().span);
1193-
1194-
let data_ptr = unwind_data.data_ptr.clone();
1195-
let vtable_ptr = unwind_data.vtable_ptr.clone();
1196-
let dest = unwind_data.dest.clone();
1197-
let ret = unwind_data.ret.clone();
1198-
drop(unwind_data);
1199-
1200-
1201-
// Here, we write directly into the frame of the function
1202-
// that called '__rust_maybe_catch_panic'.
1203-
// (NOT the function that called '__rust_start_panic')
1204-
1205-
this.write_scalar(payload_data_ptr, data_ptr.into())?;
1206-
this.write_scalar(payload_vtable_ptr, vtable_ptr.into())?;
1207-
1208-
// We 'return' the value 1 from __rust_maybe_catch_panic,
1209-
// since there was a panic
1210-
this.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?;
1211-
1212-
// We're done - continue execution in the frame of the function
1213-
// that called '__rust_maybe_catch_panic,'
1214-
this.goto_block(Some(ret))?;
1215-
1216-
return Ok(())
1217-
} else {
1218-
// This frame is above our target frame on the call stack.
1219-
// We pop it off the stack, running its 'unwind' block if applicable
1220-
trace!("unwinding: popping frame: {:?}", this.frame().span);
1221-
let block = &this.frame().mir.basic_blocks()[this.frame().block];
1222-
1223-
// All frames in the call stack should be executing their terminators.,
1224-
// as that's the only way for a basic block to perform a function call
1225-
if let Some(stmt) = block.statements.get(this.frame().stmt) {
1226-
panic!("Unexpcted statement '{:?}' for frame {:?}", stmt, this.frame().span);
1227-
}
1228-
1229-
// We're only interested in terminator types which allow for a cleanuup
1230-
// block (e.g. Call), and that also actually provide one
1231-
if let Some(Some(unwind)) = block.terminator().unwind() {
1232-
this.goto_block(Some(*unwind))?;
1233-
1234-
// Run the 'unwind' block until we encounter
1235-
// a 'Resume', which indicates that the block
1236-
// is done.
1237-
assert_eq!(this.run()?, StepOutcome::Resume);
1238-
}
1239-
1240-
// Pop this frame, and continue on to the next one
1241-
//this.pop_stack_frame()?;
1242-
//this.pop_stack_frame_unwind()?;
1243-
}
1244-
}
1245-
1246-
// We should never get here:
1247-
// The 'start_fn' lang item should always install a panic handler
1248-
return err!(Unreachable);
1249-
}

src/lib.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use std::rc::Rc;
2828
use rand::rngs::StdRng;
2929
use rand::SeedableRng;
3030

31-
use rustc_target::spec::PanicStrategy;
3231
use rustc::ty::{ExistentialPredicate, ExistentialTraitRef, RegionKind, List, ParamEnv};
3332
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
3433
use rustc::ty::layout::{LayoutOf, Size, Align, TyLayout};
@@ -232,11 +231,6 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
232231
}
233232
}
234233

235-
// Cache some data used by unwinding
236-
if ecx.tcx.tcx.sess.panic_strategy() == PanicStrategy::Unwind {
237-
238-
}
239-
240234
assert!(args.next().is_none(), "start lang item has more arguments than expected");
241235

242236
Ok(ecx)
@@ -330,6 +324,7 @@ pub enum MiriMemoryKind {
330324
C,
331325
/// Part of env var emulation.
332326
Env,
327+
/// Temporary storage for implementing unwinding
333328
UnwindHelper,
334329
/// Mutable statics.
335330
MutStatic,
@@ -680,7 +675,6 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
680675
let data_ptr = unwind_data.data_ptr.clone();
681676
let vtable_ptr = unwind_data.vtable_ptr.clone();
682677
let dest = unwind_data.dest.clone();
683-
let ret = unwind_data.ret.clone();
684678
drop(unwind_data);
685679

686680

@@ -697,11 +691,6 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
697691
ecx.machine.unwinding = false;
698692

699693
ecx.memory_mut().deallocate(tmp_ptr.to_ptr()?, None, MiriMemoryKind::UnwindHelper.into())?;
700-
701-
// We're done - continue execution in the frame of the function
702-
// that called '__rust_maybe_catch_panic,'
703-
//this.goto_block(Some(ret))?;
704-
705694
}
706695
}
707696
ecx.memory().extra.borrow_mut().end_call(extra.call_id);

src/stacked_borrows.rs

-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ trait EvalContextPrivExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
548548
trace!("reborrow: {} reference {:?} derived from {:?} (pointee {}): {:?}, size {}",
549549
kind, new_tag, ptr.tag, place.layout.ty, ptr.erase_tag(), size.bytes());
550550

551-
552551
// Get the allocation. It might not be mutable, so we cannot use `get_mut`.
553552
let alloc = this.memory().get(ptr.alloc_id)?;
554553
alloc.check_bounds(this, ptr, size, CheckInAllocMsg::InboundsTest)?;

0 commit comments

Comments
 (0)