@@ -204,7 +204,7 @@ struct InteriorLivenessResult: CustomDebugStringConvertible {
204
204
/// The implementation may recursively call back to the top-level
205
205
/// entry points. Additionally, the implementation may recurse into inner
206
206
/// borrow scopes, skipping over the uses within inner scopes using:
207
- /// - `visitInnerBorrowUses(of: BorrowingInstruction)`
207
+ /// - `visitInnerBorrowUses(of: BorrowingInstruction, operand: )`
208
208
/// - `visitInnerScopeUses(of: Value)`
209
209
///
210
210
/// Visitors implement:
@@ -251,21 +251,18 @@ protocol OwnershipUseVisitor {
251
251
/// `isInnerLifetime` indicates whether `operand` uses the original
252
252
/// OSSA lifetime. This use ends the original lifetime if
253
253
/// (!isInnerLifetime && use.endsLifetime).
254
- mutating func ownershipLeafUse( of operand: Operand , isInnerLifetime: Bool )
255
- -> WalkResult
254
+ mutating func ownershipLeafUse( of operand: Operand , isInnerLifetime: Bool ) -> WalkResult
256
255
257
256
/// A forwarding operand.
258
257
///
259
258
/// Use ForwardingInstruction or ForwardingDefUseWalker to handle
260
259
/// downstream uses.
261
260
///
262
261
/// If `isInnerLifetime` is true, then the value depends on an inner borrow.
263
- mutating func forwardingUse( of operand: Operand , isInnerLifetime: Bool )
264
- -> WalkResult
262
+ mutating func forwardingUse( of operand: Operand , isInnerLifetime: Bool ) -> WalkResult
265
263
266
264
/// A use that projects an address.
267
- mutating func interiorPointerUse( of: Operand , into address: Value )
268
- -> WalkResult
265
+ mutating func interiorPointerUse( of: Operand , into address: Value ) -> WalkResult
269
266
270
267
/// A use that escapes information from its operand's value.
271
268
///
@@ -280,22 +277,19 @@ protocol OwnershipUseVisitor {
280
277
/// there are no explicit scope-ending operations. Instead
281
278
/// BorrowingInstruction.scopeEndingOperands will return the final
282
279
/// consumes in the dependent value's forwarding chain.
283
- mutating func dependentUse( of operand: Operand , into value: Value )
284
- -> WalkResult
280
+ mutating func dependentUse( of operand: Operand , into value: Value ) -> WalkResult
285
281
286
282
/// A use that is scoped to an inner borrow scope.
287
283
///
288
284
/// Call `visitInnerScopeUses(of:)` to recursively classify any
289
285
/// scope-ending uses and forwarded dependent values.
290
- mutating func borrowingUse( of operand: Operand ,
291
- by borrowInst: BorrowingInstruction ) -> WalkResult
286
+ mutating func borrowingUse( of operand: Operand , by borrowInst: BorrowingInstruction ) -> WalkResult
292
287
293
288
/// A reborrow operand.
294
289
///
295
- /// Call `visitInnerScopeUses()` to recursively classify scope-ending
296
- /// uses (reborrow and end_borrow).
297
- mutating func reborrowingUse( of operand: Operand , isInnerLifetime: Bool )
298
- -> WalkResult
290
+ /// Call `visitInnerBorrowUses(of:)` or `visitInnerScopeUses(of:)` to recursively classify scope-ending uses (such as
291
+ /// reborrow and end_borrow).
292
+ mutating func reborrowingUse( of operand: Operand , isInnerLifetime: Bool ) -> WalkResult
299
293
}
300
294
301
295
extension OwnershipUseVisitor {
@@ -320,7 +314,7 @@ extension OwnershipUseVisitor {
320
314
/// adjacent phis and treat them like inner borrows.
321
315
///
322
316
/// This is only called for uses in the outer lifetime.
323
- mutating func visitAllUses( of: Value ) -> WalkResult {
317
+ mutating func visitAllUses( of value : Value ) -> WalkResult {
324
318
switch value. ownership {
325
319
case . owned:
326
320
return value. uses. ignoreTypeDependence. walk { classifyOwned ( operand: $0) }
@@ -351,11 +345,9 @@ extension OwnershipUseVisitor {
351
345
}
352
346
}
353
347
}
354
- // When a borrow introduces an owned value, each OSSA lifetime is
355
- // effectively a separate borrow scope. A destroy ends the borrow
356
- // scope, while a forwarding consume effectively "reborrows".
357
- assert ( value. ownership == . owned,
358
- " inner value must be a reborrow or owned forward " )
348
+ // When a borrow introduces an owned value, each OSSA lifetime is effectively a separate borrow scope. A destroy
349
+ // ends the borrow scope, while a forwarding consume effectively "reborrows".
350
+ assert ( value. ownership == . owned, " inner value must be a reborrow or owned forward " )
359
351
return value. uses. endingLifetime. walk {
360
352
switch $0. ownership {
361
353
case . forwardingConsume:
@@ -370,16 +362,14 @@ extension OwnershipUseVisitor {
370
362
371
363
// Visit uses of borrowing instruction (operandOwnerhip == .borrow),
372
364
// skipping uses within the borrow scope.
373
- mutating func visitInnerScopeUses( of borrowInst: BorrowingInstruction )
374
- -> WalkResult {
375
- // If a borrowed value is introduced, then handle the inner scope.
365
+ mutating func visitInnerBorrowUses( of borrowInst: BorrowingInstruction , operand: Operand ) -> WalkResult {
366
+ // Delegate begin_borrow to visitInnerScopeUses, because it dispatches to reborrowingUse.
376
367
if let beginBorrow = BeginBorrowValue ( resultOf: borrowInst) {
377
368
return visitInnerScopeUses ( of: beginBorrow. value)
378
369
}
379
- // Otherwise, directly visit the scope ending uses.
370
+ // Otherwise, directly visit the scope ending uses as leaf uses .
380
371
//
381
- // TODO: remove this stack by changign visitScopeEndingOperands to
382
- // take a non-escaping closure that can call ownershipLeafUse.
372
+ // TODO: remove this stack by changing visitScopeEndingOperands to take a non-escaping closure.
383
373
var stack = Stack < Operand > ( context)
384
374
defer { stack. deinitialize ( ) }
385
375
_ = borrowInst. visitScopeEndingOperands ( context) {
@@ -406,8 +396,7 @@ extension OwnershipUseVisitor {
406
396
case . pointerEscape:
407
397
return pointerEscapingUse ( of: operand)
408
398
409
- case . instantaneousUse, . forwardingUnowned, . unownedInstantaneousUse,
410
- . bitwiseEscape:
399
+ case . instantaneousUse, . forwardingUnowned, . unownedInstantaneousUse, . bitwiseEscape:
411
400
return ownershipLeafUse ( of: operand, isInnerLifetime: false )
412
401
413
402
case . borrow:
@@ -436,8 +425,7 @@ extension OwnershipUseVisitor {
436
425
}
437
426
return pointerEscapingUse ( of: operand)
438
427
439
- case . instantaneousUse, . forwardingUnowned, . unownedInstantaneousUse,
440
- . bitwiseEscape, . endBorrow:
428
+ case . instantaneousUse, . forwardingUnowned, . unownedInstantaneousUse, . bitwiseEscape, . endBorrow:
441
429
return ownershipLeafUse ( of: operand, isInnerLifetime: false )
442
430
443
431
case . reborrow:
@@ -457,8 +445,7 @@ extension OwnershipUseVisitor {
457
445
}
458
446
}
459
447
460
- private mutating func visitBorrowingUse( of operand: Operand )
461
- -> WalkResult {
448
+ private mutating func visitBorrowingUse( of operand: Operand ) -> WalkResult {
462
449
switch operand. instruction {
463
450
case let pai as PartialApplyInst :
464
451
assert ( !pai. mayEscape)
@@ -472,8 +459,7 @@ extension OwnershipUseVisitor {
472
459
}
473
460
}
474
461
475
- private mutating func visitInteriorPointerUse( of operand: Operand )
476
- -> WalkResult {
462
+ private mutating func visitInteriorPointerUse( of operand: Operand ) -> WalkResult {
477
463
switch operand. instruction {
478
464
case is RefTailAddrInst , is RefElementAddrInst , is ProjectBoxInst ,
479
465
is OpenExistentialBoxInst :
0 commit comments