Skip to content

Commit 9264e7a

Browse files
committed
Update SwiftCompilerSources AllocBoxToStack to handle mark_dep.
Handle the easy case in which the promoted box is the base operand of a mark_dep. This requires nothing more than setting the base operand to the new stack address. Required for move-only checking. Otherwise, we get an incredibly bizarre compiler error: noncopyable 'foo' cannot be consumed when captured by an escaping closure The legacy pass was updated first for 6.2.
1 parent 14a0bff commit 9264e7a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocBoxToStack.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ private func canPromote(allocBox: AllocBoxInst) -> (promotableArguments: [Functi
154154
fallthrough
155155
case is MarkUninitializedInst, is CopyValueInst, is MoveValueInst:
156156
worklist.pushIfNotVisited(use.instruction as! SingleValueInstruction)
157+
case let markDep as MarkDependenceInstruction:
158+
if markDep.baseOperand == use {
159+
// mark_dependence base value uses will be directly converted to base address uses.
160+
break
161+
}
162+
return nil
157163
case let apply as ApplySite:
158164
if apply.isCallee(operand: use) {
159165
// Calling the closure does not escape the closure value.
@@ -226,6 +232,9 @@ private struct FunctionSpecializations {
226232
// First, replace the instruction with the original `box`, which adds more uses to `box`.
227233
// In a later iteration those additional uses will be handled.
228234
(user as! SingleValueInstruction).replace(with: box, context)
235+
case let markDep as MarkDependenceInstruction:
236+
assert(markDep.baseOperand == use)
237+
markDep.baseOperand.set(to: stack, context)
229238
case let apply as ApplySite:
230239
specialize(apply: apply, context)
231240
default:

test/SILOptimizer/allocbox_to_stack_ne.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-sil-opt -enable-experimental-feature LifetimeDependence -allocbox-to-stack %s | %FileCheck %s
2+
// RUN: %target-sil-opt -enable-experimental-feature LifetimeDependence -legacy-allocbox-to-stack %s | %FileCheck %s
23

34
// REQUIRES: swift_feature_LifetimeDependence
45

0 commit comments

Comments
 (0)