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,72 +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, Identifier name,
78- ParsedLifetimeDependenceKind kind =
79- ParsedLifetimeDependenceKind::Default) {
80- 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};
8180 }
8281
83- static LifetimeDependenceSpecifier
84- getImmortalLifetimeDependenceSpecifier (SourceLoc loc) {
85- return {loc, SpecifierKind::Immortal, {}, {}};
82+ static LifetimeEntry getImmortalLifetimeEntry (SourceLoc loc) {
83+ return {loc, LifetimeEntryKind::Immortal, {}, {}};
8684 }
8785
88- static LifetimeDependenceSpecifier getOrderedLifetimeDependenceSpecifier (
89- SourceLoc loc, unsigned index,
90- ParsedLifetimeDependenceKind kind =
91- ParsedLifetimeDependenceKind::Default) {
92- 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};
9391 }
9492
95- static LifetimeDependenceSpecifier getSelfLifetimeDependenceSpecifier (
96- SourceLoc loc, ParsedLifetimeDependenceKind kind =
97- ParsedLifetimeDependenceKind::Default) {
98- return {loc, SpecifierKind::Self, kind, {}};
93+ static LifetimeEntry
94+ getSelfLifetimeEntry (SourceLoc loc,
95+ ParsedLifetimeDependenceKind kind =
96+ ParsedLifetimeDependenceKind::Default) {
97+ return {loc, LifetimeEntryKind::Self, kind, {}};
9998 }
10099
101100 SourceLoc getLoc () const { return loc; }
102101
103- SpecifierKind getSpecifierKind () const { return specifierKind ; }
102+ LifetimeEntryKind getLifetimeEntryKind () const { return lifetimeEntryKind ; }
104103
105104 ParsedLifetimeDependenceKind getParsedLifetimeDependenceKind () const {
106105 return parsedLifetimeDependenceKind;
107106 }
108107
109108 Identifier getName () const {
110- assert (specifierKind == SpecifierKind ::Named);
109+ assert (lifetimeEntryKind == LifetimeEntryKind ::Named);
111110 return value.Named .name ;
112111 }
113112
114113 unsigned getIndex () const {
115- assert (specifierKind == SpecifierKind ::Ordered);
114+ assert (lifetimeEntryKind == LifetimeEntryKind ::Ordered);
116115 return value.Ordered .index ;
117116 }
118117
119118 std::string getParamString () const {
120- switch (specifierKind ) {
121- case SpecifierKind ::Named:
119+ switch (lifetimeEntryKind ) {
120+ case LifetimeEntryKind ::Named:
122121 return value.Named .name .str ().str ();
123- case SpecifierKind ::Self:
122+ case LifetimeEntryKind ::Self:
124123 return " self" ;
125- case SpecifierKind ::Ordered:
124+ case LifetimeEntryKind ::Ordered:
126125 return std::to_string (value.Ordered .index );
127- case SpecifierKind ::Immortal:
126+ case LifetimeEntryKind ::Immortal:
128127 return " immortal" ;
129128 }
130- llvm_unreachable (" Invalid LifetimeDependenceSpecifier::SpecifierKind " );
129+ llvm_unreachable (" Invalid LifetimeEntryKind " );
131130 }
132131
133- std::string getLifetimeDependenceSpecifierString () const {
132+ std::string getDependsOnString () const {
134133 switch (parsedLifetimeDependenceKind) {
135134 case ParsedLifetimeDependenceKind::Default:
136135 return " dependsOn(" + getParamString () + " )" ;
@@ -139,8 +138,7 @@ class LifetimeDependenceSpecifier {
139138 case ParsedLifetimeDependenceKind::Inherit:
140139 return " dependsOn(inherited " + getParamString () + " )" ;
141140 }
142- llvm_unreachable (
143- " Invalid LifetimeDependenceSpecifier::ParsedLifetimeDependenceKind" );
141+ llvm_unreachable (" Invalid LifetimeEntry::ParsedLifetimeDependenceKind" );
144142 }
145143};
146144
@@ -155,10 +153,10 @@ class LifetimeDependenceInfo {
155153 unsigned sourceIndex,
156154 LifetimeDependenceKind kind);
157155
158- // / Builds LifetimeDependenceInfo on a result or parameter from a swift decl
156+ // / Builds LifetimeDependenceInfo from dependsOn type modifier
159157 static std::optional<LifetimeDependenceInfo>
160- fromTypeRepr (AbstractFunctionDecl *afd, LifetimeDependentTypeRepr *typeRepr ,
161- unsigned targetIndex);
158+ fromDependsOn (AbstractFunctionDecl *afd, TypeRepr *targetRepr ,
159+ Type targetType, unsigned targetIndex);
162160
163161 // / Infer LifetimeDependenceInfo on result
164162 static std::optional<LifetimeDependenceInfo> infer (AbstractFunctionDecl *afd);
@@ -173,9 +171,9 @@ class LifetimeDependenceInfo {
173171
174172 // / Builds LifetimeDependenceInfo from SIL function type
175173 static std::optional<LifetimeDependenceInfo>
176- fromTypeRepr (LifetimeDependentTypeRepr *lifetimeDependentRepr,
177- unsigned targetIndex, ArrayRef<SILParameterInfo> params,
178- DeclContext *dc);
174+ fromDependsOn (LifetimeDependentTypeRepr *lifetimeDependentRepr,
175+ unsigned targetIndex, ArrayRef<SILParameterInfo> params,
176+ DeclContext *dc);
179177
180178public:
181179 LifetimeDependenceInfo (IndexSubset *inheritLifetimeParamIndices,
0 commit comments