Skip to content

Commit 51c64d5

Browse files
committed
Update SideEffects for borrow accessors returning addresses
Add a read effect on the self parameter. Without this, the self parameter can get dead code eliminated by the GenericSpecializer.
1 parent db0725c commit 51c64d5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ private struct CollectedEffects {
254254
// effect, it would not give any significant benefit in any of our current optimizations.
255255
addEffects(.destroy, to: inst.operands[0].value, fromInitialPath: SmallProjectionPath(.anyValueFields))
256256

257+
case is ReturnInst:
258+
if inst.parentFunction.convention.hasGuaranteedAddressResult {
259+
addEffects(.read, to: inst.operands[0].value)
260+
}
261+
257262
default:
258263
if inst.mayRelease {
259264
globalEffects = .worstEffects

SwiftCompilerSources/Sources/SIL/FunctionConvention.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ public struct FunctionConvention : CustomStringConvertible {
9898
return SILFunctionType_getLifetimeDependencies(functionType.bridged).count() != 0
9999
}
100100

101+
public var hasGuaranteedResult: Bool {
102+
if results.count != 1 {
103+
return false
104+
}
105+
return results[0].convention == .guaranteed
106+
}
107+
108+
public var hasGuaranteedAddressResult: Bool {
109+
if results.count != 1 {
110+
return false
111+
}
112+
return results[0].convention == .guaranteedAddress
113+
}
114+
101115
public var description: String {
102116
var str = functionType.description
103117
for paramIdx in 0..<parameters.count {

0 commit comments

Comments
 (0)