@@ -51,11 +51,12 @@ struct LifetimeDescriptor {
5151 } Named;
5252 struct {
5353 unsigned index;
54+ bool isAddress;
5455 } Ordered;
5556 struct {
5657 } Self;
5758 Value (StringRef name) : Named ({name}) {}
58- Value (unsigned index) : Ordered ({index}) {}
59+ Value (unsigned index, bool isAddress ) : Ordered ({index, isAddress }) {}
5960 Value () : Self () {}
6061 } value;
6162
@@ -71,10 +72,10 @@ struct LifetimeDescriptor {
7172 SourceLoc loc)
7273 : value{name}, kind(DescriptorKind::Named),
7374 parsedLifetimeDependenceKind (parsedLifetimeDependenceKind), loc(loc) {}
74- LifetimeDescriptor (unsigned index,
75+ LifetimeDescriptor (unsigned index, bool isAddress,
7576 ParsedLifetimeDependenceKind parsedLifetimeDependenceKind,
7677 SourceLoc loc)
77- : value{index}, kind(DescriptorKind::Ordered),
78+ : value{index, isAddress }, kind(DescriptorKind::Ordered),
7879 parsedLifetimeDependenceKind (parsedLifetimeDependenceKind), loc(loc) {}
7980 LifetimeDescriptor (ParsedLifetimeDependenceKind parsedLifetimeDependenceKind,
8081 SourceLoc loc)
@@ -91,8 +92,9 @@ struct LifetimeDescriptor {
9192 static LifetimeDescriptor
9293 forOrdered (unsigned index,
9394 ParsedLifetimeDependenceKind parsedLifetimeDependenceKind,
94- SourceLoc loc) {
95- return {index, parsedLifetimeDependenceKind, loc};
95+ SourceLoc loc,
96+ bool isAddress = false ) {
97+ return {index, isAddress, parsedLifetimeDependenceKind, loc};
9698 }
9799 static LifetimeDescriptor
98100 forSelf (ParsedLifetimeDependenceKind parsedLifetimeDependenceKind,
@@ -113,6 +115,12 @@ struct LifetimeDescriptor {
113115 assert (kind == DescriptorKind::Ordered);
114116 return value.Ordered .index ;
115117 }
118+
119+ bool isAddressable () const {
120+ return kind == DescriptorKind::Ordered
121+ ? value.Ordered .isAddress
122+ : false ;
123+ }
116124
117125 DescriptorKind getDescriptorKind () const { return kind; }
118126
@@ -206,8 +214,9 @@ class LifetimeEntry final
206214class LifetimeDependenceInfo {
207215 IndexSubset *inheritLifetimeParamIndices;
208216 IndexSubset *scopeLifetimeParamIndices;
217+ llvm::PointerIntPair<IndexSubset *, 1 , bool >
218+ addressableParamIndicesAndImmortal;
209219 unsigned targetIndex;
210- bool immortal;
211220
212221 static LifetimeDependenceInfo getForIndex (AbstractFunctionDecl *afd,
213222 unsigned targetIndex,
@@ -238,11 +247,14 @@ class LifetimeDependenceInfo {
238247public:
239248 LifetimeDependenceInfo (IndexSubset *inheritLifetimeParamIndices,
240249 IndexSubset *scopeLifetimeParamIndices,
241- unsigned targetIndex, bool isImmortal)
250+ unsigned targetIndex, bool isImmortal,
251+ // set during SIL type lowering
252+ IndexSubset *addressableParamIndices = nullptr )
242253 : inheritLifetimeParamIndices(inheritLifetimeParamIndices),
243254 scopeLifetimeParamIndices (scopeLifetimeParamIndices),
244- targetIndex(targetIndex), immortal(isImmortal) {
245- assert (isImmortal || inheritLifetimeParamIndices ||
255+ addressableParamIndicesAndImmortal(addressableParamIndices, isImmortal),
256+ targetIndex(targetIndex) {
257+ assert (this ->isImmortal () || inheritLifetimeParamIndices ||
246258 scopeLifetimeParamIndices);
247259 assert (!inheritLifetimeParamIndices ||
248260 !inheritLifetimeParamIndices->isEmpty ());
@@ -252,11 +264,11 @@ class LifetimeDependenceInfo {
252264 operator bool () const { return !empty (); }
253265
254266 bool empty () const {
255- return !immortal && inheritLifetimeParamIndices == nullptr &&
267+ return !isImmortal () && inheritLifetimeParamIndices == nullptr &&
256268 scopeLifetimeParamIndices == nullptr ;
257269 }
258270
259- bool isImmortal () const { return immortal ; }
271+ bool isImmortal () const { return addressableParamIndicesAndImmortal. getInt () ; }
260272
261273 unsigned getTargetIndex () const { return targetIndex; }
262274
@@ -266,11 +278,18 @@ class LifetimeDependenceInfo {
266278 bool hasScopeLifetimeParamIndices () const {
267279 return scopeLifetimeParamIndices != nullptr ;
268280 }
281+ bool hasAddressableParamIndices () const {
282+ return addressableParamIndicesAndImmortal.getPointer () != nullptr ;
283+ }
269284
270285 IndexSubset *getInheritIndices () const { return inheritLifetimeParamIndices; }
271286
272287 IndexSubset *getScopeIndices () const { return scopeLifetimeParamIndices; }
273288
289+ IndexSubset *getAddressableIndices () const {
290+ return addressableParamIndicesAndImmortal.getPointer ();
291+ }
292+
274293 bool checkInherit (int index) const {
275294 return inheritLifetimeParamIndices
276295 && inheritLifetimeParamIndices->contains (index);
@@ -300,15 +319,15 @@ class LifetimeDependenceInfo {
300319 return this ->isImmortal () == other.isImmortal () &&
301320 this ->getTargetIndex () == other.getTargetIndex () &&
302321 this ->getInheritIndices () == other.getInheritIndices () &&
322+ this ->getAddressableIndices () == other.getAddressableIndices () &&
303323 this ->getScopeIndices () == other.getScopeIndices ();
304324 }
305325
306326 bool operator !=(const LifetimeDependenceInfo &other) const {
307- return this ->isImmortal () != other.isImmortal () &&
308- this ->getTargetIndex () != other.getTargetIndex () &&
309- this ->getInheritIndices () != other.getInheritIndices () &&
310- this ->getScopeIndices () != other.getScopeIndices ();
327+ return !(*this == other);
311328 }
329+
330+ SWIFT_DEBUG_DUMPER (dump());
312331};
313332
314333std::optional<LifetimeDependenceInfo>
0 commit comments