Skip to content

Commit 5fb001c

Browse files
authored
Merge pull request #62610 from gottesmm/pr-2fc1a68995dc3f80805e722e8419a6fcf4eb25fb
[move-only] Teach move checker that captured vars are treated like inout in the relevant closures
2 parents 40724e8 + 4901529 commit 5fb001c

13 files changed

+794
-696
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,12 @@ ERROR(sil_moveonlychecker_guaranteed_value_consumed, none,
733733
"'%0' has guaranteed ownership but was consumed", (StringRef))
734734
ERROR(sil_moveonlychecker_guaranteed_value_captured_by_closure, none,
735735
"'%0' has guaranteed ownership but was consumed due to being captured by a closure", (StringRef))
736+
ERROR(sil_moveonlychecker_let_value_consumed_in_closure, none,
737+
"'%0' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations", (StringRef))
736738
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_function, none,
737739
"'%0' consumed but not reinitialized before end of function", (StringRef))
740+
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_closure, none,
741+
"'%0' consumed in closure but not reinitialized before end of closure", (StringRef))
738742
ERROR(sil_moveonlychecker_value_consumed_in_a_loop, none,
739743
"'%0' consumed by a use in a loop", (StringRef))
740744
ERROR(sil_moveonlychecker_exclusivity_violation, none,

include/swift/SILOptimizer/Utils/InstructionDeleter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ class InstructionDeleter {
126126

127127
InstModCallbacks &getCallbacks() { return callbacks; }
128128

129+
void setCallbacks(const InstModCallbacks &newCallbacks) {
130+
callbacks = newCallbacks;
131+
}
132+
129133
bool hadCallbackInvocation() const {
130134
return const_cast<InstructionDeleter *>(this)
131135
->getCallbacks()

lib/SILGen/SILGenProlog.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ static void emitCaptureArguments(SILGenFunction &SGF,
581581
SILType::getPrimitiveObjectType(boxTy), VD);
582582
box->setClosureCapture(true);
583583
SILValue addr = SGF.B.createProjectBox(VD, box, 0);
584+
if (addr->getType().isMoveOnly())
585+
addr = SGF.B.createMarkMustCheckInst(
586+
VD, addr, MarkMustCheckInst::CheckKind::NoImplicitCopy);
584587
SGF.VarLocs[VD] = SILGenFunction::VarLoc::get(addr, box);
585588
SILDebugVariable DbgVar(VD->isLet(), ArgNo);
586589
SGF.B.createDebugValueAddr(Loc, addr, DbgVar);

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ target_sources(swiftSILOptimizer PRIVATE
2424
MovedAsyncVarDebugInfoPropagator.cpp
2525
MoveKillsCopyableAddressesChecker.cpp
2626
MoveKillsCopyableValuesChecker.cpp
27+
MoveOnlyDiagnostics.cpp
2728
MoveOnlyObjectChecker.cpp
2829
MoveOnlyAddressChecker.cpp
2930
MoveOnlyDeinitInsertion.cpp

0 commit comments

Comments
 (0)