Skip to content

Commit aa0e332

Browse files
committed
drop-if
1 parent aec002f commit aa0e332

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+338
-133
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
939939

940940
// drop and replace might have moved the assignment to the next block
941941
let maybe_additional_statement = if let Some(Terminator {
942-
kind: TerminatorKind::Drop { target: drop_target, is_replace: true, .. },
942+
kind: TerminatorKind::DropIfInit { target: drop_target, is_replace: true, .. },
943943
..
944944
}) = self.body[location.block].terminator
945945
{

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
112112
TerminatorKind::SwitchInt { ref discr, switch_ty: _, targets: _ } => {
113113
self.consume_operand(location, discr);
114114
}
115-
TerminatorKind::Drop { place: drop_place, target, unwind, is_replace } => {
115+
TerminatorKind::DropIfInit { place: drop_place, target, unwind, is_replace }
116+
| TerminatorKind::DropIf { place: drop_place, target, unwind, is_replace, test: _ } => {
116117
let next_statement = if *is_replace {
117118
self.body
118119
.basic_blocks

compiler/rustc_borrowck/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
652652
TerminatorKind::SwitchInt { ref discr, switch_ty: _, targets: _ } => {
653653
self.consume_operand(loc, (discr, span), flow_state);
654654
}
655-
TerminatorKind::Drop { place, target, unwind, is_replace } => {
655+
TerminatorKind::DropIfInit { place, target, unwind, is_replace }
656+
| TerminatorKind::DropIf { place, target, unwind, is_replace, test: _ } => {
656657
debug!(
657658
"visit_terminator_drop \
658659
loc: {:?} term: {:?} place: {:?} span: {:?}",
@@ -803,7 +804,8 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
803804
TerminatorKind::Abort
804805
| TerminatorKind::Assert { .. }
805806
| TerminatorKind::Call { .. }
806-
| TerminatorKind::Drop { .. }
807+
| TerminatorKind::DropIfInit { .. }
808+
| TerminatorKind::DropIf { .. }
807809
| TerminatorKind::FalseEdge { real_target: _, imaginary_target: _ }
808810
| TerminatorKind::FalseUnwind { real_target: _, unwind: _ }
809811
| TerminatorKind::Goto { .. }

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13421342
| TerminatorKind::Return
13431343
| TerminatorKind::GeneratorDrop
13441344
| TerminatorKind::Unreachable
1345-
| TerminatorKind::Drop { .. }
1345+
| TerminatorKind::DropIfInit { .. }
1346+
| TerminatorKind::DropIf { .. }
13461347
| TerminatorKind::FalseEdge { .. }
13471348
| TerminatorKind::FalseUnwind { .. }
13481349
| TerminatorKind::InlineAsm { .. } => {
@@ -1645,7 +1646,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16451646
}
16461647
}
16471648
TerminatorKind::Unreachable => {}
1648-
TerminatorKind::Drop { target, unwind, .. }
1649+
TerminatorKind::DropIfInit { target, unwind, .. }
1650+
| TerminatorKind::DropIf { target, unwind, .. }
16491651
| TerminatorKind::Assert { target, cleanup: unwind, .. } => {
16501652
self.assert_iscleanup(body, block_data, target, is_cleanup);
16511653
if let Some(unwind) = unwind {

compiler/rustc_borrowck/src/used_muts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc
7171
TerminatorKind::Call { destination, .. } => {
7272
self.remove_never_initialized_mut_locals(*destination);
7373
}
74-
// FIXME: ??
75-
// TerminatorKind::DropAndReplace { place, .. } => {
74+
// TerminatorKind::DropIfInit { place, .. } => {
7675
// self.remove_never_initialized_mut_locals(*place);
7776
// }
7877
_ => {}

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
477477
| TerminatorKind::GeneratorDrop => {
478478
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
479479
}
480-
TerminatorKind::Drop { place, target, unwind: _, is_replace: _ } => {
480+
TerminatorKind::DropIfInit { place, target, unwind: _, is_replace: _ }
481+
| TerminatorKind::DropIf { place, target, unwind: _, is_replace: _, test: _ } => {
481482
let drop_place = codegen_place(fx, *place);
482483
crate::abi::codegen_drop(fx, source_info, drop_place);
483484

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
539539
| TerminatorKind::Abort
540540
| TerminatorKind::Return
541541
| TerminatorKind::Unreachable
542-
| TerminatorKind::Drop { .. }
542+
| TerminatorKind::DropIfInit { .. }
543+
| TerminatorKind::DropIf { .. }
543544
| TerminatorKind::Assert { .. } => {}
544545
TerminatorKind::Yield { .. }
545546
| TerminatorKind::GeneratorDrop

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
281281
TerminatorKind::Call { cleanup: unwind, .. }
282282
| TerminatorKind::InlineAsm { cleanup: unwind, .. }
283283
| TerminatorKind::Assert { cleanup: unwind, .. }
284-
| TerminatorKind::Drop { unwind, .. } => {
284+
| TerminatorKind::DropIf { unwind, .. }
285+
| TerminatorKind::DropIfInit { unwind, .. } => {
285286
if let Some(unwind) = unwind {
286287
debug!(
287288
"cleanup_kinds: {:?}/{:?} registering {:?} as funclet",

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
413413
location: mir::Place<'tcx>,
414414
target: mir::BasicBlock,
415415
unwind: Option<mir::BasicBlock>,
416+
test: &mir::Operand<'tcx>,
416417
) {
418+
let drop_flag = self.codegen_operand(&mut bx, test);
419+
let drop_block = bx.append_sibling_block("drop");
420+
let lltarget = helper.llbb_with_cleanup(self, target);
421+
bx.cond_br(drop_flag.immediate(), drop_block, lltarget);
422+
423+
bx.switch_to_block(drop_block);
424+
self.set_debug_loc(&mut bx, helper.terminator.source_info);
425+
417426
let ty = location.ty(self.mir, bx.tcx()).ty;
418427
let ty = self.monomorphize(ty);
419428
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
@@ -1207,8 +1216,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12071216
bx.unreachable();
12081217
}
12091218

1210-
mir::TerminatorKind::Drop { place, target, unwind, is_replace: _ } => {
1211-
self.codegen_drop_terminator(helper, bx, place, target, unwind);
1219+
mir::TerminatorKind::DropIf { place, target, unwind, is_replace: _, ref test } => {
1220+
self.codegen_drop_terminator(helper, bx, place, target, unwind, test);
12121221
}
12131222

12141223
mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => {
@@ -1241,6 +1250,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12411250
mir::TerminatorKind::GeneratorDrop | mir::TerminatorKind::Yield { .. } => {
12421251
bug!("generator ops in codegen")
12431252
}
1253+
mir::TerminatorKind::DropIfInit { .. } => {
1254+
bug!(
1255+
"drop elaboration should have removed this terminator in codegen {:?}",
1256+
self.mir
1257+
)
1258+
}
12441259
mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
12451260
bug!("borrowck false edges in codegen")
12461261
}

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
119119
}
120120
}
121121

122-
Drop { place, target, unwind, is_replace: _ } => {
122+
DropIf { place, target, unwind, .. } => {
123123
let place = self.eval_place(place)?;
124124
let ty = place.layout.ty;
125-
trace!("TerminatorKind::drop: {:?}, type {}", place, ty);
125+
trace!("TerminatorKind::DropIf: {:?}, type {}", place, ty);
126126

127127
let instance = Instance::resolve_drop_in_place(*self.tcx, ty);
128128
self.drop_in_place(&place, instance, target, unwind)?;
@@ -156,7 +156,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
156156
Unreachable => throw_ub!(Unreachable),
157157

158158
// These should never occur for MIR we actually run.
159-
FalseEdge { .. } | FalseUnwind { .. } | Yield { .. } | GeneratorDrop => span_bug!(
159+
DropIfInit { .. }
160+
| FalseEdge { .. }
161+
| FalseUnwind { .. }
162+
| Yield { .. }
163+
| GeneratorDrop => span_bug!(
160164
terminator.source_info.span,
161165
"{:#?} should have been eliminated by MIR pass",
162166
terminator.kind

0 commit comments

Comments
 (0)