Skip to content

Commit eb03fb6

Browse files
committed
[move-function] Convert an assert into an early exit.
This assert was making sure we never saw a reborrow since they shouldn't occur in Raw SIL. Some people were reporting that they /are/ hitting this assert, so I am converting it into an early exit + skip analyzing an address. This will prevent the assertion and also will fulfill the same purpose as the original, not performing the move checking. This will still result in correctness since if we skip as a move marker instruction as a result of us skipping processing an address, the pass will emit a compile time diagnostic saying the checker wasn't able to understand the given code. So not the best, but at least if this hits a move itself we will be ok.
1 parent 2755f74 commit eb03fb6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ struct CheckerLivenessInfo {
8080
} // end anonymous namespace
8181

8282
bool CheckerLivenessInfo::compute() {
83-
bool foundEscapes = false;
84-
8583
LLVM_DEBUG(llvm::dbgs() << "LivenessVisitor Begin!\n");
8684
while (SILValue value = defUseWorklist.pop()) {
8785
LLVM_DEBUG(llvm::dbgs() << "New Value: " << value);
@@ -108,7 +106,8 @@ bool CheckerLivenessInfo::compute() {
108106
// escape. Is it legal to canonicalize ForwardingUnowned?
109107
case OperandOwnership::ForwardingUnowned:
110108
case OperandOwnership::PointerEscape:
111-
foundEscapes = true;
109+
// This is an escape but it is up to the user to handle this, move
110+
// checking stops here.
112111
break;
113112
case OperandOwnership::InstantaneousUse:
114113
case OperandOwnership::UnownedInstantaneousUse:
@@ -133,8 +132,8 @@ bool CheckerLivenessInfo::compute() {
133132
// binding that should be tracked separately.
134133
if (!bbi->isLexical()) {
135134
bool failed = !liveness.updateForBorrowingOperand(use);
136-
assert(!failed &&
137-
"Shouldn't see reborrows this early in the pipeline");
135+
if (failed)
136+
return false;
138137
}
139138
}
140139
break;
@@ -178,8 +177,8 @@ bool CheckerLivenessInfo::compute() {
178177
}
179178
}
180179

181-
// We succeeded if we did not find any escapes.
182-
return !foundEscapes;
180+
// We succeeded if we reached this point since we handled all uses.
181+
return true;
183182
}
184183

185184
//===----------------------------------------------------------------------===//
@@ -380,11 +379,12 @@ bool MoveKillsCopyableValuesChecker::check() {
380379
// Then compute liveness.
381380
SWIFT_DEFER { livenessInfo.clear(); };
382381
livenessInfo.initDef(lexicalValue);
383-
// We do not care if we find an escape. We just want to make sure that any
384-
// non-escaping users obey our property. If the user does something unsafe
385-
// that is on them to manage.
386-
bool foundEscape = livenessInfo.compute();
387-
(void)foundEscape;
382+
383+
// We only fail to optimize if for some reason we hit reborrows. This is
384+
// temporary since we really should just ban reborrows in Raw SIL.
385+
bool canOptimize = livenessInfo.compute();
386+
if (!canOptimize)
387+
continue;
388388

389389
// Then look at all of our found consuming uses. See if any of these are
390390
// _move that are within the boundary.

0 commit comments

Comments
 (0)