@@ -104,6 +104,7 @@ extension ProjectedValue {
104104 _ context: some Context ) -> V . Result ? {
105105 var walker = EscapeWalker ( visitor: visitor, complexityBudget: complexityBudget, context)
106106 if walker. walkUp ( addressOrValue: value, path: path. escapePath) == . abortWalk {
107+ walker. visitor. cleanupOnAbort ( )
107108 return nil
108109 }
109110 return walker. visitor. result
@@ -119,6 +120,7 @@ extension ProjectedValue {
119120 _ context: some Context ) -> V . Result ? {
120121 var walker = EscapeWalker ( visitor: visitor, context)
121122 if walker. walkDown ( addressOrValue: value, path: path. escapePath) == . abortWalk {
123+ walker. visitor. cleanupOnAbort ( )
122124 return nil
123125 }
124126 return walker. visitor. result
@@ -182,6 +184,12 @@ extension EscapeVisitor {
182184protocol EscapeVisitorWithResult : EscapeVisitor {
183185 associatedtype Result
184186 var result : Result { get }
187+
188+ mutating func cleanupOnAbort( )
189+ }
190+
191+ extension EscapeVisitorWithResult {
192+ mutating func cleanupOnAbort( ) { }
185193}
186194
187195// FIXME: This ought to be marked private, but that triggers a compiler bug
@@ -482,7 +490,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
482490 // 1. the closure (with the captured values) itself can escape
483491 // 2. something can escape in a destructor when the context is destroyed
484492 return walkDownUses ( ofValue: pai, path: path. with ( knownType: nil ) )
485- case is LoadInst , is LoadWeakInst , is LoadUnownedInst :
493+ case is LoadInst , is LoadWeakInst , is LoadUnownedInst , is LoadBorrowInst :
486494 if !followLoads( at: path. projectionPath) {
487495 return . continueWalk
488496 }
@@ -693,7 +701,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
693701 }
694702 case let ap as ApplyInst :
695703 return walkUpApplyResult ( apply: ap, path: path. with ( knownType: nil ) )
696- case is LoadInst , is LoadWeakInst , is LoadUnownedInst :
704+ case is LoadInst , is LoadWeakInst , is LoadUnownedInst , is LoadBorrowInst :
697705 if !followLoads( at: path. projectionPath) {
698706 // When walking up we shouldn't end up at a load where followLoads is false,
699707 // because going from a (non-followLoads) address to a load always involves a class indirection.
0 commit comments