@@ -73,22 +73,20 @@ public struct FunctionConvention : CustomStringConvertible {
73
73
hasLoweredAddresses: hasLoweredAddresses)
74
74
}
75
75
76
- /// If the function result depends on any parameters, return a
77
- /// Collection of LifetimeDependenceConvention indexed on the
78
- /// function parameter.
79
- public var resultDependencies : ResultDependencies ? {
80
- let bridgedDependencies = bridgedFunctionType. SILFunctionType_getLifetimeDependencies ( )
81
- let dependencies = LifetimeDependencies ( bridged: bridgedDependencies)
82
- let targetIndex = parameters. count
83
-
84
- for dependence in dependencies {
85
- if dependence. getTargetIndex ( ) == targetIndex {
86
- return ResultDependencies ( bridged: dependence,
87
- parameterCount: parameters. count,
88
- hasSelfParameter: hasSelfParameter)
89
- }
90
- }
91
- return nil
76
+ /// If the function result depends on any parameters, return a Collection of LifetimeDependenceConventions for the
77
+ /// dependence source parameters.
78
+ public var resultDependencies : LifetimeDependencies ? {
79
+ lifetimeDependencies ( for: parameters. count)
80
+ }
81
+
82
+ /// If the parameter indexed by 'targetParameterIndex' is the target of any dependencies on other parameters, return a
83
+ /// Collection of LifetimeDependenceConventions for the dependence source parameters.
84
+ public func parameterDependencies( for targetParameterIndex: Int ) -> LifetimeDependencies ? {
85
+ lifetimeDependencies ( for: targetParameterIndex)
86
+ }
87
+
88
+ public func hasLifetimeDependencies( ) -> Bool {
89
+ return bridgedFunctionType. SILFunctionType_getLifetimeDependencies ( ) . count ( ) != 0
92
90
}
93
91
94
92
public var description : String {
@@ -248,28 +246,22 @@ public enum LifetimeDependenceConvention : CustomStringConvertible {
248
246
}
249
247
250
248
extension FunctionConvention {
251
- struct LifetimeDependencies : Collection {
252
- let bridged : BridgedLifetimeDependenceInfoArray
253
-
254
- var startIndex : Int { 0 }
255
-
256
- var endIndex : Int { bridged. count ( ) }
257
-
258
- func index( after index: Int ) -> Int {
259
- return index + 1
260
- }
261
- // Create a Swift LifetimeDependenceInfo for BridgedLifetimeDependenceInfo if this method needs
262
- // to be exposed outside FunctionConvention.
263
- // That will likely need bridging IndexSubset to Swift.
264
- subscript( _ index: Int ) -> BridgedLifetimeDependenceInfo {
265
- return bridged. at ( index)
249
+ // 'targetIndex' is either the parameter index or parameters.count for the function result.
250
+ private func lifetimeDependencies( for targetIndex: Int ) -> LifetimeDependencies ? {
251
+ let bridgedDependenceInfoArray = bridgedFunctionType. SILFunctionType_getLifetimeDependencies ( )
252
+ for infoIndex in 0 ..< bridgedDependenceInfoArray. count ( ) {
253
+ let bridgedDependenceInfo = bridgedDependenceInfoArray. at ( infoIndex)
254
+ if bridgedDependenceInfo. targetIndex == targetIndex {
255
+ return LifetimeDependencies ( bridged: bridgedDependenceInfo,
256
+ parameterCount: parameters. count,
257
+ hasSelfParameter: hasSelfParameter)
258
+ }
266
259
}
260
+ return nil
267
261
}
268
- }
269
262
270
- extension FunctionConvention {
271
263
/// Collection of LifetimeDependenceConvention? that parallels parameters.
272
- public struct ResultDependencies : Collection , CustomStringConvertible {
264
+ public struct LifetimeDependencies : Collection , CustomStringConvertible {
273
265
let bridged : BridgedLifetimeDependenceInfo
274
266
let paramCount : Int
275
267
let hasSelfParam : Bool
0 commit comments