@@ -236,32 +236,22 @@ private struct LifetimeVariable {
236
236
self = Self ( accessBase: value. accessBase, context)
237
237
return
238
238
}
239
- if let firstIntroducer = getFirstBorrowIntroducer ( of: value, context) {
239
+ if let firstIntroducer = getFirstVariableIntroducer ( of: value, context) {
240
240
self = Self ( introducer: firstIntroducer)
241
241
return
242
242
}
243
243
self . varDecl = nil
244
244
self . sourceLoc = nil
245
245
}
246
246
247
- // FUTURE: consider diagnosing multiple variable introducers. It's
248
- // unclear how more than one can happen.
249
- private func getFirstBorrowIntroducer( of value: Value ,
250
- _ context: some Context )
251
- -> Value ? {
252
- var introducers = Stack < Value > ( context)
253
- gatherBorrowIntroducers ( for: value, in: & introducers, context)
254
- return introducers. pop ( )
255
- }
256
-
257
- private func getFirstLifetimeIntroducer( of value: Value ,
258
- _ context: some Context )
259
- -> Value ? {
247
+ private func getFirstVariableIntroducer( of value: Value , _ context: some Context ) -> Value ? {
260
248
var introducer : Value ?
261
- _ = visitLifetimeIntroducers ( for : value , context) {
249
+ var useDefVisitor = VariableIntroducerUseDefWalker ( context) {
262
250
introducer = $0
263
251
return . abortWalk
264
252
}
253
+ defer { useDefVisitor. deinitialize ( ) }
254
+ _ = useDefVisitor. walkUp ( valueOrAddress: value)
265
255
return introducer
266
256
}
267
257
@@ -283,12 +273,11 @@ private struct LifetimeVariable {
283
273
private init ( accessBase: AccessBase , _ context: some Context ) {
284
274
switch accessBase {
285
275
case . box( let projectBox) :
286
- if let box = getFirstLifetimeIntroducer ( of: projectBox. box, context) {
287
- self = Self ( introducer: box)
288
- }
289
- // We should always find an introducer since boxes are nontrivial.
290
- self . varDecl = nil
291
- self . sourceLoc = nil
276
+ // Note: referenceRoot looks through `begin_borrow [var_decl]` and `move_value [var_decl]`. But the box should
277
+ // never be produced by one of these, except when it is redundant with the `alloc_box` VarDecl. It does not seem
278
+ // possible for a box to be moved/borrowed directly into another variable's box. Reassignment always loads/stores
279
+ // the value.
280
+ self = Self ( introducer: projectBox. box. referenceRoot)
292
281
case . stack( let allocStack) :
293
282
self = Self ( introducer: allocStack)
294
283
case . global( let globalVar) :
0 commit comments