@@ -69,6 +69,12 @@ public enum AccessBase : CustomStringConvertible, Hashable {
6969 /// An indirect result of a `begin_apply`.
7070 case yield( MultipleValueInstructionResult )
7171
72+ /// store_borrow is never the base of a formal access, but calling Value.enclosingScope on an arbitrary address will
73+ /// return it as the accessBase. A store_borrow always stores into an alloc_stack, but it is handled separately
74+ /// because it may be useful for clients to know which value was stored in the temporary stack location for the
75+ /// duration of this borrow scope.
76+ case storeBorrow( StoreBorrowInst )
77+
7278 /// An address which is derived from a `Builtin.RawPointer`.
7379 case pointer( PointerToAddressInst )
7480
@@ -90,6 +96,8 @@ public enum AccessBase : CustomStringConvertible, Hashable {
9096 } else {
9197 self = . unidentified
9298 }
99+ case let sb as StoreBorrowInst :
100+ self = . storeBorrow( sb)
93101 default :
94102 self = . unidentified
95103 }
@@ -105,6 +113,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
105113 case . tail( let rta) : return " tail - \( rta. instance) "
106114 case . argument( let arg) : return " argument - \( arg) "
107115 case . yield( let result) : return " yield - \( result) "
116+ case . storeBorrow( let sb) : return " storeBorrow - \( sb) "
108117 case . pointer( let p) : return " pointer - \( p) "
109118 }
110119 }
@@ -114,7 +123,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
114123 switch self {
115124 case . class, . tail:
116125 return true
117- case . box, . stack, . global, . argument, . yield, . pointer, . unidentified:
126+ case . box, . stack, . global, . argument, . yield, . storeBorrow , . pointer, . unidentified:
118127 return false
119128 }
120129 }
@@ -125,7 +134,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
125134 case . box( let pbi) : return pbi. box
126135 case . class( let rea) : return rea. instance
127136 case . tail( let rta) : return rta. instance
128- case . stack, . global, . argument, . yield, . pointer, . unidentified:
137+ case . stack, . global, . argument, . yield, . storeBorrow , . pointer, . unidentified:
129138 return nil
130139 }
131140 }
@@ -153,7 +162,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
153162 switch self {
154163 case . class( let rea) : return rea. fieldIsLet
155164 case . global( let g) : return g. isLet
156- case . box, . stack, . tail, . argument, . yield, . pointer, . unidentified:
165+ case . box, . stack, . tail, . argument, . yield, . storeBorrow , . pointer, . unidentified:
157166 return false
158167 }
159168 }
@@ -164,7 +173,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
164173 case . box( let pbi) : return pbi. box. referenceRoot is AllocBoxInst
165174 case . class( let rea) : return rea. instance. referenceRoot is AllocRefInstBase
166175 case . tail( let rta) : return rta. instance. referenceRoot is AllocRefInstBase
167- case . stack: return true
176+ case . stack, . storeBorrow : return true
168177 case . global, . argument, . yield, . pointer, . unidentified:
169178 return false
170179 }
@@ -173,7 +182,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
173182 /// True, if the kind of storage of the access is known (e.g. a class property, or global variable).
174183 public var hasKnownStorageKind : Bool {
175184 switch self {
176- case . box, . class, . tail, . stack, . global:
185+ case . box, . class, . tail, . stack, . storeBorrow , . global:
177186 return true
178187 case . argument, . yield, . pointer, . unidentified:
179188 return false
@@ -203,6 +212,8 @@ public enum AccessBase : CustomStringConvertible, Hashable {
203212 return arg1 == arg2
204213 case ( . yield( let baResult1) , . yield( let baResult2) ) :
205214 return baResult1 == baResult2
215+ case ( . storeBorrow( let sb1) , . storeBorrow( let sb2) ) :
216+ return sb1 == sb2
206217 case ( . pointer( let p1) , . pointer( let p2) ) :
207218 return p1 == p2
208219 default :
@@ -260,6 +271,15 @@ public enum AccessBase : CustomStringConvertible, Hashable {
260271 case ( _, . argument( let otherArg) ) :
261272 return argIsDistinct ( otherArg, from: self )
262273
274+ case ( . storeBorrow( let arg) , . storeBorrow( let otherArg) ) :
275+ return arg. allocStack != otherArg. allocStack
276+
277+ // A StoreBorrow location can only be used by other StoreBorrows.
278+ case ( . storeBorrow, _) :
279+ return true
280+ case ( _, . storeBorrow) :
281+ return true
282+
263283 default :
264284 // As we already handled pairs of the same kind, here we handle pairs with different kinds.
265285 // Different storage kinds cannot alias, regardless where the storage comes from.
@@ -591,7 +611,7 @@ extension ValueUseDefWalker where Path == SmallProjectionPath {
591611 return walkUp ( value: rea. instance, path: path. push ( . classField, index: rea. fieldIndex) ) != . abortWalk
592612 case . tail( let rta) :
593613 return walkUp ( value: rta. instance, path: path. push ( . tailElements, index: 0 ) ) != . abortWalk
594- case . stack, . global, . argument, . yield, . pointer, . unidentified:
614+ case . stack, . global, . argument, . yield, . storeBorrow , . pointer, . unidentified:
595615 return false
596616 }
597617 }
0 commit comments