Skip to content

Commit daeb844

Browse files
committed
Refactor unwind from Option to a new enum
1 parent 7f6edd3 commit daeb844

File tree

39 files changed

+328
-250
lines changed

39 files changed

+328
-250
lines changed

compiler/rustc_borrowck/src/diagnostics/find_use.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212
use rustc_data_structures::fx::FxIndexSet;
1313
use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor};
14-
use rustc_middle::mir::{Body, Local, Location};
14+
use rustc_middle::mir::{self, Body, Local, Location};
1515
use rustc_middle::ty::{RegionVid, TyCtxt};
1616

1717
pub(crate) fn find<'tcx>(
@@ -70,7 +70,10 @@ impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
7070
block_data
7171
.terminator()
7272
.successors()
73-
.filter(|&bb| Some(&Some(bb)) != block_data.terminator().unwind())
73+
.filter(|&bb| {
74+
Some(&mir::UnwindAction::Cleanup(bb))
75+
!= block_data.terminator().unwind()
76+
})
7477
.map(|bb| Location { statement_index: 0, block: bb }),
7578
);
7679
}

compiler/rustc_borrowck/src/invalidation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
125125
args,
126126
destination,
127127
target: _,
128-
cleanup: _,
128+
unwind: _,
129129
from_hir_call: _,
130130
fn_span: _,
131131
} => {
@@ -135,7 +135,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
135135
}
136136
self.mutate_place(location, *destination, Deep);
137137
}
138-
TerminatorKind::Assert { cond, expected: _, msg, target: _, cleanup: _ } => {
138+
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
139139
self.consume_operand(location, cond);
140140
use rustc_middle::mir::AssertKind;
141141
if let AssertKind::BoundsCheck { len, index } = msg {
@@ -173,7 +173,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
173173
options: _,
174174
line_spans: _,
175175
destination: _,
176-
cleanup: _,
176+
unwind: _,
177177
} => {
178178
for op in operands {
179179
match op {

compiler/rustc_borrowck/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
740740
args,
741741
destination,
742742
target: _,
743-
cleanup: _,
743+
unwind: _,
744744
from_hir_call: _,
745745
fn_span: _,
746746
} => {
@@ -750,7 +750,7 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
750750
}
751751
self.mutate_place(loc, (*destination, span), Deep, flow_state);
752752
}
753-
TerminatorKind::Assert { cond, expected: _, msg, target: _, cleanup: _ } => {
753+
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
754754
self.consume_operand(loc, (cond, span), flow_state);
755755
use rustc_middle::mir::AssertKind;
756756
if let AssertKind::BoundsCheck { len, index } = msg {
@@ -770,7 +770,7 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
770770
options: _,
771771
line_spans: _,
772772
destination: _,
773-
cleanup: _,
773+
unwind: _,
774774
} => {
775775
for op in operands {
776776
match op {

compiler/rustc_borrowck/src/type_check/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1610,20 +1610,20 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16101610
}
16111611
TerminatorKind::Unreachable => {}
16121612
TerminatorKind::Drop { target, unwind, .. }
1613-
| TerminatorKind::Assert { target, cleanup: unwind, .. } => {
1613+
| TerminatorKind::Assert { target, unwind, .. } => {
16141614
self.assert_iscleanup(body, block_data, target, is_cleanup);
1615-
if let Some(unwind) = unwind {
1615+
if let UnwindAction::Cleanup(unwind) = unwind {
16161616
if is_cleanup {
16171617
span_mirbug!(self, block_data, "unwind on cleanup block")
16181618
}
16191619
self.assert_iscleanup(body, block_data, unwind, true);
16201620
}
16211621
}
1622-
TerminatorKind::Call { ref target, cleanup, .. } => {
1622+
TerminatorKind::Call { ref target, unwind, .. } => {
16231623
if let &Some(target) = target {
16241624
self.assert_iscleanup(body, block_data, target, is_cleanup);
16251625
}
1626-
if let Some(cleanup) = cleanup {
1626+
if let UnwindAction::Cleanup(cleanup) = unwind {
16271627
if is_cleanup {
16281628
span_mirbug!(self, block_data, "cleanup on cleanup block")
16291629
}
@@ -1636,18 +1636,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16361636
}
16371637
TerminatorKind::FalseUnwind { real_target, unwind } => {
16381638
self.assert_iscleanup(body, block_data, real_target, is_cleanup);
1639-
if let Some(unwind) = unwind {
1639+
if let UnwindAction::Cleanup(unwind) = unwind {
16401640
if is_cleanup {
16411641
span_mirbug!(self, block_data, "cleanup in cleanup block via false unwind");
16421642
}
16431643
self.assert_iscleanup(body, block_data, unwind, true);
16441644
}
16451645
}
1646-
TerminatorKind::InlineAsm { destination, cleanup, .. } => {
1646+
TerminatorKind::InlineAsm { destination, unwind, .. } => {
16471647
if let Some(target) = destination {
16481648
self.assert_iscleanup(body, block_data, target, is_cleanup);
16491649
}
1650-
if let Some(cleanup) = cleanup {
1650+
if let UnwindAction::Cleanup(cleanup) = unwind {
16511651
if is_cleanup {
16521652
span_mirbug!(self, block_data, "cleanup on cleanup block")
16531653
}

compiler/rustc_codegen_cranelift/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
345345
TerminatorKind::Return => {
346346
crate::abi::codegen_return(fx);
347347
}
348-
TerminatorKind::Assert { cond, expected, msg, target, cleanup: _ } => {
348+
TerminatorKind::Assert { cond, expected, msg, target, unwind: _ } => {
349349
if !fx.tcx.sess.overflow_checks() && msg.is_optional_overflow_check() {
350350
let target = fx.get_block(*target);
351351
fx.bcx.ins().jump(target, &[]);
@@ -450,7 +450,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
450450
destination,
451451
target,
452452
fn_span,
453-
cleanup: _,
453+
unwind: _,
454454
from_hir_call: _,
455455
} => {
456456
fx.tcx.prof.generic_activity("codegen call").run(|| {
@@ -470,7 +470,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
470470
options,
471471
destination,
472472
line_spans: _,
473-
cleanup: _,
473+
unwind: _,
474474
} => {
475475
if options.contains(InlineAsmOptions::MAY_UNWIND) {
476476
fx.tcx.sess.span_fatal(

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
292292
| TerminatorKind::Yield { .. }
293293
| TerminatorKind::FalseEdge { .. }
294294
| TerminatorKind::FalseUnwind { .. } => { /* nothing to do */ }
295-
TerminatorKind::Call { cleanup: unwind, .. }
296-
| TerminatorKind::InlineAsm { cleanup: unwind, .. }
297-
| TerminatorKind::Assert { cleanup: unwind, .. }
295+
TerminatorKind::Call { unwind, .. }
296+
| TerminatorKind::InlineAsm { unwind, .. }
297+
| TerminatorKind::Assert { unwind, .. }
298298
| TerminatorKind::Drop { unwind, .. } => {
299-
if let Some(unwind) = unwind {
299+
if let mir::UnwindAction::Cleanup(unwind) = unwind {
300300
debug!(
301301
"cleanup_kinds: {:?}/{:?} registering {:?} as funclet",
302302
bb, data, unwind

compiler/rustc_codegen_ssa/src/mir/block.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,18 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
156156
fn_ptr: Bx::Value,
157157
llargs: &[Bx::Value],
158158
destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>,
159-
cleanup: Option<mir::BasicBlock>,
159+
unwind: mir::UnwindAction,
160160
copied_constant_arguments: &[PlaceRef<'tcx, <Bx as BackendTypes>::Value>],
161161
mergeable_succ: bool,
162162
) -> MergingSucc {
163163
// If there is a cleanup block and the function we're calling can unwind, then
164164
// do an invoke, otherwise do a call.
165165
let fn_ty = bx.fn_decl_backend_type(&fn_abi);
166166

167+
let cleanup = match unwind {
168+
mir::UnwindAction::Cleanup(cleanup) => Some(cleanup),
169+
mir::UnwindAction::Continue => None,
170+
};
167171
let unwind_block = if let Some(cleanup) = cleanup.filter(|_| fn_abi.can_unwind) {
168172
Some(self.llbb_with_cleanup(fx, cleanup))
169173
} else if fx.mir[self.bb].is_cleanup
@@ -244,11 +248,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
244248
options: InlineAsmOptions,
245249
line_spans: &[Span],
246250
destination: Option<mir::BasicBlock>,
247-
cleanup: Option<mir::BasicBlock>,
251+
unwind: mir::UnwindAction,
248252
instance: Instance<'_>,
249253
mergeable_succ: bool,
250254
) -> MergingSucc {
251-
if let Some(cleanup) = cleanup {
255+
if let mir::UnwindAction::Cleanup(cleanup) = unwind {
252256
let ret_llbb = if let Some(target) = destination {
253257
fx.llbb(target)
254258
} else {
@@ -431,7 +435,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
431435
bx: &mut Bx,
432436
location: mir::Place<'tcx>,
433437
target: mir::BasicBlock,
434-
unwind: Option<mir::BasicBlock>,
438+
unwind: mir::UnwindAction,
435439
mergeable_succ: bool,
436440
) -> MergingSucc {
437441
let ty = location.ty(self.mir, bx.tcx()).ty;
@@ -552,7 +556,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
552556
expected: bool,
553557
msg: &mir::AssertMessage<'tcx>,
554558
target: mir::BasicBlock,
555-
cleanup: Option<mir::BasicBlock>,
559+
unwind: mir::UnwindAction,
556560
mergeable_succ: bool,
557561
) -> MergingSucc {
558562
let span = terminator.source_info.span;
@@ -618,7 +622,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
618622
let (fn_abi, llfn) = common::build_langcall(bx, Some(span), lang_item);
619623

620624
// Codegen the actual panic invoke/call.
621-
let merging_succ = helper.do_call(self, bx, fn_abi, llfn, &args, None, cleanup, &[], false);
625+
let merging_succ = helper.do_call(self, bx, fn_abi, llfn, &args, None, unwind, &[], false);
622626
assert_eq!(merging_succ, MergingSucc::False);
623627
MergingSucc::False
624628
}
@@ -636,7 +640,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
636640
let (fn_abi, llfn) = common::build_langcall(bx, Some(span), LangItem::PanicCannotUnwind);
637641

638642
// Codegen the actual panic invoke/call.
639-
let merging_succ = helper.do_call(self, bx, fn_abi, llfn, &[], None, None, &[], false);
643+
let merging_succ = helper.do_call(self, bx, fn_abi, llfn, &[], None, mir::UnwindAction::Continue, &[], false);
640644
assert_eq!(merging_succ, MergingSucc::False);
641645
}
642646

@@ -649,7 +653,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
649653
instance: Option<Instance<'tcx>>,
650654
source_info: mir::SourceInfo,
651655
target: Option<mir::BasicBlock>,
652-
cleanup: Option<mir::BasicBlock>,
656+
unwind: mir::UnwindAction,
653657
mergeable_succ: bool,
654658
) -> Option<MergingSucc> {
655659
// Emit a panic or a no-op for `assert_*` intrinsics.
@@ -696,7 +700,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
696700
llfn,
697701
&[msg.0, msg.1],
698702
target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
699-
cleanup,
703+
unwind,
700704
&[],
701705
mergeable_succ,
702706
)
@@ -719,7 +723,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
719723
args: &[mir::Operand<'tcx>],
720724
destination: mir::Place<'tcx>,
721725
target: Option<mir::BasicBlock>,
722-
cleanup: Option<mir::BasicBlock>,
726+
unwind: mir::UnwindAction,
723727
fn_span: Span,
724728
mergeable_succ: bool,
725729
) -> MergingSucc {
@@ -783,7 +787,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
783787
instance,
784788
source_info,
785789
target,
786-
cleanup,
790+
unwind,
787791
mergeable_succ,
788792
) {
789793
return merging_succ;
@@ -1064,7 +1068,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10641068
fn_ptr,
10651069
&llargs,
10661070
target.as_ref().map(|&target| (ret_dest, target)),
1067-
cleanup,
1071+
unwind,
10681072
&copied_constant_arguments,
10691073
false,
10701074
);
@@ -1084,7 +1088,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10841088
fn_ptr,
10851089
&llargs,
10861090
target.as_ref().map(|&target| (ret_dest, target)),
1087-
cleanup,
1091+
unwind,
10881092
&copied_constant_arguments,
10891093
mergeable_succ,
10901094
)
@@ -1100,7 +1104,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11001104
options: ast::InlineAsmOptions,
11011105
line_spans: &[Span],
11021106
destination: Option<mir::BasicBlock>,
1103-
cleanup: Option<mir::BasicBlock>,
1107+
unwind: mir::UnwindAction,
11041108
instance: Instance<'_>,
11051109
mergeable_succ: bool,
11061110
) -> MergingSucc {
@@ -1164,7 +1168,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11641168
options,
11651169
line_spans,
11661170
destination,
1167-
cleanup,
1171+
unwind,
11681172
instance,
11691173
mergeable_succ,
11701174
)
@@ -1274,7 +1278,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12741278
self.codegen_drop_terminator(helper, bx, place, target, unwind, mergeable_succ())
12751279
}
12761280

1277-
mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => self
1281+
mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
12781282
.codegen_assert_terminator(
12791283
helper,
12801284
bx,
@@ -1283,7 +1287,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12831287
expected,
12841288
msg,
12851289
target,
1286-
cleanup,
1290+
unwind,
12871291
mergeable_succ(),
12881292
),
12891293

@@ -1292,7 +1296,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12921296
ref args,
12931297
destination,
12941298
target,
1295-
cleanup,
1299+
unwind,
12961300
from_hir_call: _,
12971301
fn_span,
12981302
} => self.codegen_call_terminator(
@@ -1303,7 +1307,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13031307
args,
13041308
destination,
13051309
target,
1306-
cleanup,
1310+
unwind,
13071311
fn_span,
13081312
mergeable_succ(),
13091313
),
@@ -1320,7 +1324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13201324
options,
13211325
line_spans,
13221326
destination,
1323-
cleanup,
1327+
unwind,
13241328
} => self.codegen_asm_terminator(
13251329
helper,
13261330
bx,
@@ -1330,7 +1334,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13301334
options,
13311335
line_spans,
13321336
destination,
1333-
cleanup,
1337+
unwind,
13341338
self.instance,
13351339
mergeable_succ(),
13361340
),

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
526526
fn assert_panic(
527527
ecx: &mut InterpCx<'mir, 'tcx, Self>,
528528
msg: &AssertMessage<'tcx>,
529-
_unwind: Option<mir::BasicBlock>,
529+
_unwind: mir::UnwindAction,
530530
) -> InterpResult<'tcx> {
531531
use rustc_middle::mir::AssertKind::*;
532532
// Convert `AssertKind<Operand>` to `AssertKind<Scalar>`.

compiler/rustc_const_eval/src/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
215215
fn assert_panic(
216216
ecx: &mut InterpCx<'mir, 'tcx, Self>,
217217
msg: &mir::AssertMessage<'tcx>,
218-
unwind: Option<mir::BasicBlock>,
218+
unwind: mir::UnwindAction,
219219
) -> InterpResult<'tcx>;
220220

221221
/// Called to evaluate `Abort` MIR terminator.

0 commit comments

Comments
 (0)