Skip to content

Commit f2a416e

Browse files
authored
Merge pull request #40508 from gottesmm/pr-51f6aede629e2aa705d53c4909bf5c4aae7dd701
[move-function] Convert an assert into an early exit.
2 parents 2e6ff0c + eb03fb6 commit f2a416e

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)