Skip to content

[move-function] Convert an assert into an early exit. #40508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ struct CheckerLivenessInfo {
} // end anonymous namespace

bool CheckerLivenessInfo::compute() {
bool foundEscapes = false;

LLVM_DEBUG(llvm::dbgs() << "LivenessVisitor Begin!\n");
while (SILValue value = defUseWorklist.pop()) {
LLVM_DEBUG(llvm::dbgs() << "New Value: " << value);
Expand All @@ -108,7 +106,8 @@ bool CheckerLivenessInfo::compute() {
// escape. Is it legal to canonicalize ForwardingUnowned?
case OperandOwnership::ForwardingUnowned:
case OperandOwnership::PointerEscape:
foundEscapes = true;
// This is an escape but it is up to the user to handle this, move
// checking stops here.
break;
case OperandOwnership::InstantaneousUse:
case OperandOwnership::UnownedInstantaneousUse:
Expand All @@ -133,8 +132,8 @@ bool CheckerLivenessInfo::compute() {
// binding that should be tracked separately.
if (!bbi->isLexical()) {
bool failed = !liveness.updateForBorrowingOperand(use);
assert(!failed &&
"Shouldn't see reborrows this early in the pipeline");
if (failed)
return false;
}
}
break;
Expand Down Expand Up @@ -178,8 +177,8 @@ bool CheckerLivenessInfo::compute() {
}
}

// We succeeded if we did not find any escapes.
return !foundEscapes;
// We succeeded if we reached this point since we handled all uses.
return true;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -380,11 +379,12 @@ bool MoveKillsCopyableValuesChecker::check() {
// Then compute liveness.
SWIFT_DEFER { livenessInfo.clear(); };
livenessInfo.initDef(lexicalValue);
// We do not care if we find an escape. We just want to make sure that any
// non-escaping users obey our property. If the user does something unsafe
// that is on them to manage.
bool foundEscape = livenessInfo.compute();
(void)foundEscape;

// We only fail to optimize if for some reason we hit reborrows. This is
// temporary since we really should just ban reborrows in Raw SIL.
bool canOptimize = livenessInfo.compute();
if (!canOptimize)
continue;

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