1
- // ===--- LifetimeDependenceSpecifiers .h ------------------------*- C++ -*-===//
1
+ // ===--- LifetimeDependence .h --------- ------------------------*- C++ -*-===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
@@ -43,13 +43,12 @@ enum class ParsedLifetimeDependenceKind : uint8_t {
43
43
44
44
enum class LifetimeDependenceKind : uint8_t { Inherit = 0 , Scope };
45
45
46
- class LifetimeDependenceSpecifier {
47
- public:
48
- enum class SpecifierKind { Named, Ordered, Self, Immortal };
46
+ enum class LifetimeEntryKind { Named, Ordered, Self, Immortal };
49
47
48
+ class LifetimeEntry {
50
49
private:
51
50
SourceLoc loc;
52
- SpecifierKind specifierKind ;
51
+ LifetimeEntryKind lifetimeEntryKind ;
53
52
ParsedLifetimeDependenceKind parsedLifetimeDependenceKind;
54
53
union Value {
55
54
struct {
@@ -65,72 +64,72 @@ class LifetimeDependenceSpecifier {
65
64
Value () {}
66
65
} value;
67
66
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 ),
72
71
parsedLifetimeDependenceKind (parsedLifetimeDependenceKind),
73
72
value(value) {}
74
73
75
74
public:
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};
81
80
}
82
81
83
- static LifetimeDependenceSpecifier
84
- getImmortalLifetimeDependenceSpecifier (SourceLoc loc) {
85
- return {loc, SpecifierKind::Immortal, {}, {}};
82
+ static LifetimeEntry getImmortalLifetimeEntry (SourceLoc loc) {
83
+ return {loc, LifetimeEntryKind::Immortal, {}, {}};
86
84
}
87
85
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};
93
91
}
94
92
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, {}};
99
98
}
100
99
101
100
SourceLoc getLoc () const { return loc; }
102
101
103
- SpecifierKind getSpecifierKind () const { return specifierKind ; }
102
+ LifetimeEntryKind getLifetimeEntryKind () const { return lifetimeEntryKind ; }
104
103
105
104
ParsedLifetimeDependenceKind getParsedLifetimeDependenceKind () const {
106
105
return parsedLifetimeDependenceKind;
107
106
}
108
107
109
108
Identifier getName () const {
110
- assert (specifierKind == SpecifierKind ::Named);
109
+ assert (lifetimeEntryKind == LifetimeEntryKind ::Named);
111
110
return value.Named .name ;
112
111
}
113
112
114
113
unsigned getIndex () const {
115
- assert (specifierKind == SpecifierKind ::Ordered);
114
+ assert (lifetimeEntryKind == LifetimeEntryKind ::Ordered);
116
115
return value.Ordered .index ;
117
116
}
118
117
119
118
std::string getParamString () const {
120
- switch (specifierKind ) {
121
- case SpecifierKind ::Named:
119
+ switch (lifetimeEntryKind ) {
120
+ case LifetimeEntryKind ::Named:
122
121
return value.Named .name .str ().str ();
123
- case SpecifierKind ::Self:
122
+ case LifetimeEntryKind ::Self:
124
123
return " self" ;
125
- case SpecifierKind ::Ordered:
124
+ case LifetimeEntryKind ::Ordered:
126
125
return std::to_string (value.Ordered .index );
127
- case SpecifierKind ::Immortal:
126
+ case LifetimeEntryKind ::Immortal:
128
127
return " immortal" ;
129
128
}
130
- llvm_unreachable (" Invalid LifetimeDependenceSpecifier::SpecifierKind " );
129
+ llvm_unreachable (" Invalid LifetimeEntryKind " );
131
130
}
132
131
133
- std::string getLifetimeDependenceSpecifierString () const {
132
+ std::string getDependsOnString () const {
134
133
switch (parsedLifetimeDependenceKind) {
135
134
case ParsedLifetimeDependenceKind::Default:
136
135
return " dependsOn(" + getParamString () + " )" ;
@@ -139,8 +138,7 @@ class LifetimeDependenceSpecifier {
139
138
case ParsedLifetimeDependenceKind::Inherit:
140
139
return " dependsOn(inherited " + getParamString () + " )" ;
141
140
}
142
- llvm_unreachable (
143
- " Invalid LifetimeDependenceSpecifier::ParsedLifetimeDependenceKind" );
141
+ llvm_unreachable (" Invalid LifetimeEntry::ParsedLifetimeDependenceKind" );
144
142
}
145
143
};
146
144
@@ -155,10 +153,10 @@ class LifetimeDependenceInfo {
155
153
unsigned sourceIndex,
156
154
LifetimeDependenceKind kind);
157
155
158
- // / Builds LifetimeDependenceInfo on a result or parameter from a swift decl
156
+ // / Builds LifetimeDependenceInfo from dependsOn type modifier
159
157
static std::optional<LifetimeDependenceInfo>
160
- fromTypeRepr (AbstractFunctionDecl *afd, LifetimeDependentTypeRepr *typeRepr ,
161
- unsigned targetIndex);
158
+ fromDependsOn (AbstractFunctionDecl *afd, TypeRepr *targetRepr ,
159
+ Type targetType, unsigned targetIndex);
162
160
163
161
// / Infer LifetimeDependenceInfo on result
164
162
static std::optional<LifetimeDependenceInfo> infer (AbstractFunctionDecl *afd);
@@ -173,9 +171,9 @@ class LifetimeDependenceInfo {
173
171
174
172
// / Builds LifetimeDependenceInfo from SIL function type
175
173
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);
179
177
180
178
public:
181
179
LifetimeDependenceInfo (IndexSubset *inheritLifetimeParamIndices,
0 commit comments