1- // ===--- LifetimeDependenceSpecifiers .h ------------------------*- C++ -*-===//
1+ // ===--- LifetimeDependence .h --------- ------------------------*- C++ -*-===//
22//
33// This source file is part of the Swift.org open source project
44//
@@ -43,13 +43,12 @@ enum class ParsedLifetimeDependenceKind : uint8_t {
4343
4444enum class LifetimeDependenceKind : uint8_t { Inherit = 0 , Scope };
4545
46- class LifetimeDependenceSpecifier {
47- public:
48- enum class SpecifierKind { Named, Ordered, Self, Immortal };
46+ enum class LifetimeEntryKind { Named, Ordered, Self, Immortal };
4947
48+ class LifetimeEntry {
5049private:
5150 SourceLoc loc;
52- SpecifierKind specifierKind ;
51+ LifetimeEntryKind lifetimeEntryKind ;
5352 ParsedLifetimeDependenceKind parsedLifetimeDependenceKind;
5453 union Value {
5554 struct {
@@ -65,68 +64,72 @@ class LifetimeDependenceSpecifier {
6564 Value () {}
6665 } value;
6766
68- LifetimeDependenceSpecifier (
69- SourceLoc loc, SpecifierKind specifierKind ,
70- ParsedLifetimeDependenceKind parsedLifetimeDependenceKind, Value value)
71- : loc(loc), specifierKind(specifierKind ),
67+ LifetimeEntry (SourceLoc loc, LifetimeEntryKind lifetimeEntryKind,
68+ ParsedLifetimeDependenceKind parsedLifetimeDependenceKind ,
69+ Value value)
70+ : loc(loc), lifetimeEntryKind(lifetimeEntryKind ),
7271 parsedLifetimeDependenceKind (parsedLifetimeDependenceKind),
7372 value(value) {}
7473
7574public:
76- static LifetimeDependenceSpecifier getNamedLifetimeDependenceSpecifier (
77- SourceLoc loc, ParsedLifetimeDependenceKind kind, Identifier name) {
78- return {loc, SpecifierKind::Named, kind, name};
75+ static LifetimeEntry
76+ getNamedLifetimeEntry (SourceLoc loc, Identifier name,
77+ ParsedLifetimeDependenceKind kind =
78+ ParsedLifetimeDependenceKind::Default) {
79+ return {loc, LifetimeEntryKind::Named, kind, name};
7980 }
8081
81- static LifetimeDependenceSpecifier
82- getImmortalLifetimeDependenceSpecifier (SourceLoc loc) {
83- return {loc, SpecifierKind::Immortal, {}, {}};
82+ static LifetimeEntry getImmortalLifetimeEntry (SourceLoc loc) {
83+ return {loc, LifetimeEntryKind::Immortal, {}, {}};
8484 }
8585
86- static LifetimeDependenceSpecifier getOrderedLifetimeDependenceSpecifier (
87- SourceLoc loc, ParsedLifetimeDependenceKind kind, unsigned index) {
88- return {loc, SpecifierKind::Ordered, kind, index};
86+ static LifetimeEntry
87+ getOrderedLifetimeEntry (SourceLoc loc, unsigned index,
88+ ParsedLifetimeDependenceKind kind =
89+ ParsedLifetimeDependenceKind::Default) {
90+ return {loc, LifetimeEntryKind::Ordered, kind, index};
8991 }
9092
91- static LifetimeDependenceSpecifier
92- getSelfLifetimeDependenceSpecifier (SourceLoc loc,
93- ParsedLifetimeDependenceKind kind) {
94- return {loc, SpecifierKind::Self, kind, {}};
93+ static LifetimeEntry
94+ getSelfLifetimeEntry (SourceLoc loc,
95+ ParsedLifetimeDependenceKind kind =
96+ ParsedLifetimeDependenceKind::Default) {
97+ return {loc, LifetimeEntryKind::Self, kind, {}};
9598 }
9699
97100 SourceLoc getLoc () const { return loc; }
98101
99- SpecifierKind getSpecifierKind () const { return specifierKind ; }
102+ LifetimeEntryKind getLifetimeEntryKind () const { return lifetimeEntryKind ; }
100103
101104 ParsedLifetimeDependenceKind getParsedLifetimeDependenceKind () const {
102105 return parsedLifetimeDependenceKind;
103106 }
104107
105108 Identifier getName () const {
106- assert (specifierKind == SpecifierKind ::Named);
109+ assert (lifetimeEntryKind == LifetimeEntryKind ::Named);
107110 return value.Named .name ;
108111 }
109112
110113 unsigned getIndex () const {
111- assert (specifierKind == SpecifierKind ::Ordered);
114+ assert (lifetimeEntryKind == LifetimeEntryKind ::Ordered);
112115 return value.Ordered .index ;
113116 }
114117
115118 std::string getParamString () const {
116- switch (specifierKind ) {
117- case SpecifierKind ::Named:
119+ switch (lifetimeEntryKind ) {
120+ case LifetimeEntryKind ::Named:
118121 return value.Named .name .str ().str ();
119- case SpecifierKind ::Self:
122+ case LifetimeEntryKind ::Self:
120123 return " self" ;
121- case SpecifierKind ::Ordered:
124+ case LifetimeEntryKind ::Ordered:
122125 return std::to_string (value.Ordered .index );
123- case SpecifierKind ::Immortal:
126+ case LifetimeEntryKind ::Immortal:
124127 return " immortal" ;
125128 }
126- llvm_unreachable (" Invalid LifetimeDependenceSpecifier::SpecifierKind " );
129+ llvm_unreachable (" Invalid LifetimeEntryKind " );
127130 }
128131
129- std::string getLifetimeDependenceSpecifierString () const {
132+ std::string getDependsOnString () const {
130133 switch (parsedLifetimeDependenceKind) {
131134 case ParsedLifetimeDependenceKind::Default:
132135 return " dependsOn(" + getParamString () + " )" ;
@@ -135,8 +138,7 @@ class LifetimeDependenceSpecifier {
135138 case ParsedLifetimeDependenceKind::Inherit:
136139 return " dependsOn(inherited " + getParamString () + " )" ;
137140 }
138- llvm_unreachable (
139- " Invalid LifetimeDependenceSpecifier::ParsedLifetimeDependenceKind" );
141+ llvm_unreachable (" Invalid LifetimeEntry::ParsedLifetimeDependenceKind" );
140142 }
141143};
142144
@@ -151,10 +153,14 @@ class LifetimeDependenceInfo {
151153 unsigned sourceIndex,
152154 LifetimeDependenceKind kind);
153155
154- // / Builds LifetimeDependenceInfo on a result or parameter from a swift decl
156+ // / Builds LifetimeDependenceInfo from @lifetime attribute
157+ static std::optional<ArrayRef<LifetimeDependenceInfo>>
158+ fromLifetimeAttribute (AbstractFunctionDecl *afd);
159+
160+ // / Builds LifetimeDependenceInfo from dependsOn type modifier
155161 static std::optional<LifetimeDependenceInfo>
156- fromTypeRepr (AbstractFunctionDecl *afd, LifetimeDependentTypeRepr *typeRepr ,
157- unsigned targetIndex);
162+ fromDependsOn (AbstractFunctionDecl *afd, TypeRepr *targetRepr ,
163+ Type targetType, unsigned targetIndex);
158164
159165 // / Infer LifetimeDependenceInfo on result
160166 static std::optional<LifetimeDependenceInfo> infer (AbstractFunctionDecl *afd);
@@ -169,9 +175,9 @@ class LifetimeDependenceInfo {
169175
170176 // / Builds LifetimeDependenceInfo from SIL function type
171177 static std::optional<LifetimeDependenceInfo>
172- fromTypeRepr (LifetimeDependentTypeRepr *lifetimeDependentRepr,
173- unsigned targetIndex, ArrayRef<SILParameterInfo> params,
174- DeclContext *dc);
178+ fromDependsOn (LifetimeDependentTypeRepr *lifetimeDependentRepr,
179+ unsigned targetIndex, ArrayRef<SILParameterInfo> params,
180+ DeclContext *dc);
175181
176182public:
177183 LifetimeDependenceInfo (IndexSubset *inheritLifetimeParamIndices,
0 commit comments