Skip to content

Commit 001b162

Browse files
committed
Surface addressableForDeps in SILType and FunctionConventions
With this approach, you cannot tell whether a parameter is addressable only from the function type. Instead you need the SILValue that will be passed to the call site.
1 parent 7cecf57 commit 001b162

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceInsertion.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ extension LifetimeDependentApply {
138138
// for consistency, we use yieldAddress if any yielded value is an address.
139139
let targetKind = beginApply.yieldedValues.contains(where: { $0.type.isAddress })
140140
? TargetKind.yieldAddress : TargetKind.yield
141-
info.sources.push(LifetimeSource(targetKind: targetKind, convention: .scope(addressable: false),
141+
info.sources.push(LifetimeSource(targetKind: targetKind,
142+
convention: .scope(addressable: false, addressableForDeps: false),
142143
value: beginApply.token))
143144
}
144145
for operand in applySite.parameterOperands {
@@ -218,7 +219,7 @@ private extension LifetimeDependentApply.LifetimeSourceInfo {
218219
bases.append(source.value)
219220
case .result, .inParameter, .inoutParameter:
220221
// addressable dependencies directly depend on the incoming address.
221-
if context.options.enableAddressDependencies() && source.convention.isAddressable {
222+
if context.options.enableAddressDependencies() && source.convention.isAddressable(for: source.value) {
222223
bases.append(source.value)
223224
return
224225
}

SwiftCompilerSources/Sources/SIL/FunctionConvention.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ extension FunctionConvention {
237237

238238
public enum LifetimeDependenceConvention : CustomStringConvertible {
239239
case inherit
240-
case scope(addressable: Bool)
240+
case scope(addressable: Bool, addressableForDeps: Bool)
241241

242242
public var isScoped: Bool {
243243
switch self {
@@ -248,12 +248,12 @@ public enum LifetimeDependenceConvention : CustomStringConvertible {
248248
}
249249
}
250250

251-
public var isAddressable: Bool {
251+
public func isAddressable(for value: Value) -> Bool {
252252
switch self {
253253
case .inherit:
254254
return false
255-
case let .scope(addressable):
256-
return addressable
255+
case let .scope(addressable, addressableForDeps):
256+
return addressable || (addressableForDeps && value.type.isAddressableForDeps(in: value.parentFunction))
257257
}
258258
}
259259

@@ -313,8 +313,8 @@ extension FunctionConvention {
313313
}
314314
if scope {
315315
let addressable = bridged.checkAddressable(bridgedIndex(parameterIndex: index))
316-
|| bridged.checkConditionallyAddressable(bridgedIndex(parameterIndex: index))
317-
return .scope(addressable: addressable)
316+
let addressableForDeps = bridged.checkConditionallyAddressable(bridgedIndex(parameterIndex: index))
317+
return .scope(addressable: addressable, addressableForDeps: addressableForDeps)
318318
}
319319
return nil
320320
}

include/swift/SIL/SILBridgingImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ bool BridgedType::isMarkedAsImmortal() const {
393393
}
394394

395395
bool BridgedType::isAddressableForDeps(BridgedFunction f) const {
396-
return unbridged().isAddressableForDeps();
396+
return unbridged().isAddressableForDeps(*f.getFunction());
397397
}
398398

399399
SwiftInt BridgedType::getCaseIdxOfEnumType(BridgedStringRef name) const {

0 commit comments

Comments
 (0)