Skip to content

Commit 258986a

Browse files
committed
[move-function] When processing object lets only look through non-lexical borrows.
A lexical borrow is creating a new entity that should be checked separately from the operand of the lexical borrow.
1 parent 544b338 commit 258986a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,16 @@ bool CheckerLivenessInfo::compute() {
127127
consumingUse.insert(use);
128128
break;
129129
case OperandOwnership::Borrow: {
130-
bool failed = !liveness.updateForBorrowingOperand(use);
131-
assert(!failed && "Shouldn't see reborrows this early in the pipeline");
130+
if (auto *bbi = dyn_cast<BeginBorrowInst>(user)) {
131+
// Only add borrows to liveness if the borrow isn't lexical. If it is
132+
// a lexical borrow, we have created an entirely new source level
133+
// binding that should be tracked separately.
134+
if (!bbi->isLexical()) {
135+
bool failed = !liveness.updateForBorrowingOperand(use);
136+
assert(!failed &&
137+
"Shouldn't see reborrows this early in the pipeline");
138+
}
139+
}
132140
break;
133141
}
134142
case OperandOwnership::ForwardingBorrow:

test/SILOptimizer/move_function_kills_copyable_addressonly_lets.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,10 @@ public func performMoveOnOneEltOfTPair2<T>(_ p: __owned TPair<T>) {
277277
let _ = _move(p.x) // expected-error {{_move applied to value that the compiler does not support checking}}
278278
nonConsumingUse(p.y)
279279
}
280+
281+
public func multipleVarsWithSubsequentBorrows<T : Equatable>(_ p: T) -> Bool {
282+
let k = p
283+
let k2 = k
284+
let k3 = _move(k)
285+
return k2 == k3
286+
}

test/SILOptimizer/move_function_kills_copyable_values.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,10 @@ public func performMoveOnVarGlobalError() {
248248
public func performMoveOnLetGlobalError() {
249249
let _ = _move(myVarGlobal) // expected-error {{_move applied to value that the compiler does not support checking}}
250250
}
251+
252+
public func multipleVarsWithSubsequentBorrows() -> Bool {
253+
let k = Klass()
254+
let k2 = k
255+
let k3 = _move(k)
256+
return k2 === k3
257+
}

0 commit comments

Comments
 (0)