@@ -91,7 +91,7 @@ func gatherVariableIntroducers(for value: Value, _ context: Context)
91
91
/// A lifetime dependence represents a scope in which some parent
92
92
/// value is alive and accessible along with a dependent value. All
93
93
/// 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.
95
95
///
96
96
/// A lifetime dependence is produced by either 'mark_dependence [nonescaping]':
97
97
///
@@ -114,6 +114,8 @@ struct LifetimeDependence : CustomStringConvertible {
114
114
case yield( Value )
115
115
/// An owned value whose OSSA lifetime encloses nonescapable values
116
116
case owned( Value )
117
+ /// An borrowed value whose OSSA lifetime encloses nonescapable values
118
+ case borrowed( Value )
117
119
/// Singly-initialized addressable storage (likely for an
118
120
/// immutable address-only value). The lifetime extends until the
119
121
/// memory is destroyed. e.g. A value produced by an @in
@@ -134,6 +136,7 @@ struct LifetimeDependence : CustomStringConvertible {
134
136
case let . access( beginAccess) : return beginAccess
135
137
case let . yield( value) : return value
136
138
case let . owned( value) : return value
139
+ case let . borrowed( value) : return value
137
140
case let . initialized( initialAddress, _) : return initialAddress
138
141
case let . unknown( value) : return value
139
142
}
@@ -149,6 +152,8 @@ struct LifetimeDependence : CustomStringConvertible {
149
152
precondition ( value. definingInstruction is BeginApplyInst )
150
153
case let . owned( value) :
151
154
precondition ( value. ownership == . owned)
155
+ case let . borrowed( value) :
156
+ precondition ( value. ownership == . guaranteed)
152
157
case let . initialized( initialAddress, initializingStore) :
153
158
precondition ( initialAddress. type. isAddress, " expected an address " )
154
159
precondition ( initialAddress is AllocStackInst
@@ -166,6 +171,7 @@ struct LifetimeDependence : CustomStringConvertible {
166
171
case . access: return " Access: "
167
172
case . yield: return " Yield: "
168
173
case . owned: return " Owned: "
174
+ case . borrowed: return " Borrowed: "
169
175
case . initialized: return " Initialized: "
170
176
case . unknown: return " Unknown: "
171
177
}
@@ -225,10 +231,10 @@ extension LifetimeDependence {
225
231
return false
226
232
}
227
233
228
- /// Construct LifetimeDependence from mark_dependence [unresolved]
234
+ /// Construct LifetimeDependence from mark_dependence [unresolved] or mark_dependence [nonescaping].
229
235
///
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.
232
238
///
233
239
/// TODO: Add SIL verification that all mark_depedence [unresolved]
234
240
/// have a valid LifetimeDependence.
@@ -384,16 +390,11 @@ extension LifetimeDependence.Scope {
384
390
" guaranteed phis not allowed when diagnosing lifetime dependence " )
385
391
switch beginBorrow {
386
392
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)
393
394
case let . beginApply( value) :
394
395
self = . yield( value)
395
- case . functionArgument:
396
- self = . caller( beginBorrow . value as! FunctionArgument )
396
+ case let . functionArgument( arg ) :
397
+ self = . caller( arg )
397
398
case . reborrow:
398
399
fatalError ( " reborrows are not supported in diagnostics " )
399
400
}
@@ -447,6 +448,8 @@ extension LifetimeDependence.Scope {
447
448
// how would we ensure that the borrowed mark_dependence value
448
449
// is within this value's OSSA lifetime?
449
450
return computeLinearLiveness ( for: value, context)
451
+ case let . borrowed( value) :
452
+ return computeLinearLiveness ( for: value, context)
450
453
case let . initialized( initialAddress, initializingStore) :
451
454
return LifetimeDependence . Scope. computeInitializedRange (
452
455
initialAddress: initialAddress, initializingStore: initializingStore,
0 commit comments