1
Fork 0

Add UnwindAction::Unreachable

This also makes eval machine's `StackPopUnwind`
redundant so that is replaced.
This commit is contained in:
Gary Guo 2022-10-10 19:50:49 +01:00
parent daeb844e0c
commit 5e6ed132fa
23 changed files with 160 additions and 149 deletions

View file

@ -131,7 +131,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
for id in cleanups_to_remove {
let cleanup = body.basic_blocks_mut()[id].terminator_mut().unwind_mut().unwrap();
*cleanup = UnwindAction::Continue;
*cleanup = UnwindAction::Unreachable;
}
// We may have invalidated some `cleanup` blocks so clean those up now.

View file

@ -24,7 +24,7 @@ use crate::MirPass;
use rustc_const_eval::interpret::{
self, compile_time_machine, AllocId, ConstAllocation, ConstValue, CtfeValidationMode, Frame,
ImmTy, Immediate, InterpCx, InterpResult, LocalValue, MemoryKind, OpTy, PlaceTy, Pointer,
Scalar, StackPopCleanup, StackPopUnwind,
Scalar, StackPopCleanup,
};
/// The maximum number of bytes that we'll allocate space for a local or the return value.
@ -209,7 +209,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
_args: &[OpTy<'tcx>],
_destination: &PlaceTy<'tcx>,
_target: Option<BasicBlock>,
_unwind: StackPopUnwind,
_unwind: UnwindAction,
) -> InterpResult<'tcx, Option<(&'mir Body<'tcx>, ty::Instance<'tcx>)>> {
Ok(None)
}
@ -220,7 +220,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
_args: &[OpTy<'tcx>],
_destination: &PlaceTy<'tcx>,
_target: Option<BasicBlock>,
_unwind: StackPopUnwind,
_unwind: UnwindAction,
) -> InterpResult<'tcx> {
throw_machine_stop_str!("calling intrinsics isn't supported in ConstProp")
}

View file

@ -399,7 +399,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let loc = Location { block: bb, statement_index: data.statements.len() };
let terminator = data.terminator();
let resume_block = self.patch.resume_block();
match terminator.kind {
TerminatorKind::Drop { mut place, target, unwind } => {
if let Some(new_place) = self.un_derefer.derefer(place.as_ref(), self.body) {
@ -408,22 +407,29 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
self.init_data.seek_before(loc);
match self.move_data().rev_lookup.find(place.as_ref()) {
LookupResult::Exact(path) => elaborate_drop(
&mut Elaborator { ctxt: self },
terminator.source_info,
place,
path,
target,
if data.is_cleanup {
LookupResult::Exact(path) => {
let unwind = if data.is_cleanup {
Unwind::InCleanup
} else {
match unwind {
UnwindAction::Cleanup(cleanup) => Unwind::To(cleanup),
UnwindAction::Continue => Unwind::To(resume_block),
UnwindAction::Continue => Unwind::To(self.patch.resume_block()),
UnwindAction::Unreachable => {
Unwind::To(self.patch.unreachable_block())
}
UnwindAction::Terminate => Unwind::To(self.patch.terminate_block()),
}
},
bb,
),
};
elaborate_drop(
&mut Elaborator { ctxt: self },
terminator.source_info,
place,
path,
target,
unwind,
bb,
)
}
LookupResult::Parent(..) => {
if !matches!(
terminator.source_info.span.desugaring_kind(),

View file

@ -1063,6 +1063,7 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Unwind::To(match *unwind {
UnwindAction::Cleanup(tgt) => tgt,
UnwindAction::Continue => elaborator.patch.resume_block(),
UnwindAction::Unreachable => elaborator.patch.unreachable_block(),
})
};
elaborate_drop(

View file

@ -1020,11 +1020,12 @@ impl Integrator<'_, '_> {
UnwindAction::Cleanup(_) => {
bug!("cleanup on cleanup block");
}
UnwindAction::Continue => return unwind,
UnwindAction::Continue | UnwindAction::Unreachable => return unwind,
}
}
match unwind {
UnwindAction::Unreachable => unwind,
UnwindAction::Cleanup(target) => UnwindAction::Cleanup(self.map_block(target)),
// Add an unwind edge to the original call's cleanup block
UnwindAction::Continue => self.cleanup_block,
@ -1140,6 +1141,9 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
terminator.kind = TerminatorKind::Goto { target: tgt };
}
UnwindAction::Continue => (),
UnwindAction::Unreachable => {
terminator.kind = TerminatorKind::Unreachable;
}
},
TerminatorKind::Abort => {}
TerminatorKind::Unreachable => {}

View file

@ -54,7 +54,7 @@ fn lower_slice_len_call<'tcx>(
args,
destination,
target: Some(bb),
unwind: UnwindAction::Continue,
unwind: UnwindAction::Unreachable,
from_hir_call: true,
..
} => {