Skip to content

Commit 7811a63

Browse files
committed
Extend LifetimeDependence to allow borrowed value base.
1 parent f5e16b6 commit 7811a63

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func gatherVariableIntroducers(for value: Value, _ context: Context)
9191
/// A lifetime dependence represents a scope in which some parent
9292
/// value is alive and accessible along with a dependent value. All
9393
/// values derived from the dependent value must be used within this
94-
/// scope. This supports diagnostics on non-escapable types.
94+
/// scope. This supports diagnostics on non-copyable and non-escapable types.
9595
///
9696
/// A lifetime dependence is produced by either 'mark_dependence [nonescaping]':
9797
///
@@ -114,6 +114,8 @@ struct LifetimeDependence : CustomStringConvertible {
114114
case yield(Value)
115115
/// An owned value whose OSSA lifetime encloses nonescapable values
116116
case owned(Value)
117+
/// An borrowed value whose OSSA lifetime encloses nonescapable values
118+
case borrowed(Value)
117119
/// Singly-initialized addressable storage (likely for an
118120
/// immutable address-only value). The lifetime extends until the
119121
/// memory is destroyed. e.g. A value produced by an @in
@@ -134,6 +136,7 @@ struct LifetimeDependence : CustomStringConvertible {
134136
case let .access(beginAccess): return beginAccess
135137
case let .yield(value): return value
136138
case let .owned(value): return value
139+
case let .borrowed(value): return value
137140
case let .initialized(initialAddress, _): return initialAddress
138141
case let .unknown(value): return value
139142
}
@@ -149,6 +152,8 @@ struct LifetimeDependence : CustomStringConvertible {
149152
precondition(value.definingInstruction is BeginApplyInst)
150153
case let .owned(value):
151154
precondition(value.ownership == .owned)
155+
case let .borrowed(value):
156+
precondition(value.ownership == .guaranteed)
152157
case let .initialized(initialAddress, initializingStore):
153158
precondition(initialAddress.type.isAddress, "expected an address")
154159
precondition(initialAddress is AllocStackInst
@@ -166,6 +171,7 @@ struct LifetimeDependence : CustomStringConvertible {
166171
case .access: return "Access: "
167172
case .yield: return "Yield: "
168173
case .owned: return "Owned: "
174+
case .borrowed: return "Borrowed: "
169175
case .initialized: return "Initialized: "
170176
case .unknown: return "Unknown: "
171177
}
@@ -225,10 +231,10 @@ extension LifetimeDependence {
225231
return false
226232
}
227233

228-
/// Construct LifetimeDependence from mark_dependence [unresolved]
234+
/// Construct LifetimeDependence from mark_dependence [unresolved] or mark_dependence [nonescaping].
229235
///
230-
/// For any LifetimeDependence constructed from a mark_dependence,
231-
/// its `dependentValue` will be the result of the mark_dependence.
236+
/// For any LifetimeDependence constructed from a mark_dependence, its `dependentValue` will be the result of the
237+
/// mark_dependence.
232238
///
233239
/// TODO: Add SIL verification that all mark_depedence [unresolved]
234240
/// have a valid LifetimeDependence.
@@ -384,16 +390,11 @@ extension LifetimeDependence.Scope {
384390
"guaranteed phis not allowed when diagnosing lifetime dependence")
385391
switch beginBorrow {
386392
case .beginBorrow, .loadBorrow:
387-
let borrowOperand = beginBorrow.baseOperand!
388-
guard let scope = LifetimeDependence.Scope(base: borrowOperand.value,
389-
context) else {
390-
return nil
391-
}
392-
self = scope
393+
self = .borrowed(beginBorrow.value)
393394
case let .beginApply(value):
394395
self = .yield(value)
395-
case .functionArgument:
396-
self = .caller(beginBorrow.value as! FunctionArgument)
396+
case let .functionArgument(arg):
397+
self = .caller(arg)
397398
case .reborrow:
398399
fatalError("reborrows are not supported in diagnostics")
399400
}
@@ -447,6 +448,8 @@ extension LifetimeDependence.Scope {
447448
// how would we ensure that the borrowed mark_dependence value
448449
// is within this value's OSSA lifetime?
449450
return computeLinearLiveness(for: value, context)
451+
case let .borrowed(value):
452+
return computeLinearLiveness(for: value, context)
450453
case let .initialized(initialAddress, initializingStore):
451454
return LifetimeDependence.Scope.computeInitializedRange(
452455
initialAddress: initialAddress, initializingStore: initializingStore,

0 commit comments

Comments
 (0)