Skip to content

Commit 6734b55

Browse files
committed
[move-only] Teach the move only object checker how to handle concrete resilient guaranteed arguments.
The only difference from normal concrete guaranteed parameter emission is we have a load_borrow on the argument before the copy_value. That is instead of: ``` bb0(%0 : @guaranteed $Type): %1 = copy_value %0 %2 = mark_must_check [no_consume_or_assign] %1 ``` we have, ``` bb0(%0 : $*Type): // in_guaranteed %1 = load_borrow %0 %2 = copy_value %1 %3 = mark_must_check [no_consume_or_assign] %2 ``` So I just needed to update the checker to recognize that pattern. This is tested by just making sure that the checker can handle the borrowVal in the tests without emitting an error. rdar://109170906 (cherry picked from commit 7d7c929)
1 parent a10a5db commit 6734b55

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerUtils.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ bool swift::siloptimizer::searchForCandidateObjectMarkMustChecks(
110110
}
111111
}
112112

113+
// In the case we have a resilient argument, we may have the following pattern:
114+
//
115+
// bb0(%0 : $*Type): // in_guaranteed
116+
// %1 = load_borrow %0
117+
// %2 = copy_value
118+
// %3 = mark_must_check [no_copy_or_assign]
119+
if (auto *lbi = dyn_cast<LoadBorrowInst>(cvi->getOperand())) {
120+
if (auto *arg = dyn_cast<SILFunctionArgument>(lbi->getOperand())) {
121+
if (arg->getKnownParameterInfo().isIndirectInGuaranteed()) {
122+
moveIntroducersToProcess.insert(mmci);
123+
continue;
124+
}
125+
}
126+
}
127+
113128
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
114129
if (bbi->isLexical()) {
115130
moveIntroducersToProcess.insert(mmci);
@@ -656,6 +671,11 @@ void MoveOnlyObjectCheckerPImpl::check(DominanceInfo *domTree,
656671
i = copyToMoveOnly;
657672
}
658673

674+
// Handle:
675+
//
676+
// bb0(%0 : @guaranteed $Type):
677+
// %1 = copy_value %0
678+
// %2 = mark_must_check [no_consume_or_assign] %1
659679
if (auto *arg = dyn_cast<SILFunctionArgument>(i->getOperand(0))) {
660680
if (arg->getOwnershipKind() == OwnershipKind::Guaranteed) {
661681
for (auto *use : markedInst->getConsumingUses()) {
@@ -669,6 +689,28 @@ void MoveOnlyObjectCheckerPImpl::check(DominanceInfo *domTree,
669689
continue;
670690
}
671691
}
692+
693+
// Handle:
694+
//
695+
// bb0(%0 : $*Type): // in_guaranteed
696+
// %1 = load_borrow %0
697+
// %2 = copy_value %1
698+
// %3 = mark_must_check [no_consume_or_assign] %2
699+
if (auto *lbi = dyn_cast<LoadBorrowInst>(i->getOperand(0))) {
700+
if (auto *arg = dyn_cast<SILFunctionArgument>(lbi->getOperand())) {
701+
if (arg->getKnownParameterInfo().isIndirectInGuaranteed()) {
702+
for (auto *use : markedInst->getConsumingUses()) {
703+
destroys.push_back(cast<DestroyValueInst>(use->getUser()));
704+
}
705+
while (!destroys.empty())
706+
destroys.pop_back_val()->eraseFromParent();
707+
markedInst->replaceAllUsesWith(lbi);
708+
markedInst->eraseFromParent();
709+
cvi->eraseFromParent();
710+
continue;
711+
}
712+
}
713+
}
672714
}
673715
}
674716
}

test/SILOptimizer/moveonly_addresschecker_diagnostics_library_evolution.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
// MARK: Deinit Tests //
99
////////////////////////
1010

11+
@_moveOnly public struct EmptyStruct {}
12+
@_moveOnly public struct NonEmptyStruct {
13+
var e = EmptyStruct()
14+
}
15+
public class CopyableKlass {
16+
var s = NonEmptyStruct()
17+
}
18+
19+
public func borrowVal(_ x: borrowing NonEmptyStruct) {}
20+
public func borrowVal(_ x: borrowing EmptyStruct) {}
21+
22+
/////////////////
23+
// MARK: Tests //
24+
/////////////////
25+
1126
public struct DeinitTest : ~Copyable {
1227
deinit {}
1328
}

0 commit comments

Comments
 (0)