Skip to content

Commit 1bf600d

Browse files
committed
[NFC] Add ApplySite.fullyAssigns(Operand) query
1 parent 3bb3e4d commit 1bf600d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

SwiftCompilerSources/Sources/SIL/ApplySite.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ public protocol ApplySite : Instruction {
122122
var unappliedArgumentCount: Int { get }
123123
}
124124

125+
// lattice: no -> lifetime -> value
126+
public enum IsFullyAssigned {
127+
case no
128+
case lifetime
129+
case value
130+
131+
var reassignsLifetime: Bool {
132+
switch self {
133+
case .no:
134+
false
135+
case .lifetime, .value:
136+
true
137+
}
138+
}
139+
}
140+
125141
extension ApplySite {
126142
public var callee: Value { operands[ApplyOperandConventions.calleeIndex].value }
127143

@@ -260,6 +276,26 @@ extension ApplySite {
260276
return operandConventions.parameterDependence(targetOperandIndex: target.index, sourceOperandIndex: source.index)
261277
}
262278

279+
/// Returns .value if this apply fully assigns 'operand' (via @out).
280+
///
281+
/// Returns .lifetime if this 'operand' is a non-Escapable inout argument and its lifetime is not propagated by the
282+
/// call ('@lifetime(param: copy param)' is not present).
283+
public func fullyAssigns(operand: Operand) -> IsFullyAssigned {
284+
switch convention(of: operand) {
285+
case .indirectOut:
286+
return .value
287+
case .indirectInout:
288+
if let argIdx = calleeArgumentIndex(of: operand),
289+
calleeArgumentConventions.parameterDependence(targetArgumentIndex: argIdx, sourceArgumentIndex: argIdx) == nil
290+
{
291+
return .lifetime
292+
}
293+
return .no
294+
default:
295+
return .no
296+
}
297+
}
298+
263299
public var yieldConventions: YieldConventions {
264300
YieldConventions(convention: functionConvention)
265301
}

0 commit comments

Comments
 (0)