Skip to content

Commit 7b8665b

Browse files
committed
[NFC] Rename LifetimeDependenceSpecifier -> LifetimeEntry
1 parent c00072d commit 7b8665b

File tree

12 files changed

+96
-115
lines changed

12 files changed

+96
-115
lines changed

include/swift/AST/Attr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,19 +2636,19 @@ class RawLayoutAttr final : public DeclAttribute {
26362636

26372637
class LifetimeAttr final
26382638
: public DeclAttribute,
2639-
private llvm::TrailingObjects<LifetimeAttr, LifetimeDependenceSpecifier> {
2639+
private llvm::TrailingObjects<LifetimeAttr, LifetimeEntry> {
26402640

26412641
friend TrailingObjects;
26422642

26432643
unsigned NumEntries = 0;
26442644

26452645
explicit LifetimeAttr(SourceLoc atLoc, SourceRange baseRange, bool implicit,
2646-
ArrayRef<LifetimeDependenceSpecifier> entries);
2646+
ArrayRef<LifetimeEntry> entries);
26472647

26482648
public:
26492649
static LifetimeAttr *create(ASTContext &context, SourceLoc atLoc,
26502650
SourceRange baseRange, bool implicit,
2651-
ArrayRef<LifetimeDependenceSpecifier> entries);
2651+
ArrayRef<LifetimeEntry> entries);
26522652

26532653
static bool classof(const DeclAttribute *DA) {
26542654
return DA->getKind() == DeclAttrKind::Lifetime;

include/swift/AST/LifetimeDependence.h

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- LifetimeDependenceSpecifiers.h ------------------------*- C++ -*-===//
1+
//===--- LifetimeDependence.h ---------------------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -43,12 +43,12 @@ enum class ParsedLifetimeDependenceKind : uint8_t {
4343

4444
enum class LifetimeDependenceKind : uint8_t { Inherit = 0, Scope };
4545

46-
enum class LifetimeSpecifierKind { Named, Ordered, Self, Immortal };
46+
enum class LifetimeEntryKind { Named, Ordered, Self, Immortal };
4747

48-
class LifetimeDependenceSpecifier {
48+
class LifetimeEntry {
4949
private:
5050
SourceLoc loc;
51-
LifetimeSpecifierKind specifierKind;
51+
LifetimeEntryKind lifetimeEntryKind;
5252
ParsedLifetimeDependenceKind parsedLifetimeDependenceKind;
5353
union Value {
5454
struct {
@@ -64,72 +64,72 @@ class LifetimeDependenceSpecifier {
6464
Value() {}
6565
} value;
6666

67-
LifetimeDependenceSpecifier(
68-
SourceLoc loc, LifetimeSpecifierKind specifierKind,
69-
ParsedLifetimeDependenceKind parsedLifetimeDependenceKind, Value value)
70-
: loc(loc), specifierKind(specifierKind),
67+
LifetimeEntry(SourceLoc loc, LifetimeEntryKind lifetimeEntryKind,
68+
ParsedLifetimeDependenceKind parsedLifetimeDependenceKind,
69+
Value value)
70+
: loc(loc), lifetimeEntryKind(lifetimeEntryKind),
7171
parsedLifetimeDependenceKind(parsedLifetimeDependenceKind),
7272
value(value) {}
7373

7474
public:
75-
static LifetimeDependenceSpecifier getNamedLifetimeDependenceSpecifier(
76-
SourceLoc loc, Identifier name,
77-
ParsedLifetimeDependenceKind kind =
78-
ParsedLifetimeDependenceKind::Default) {
79-
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};
8080
}
8181

82-
static LifetimeDependenceSpecifier
83-
getImmortalLifetimeDependenceSpecifier(SourceLoc loc) {
84-
return {loc, LifetimeSpecifierKind::Immortal, {}, {}};
82+
static LifetimeEntry getImmortalLifetimeEntry(SourceLoc loc) {
83+
return {loc, LifetimeEntryKind::Immortal, {}, {}};
8584
}
8685

87-
static LifetimeDependenceSpecifier getOrderedLifetimeDependenceSpecifier(
88-
SourceLoc loc, unsigned index,
89-
ParsedLifetimeDependenceKind kind =
90-
ParsedLifetimeDependenceKind::Default) {
91-
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};
9291
}
9392

94-
static LifetimeDependenceSpecifier getSelfLifetimeDependenceSpecifier(
95-
SourceLoc loc, ParsedLifetimeDependenceKind kind =
96-
ParsedLifetimeDependenceKind::Default) {
97-
return {loc, SpecifierKind::Self, kind, {}};
93+
static LifetimeEntry
94+
getSelfLifetimeEntry(SourceLoc loc,
95+
ParsedLifetimeDependenceKind kind =
96+
ParsedLifetimeDependenceKind::Default) {
97+
return {loc, LifetimeEntryKind::Self, kind, {}};
9898
}
9999

100100
SourceLoc getLoc() const { return loc; }
101101

102-
LifetimeSpecifierKind getSpecifierKind() const { return specifierKind; }
102+
LifetimeEntryKind getLifetimeEntryKind() const { return lifetimeEntryKind; }
103103

104104
ParsedLifetimeDependenceKind getParsedLifetimeDependenceKind() const {
105105
return parsedLifetimeDependenceKind;
106106
}
107107

108108
Identifier getName() const {
109-
assert(specifierKind == LifetimeSpecifierKind::Named);
109+
assert(lifetimeEntryKind == LifetimeEntryKind::Named);
110110
return value.Named.name;
111111
}
112112

113113
unsigned getIndex() const {
114-
assert(specifierKind == LifetimeSpecifierKind::Ordered);
114+
assert(lifetimeEntryKind == LifetimeEntryKind::Ordered);
115115
return value.Ordered.index;
116116
}
117117

118118
std::string getParamString() const {
119-
switch (specifierKind) {
120-
case LifetimeSpecifierKind::Named:
119+
switch (lifetimeEntryKind) {
120+
case LifetimeEntryKind::Named:
121121
return value.Named.name.str().str();
122-
case LifetimeSpecifierKind::Self:
122+
case LifetimeEntryKind::Self:
123123
return "self";
124-
case LifetimeSpecifierKind::Ordered:
124+
case LifetimeEntryKind::Ordered:
125125
return std::to_string(value.Ordered.index);
126-
case LifetimeSpecifierKind::Immortal:
126+
case LifetimeEntryKind::Immortal:
127127
return "immortal";
128128
}
129-
llvm_unreachable("Invalid LifetimeSpecifierKind");
129+
llvm_unreachable("Invalid LifetimeEntryKind");
130130
}
131131

132-
std::string getLifetimeDependenceSpecifierString() const {
132+
std::string getDependsOnString() const {
133133
switch (parsedLifetimeDependenceKind) {
134134
case ParsedLifetimeDependenceKind::Default:
135135
return "dependsOn(" + getParamString() + ")";
@@ -138,8 +138,7 @@ class LifetimeDependenceSpecifier {
138138
case ParsedLifetimeDependenceKind::Inherit:
139139
return "dependsOn(inherited " + getParamString() + ")";
140140
}
141-
llvm_unreachable(
142-
"Invalid LifetimeDependenceSpecifier::ParsedLifetimeDependenceKind");
141+
llvm_unreachable("Invalid LifetimeEntry::ParsedLifetimeDependenceKind");
143142
}
144143
};
145144

include/swift/AST/TypeRepr.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,31 +1533,28 @@ class SILBoxTypeRepr final : public TypeRepr,
15331533

15341534
class LifetimeDependentTypeRepr final
15351535
: public SpecifierTypeRepr,
1536-
private llvm::TrailingObjects<LifetimeDependentTypeRepr,
1537-
LifetimeDependenceSpecifier> {
1536+
private llvm::TrailingObjects<LifetimeDependentTypeRepr, LifetimeEntry> {
15381537
friend TrailingObjects;
15391538

15401539
size_t numTrailingObjects(OverloadToken<LifetimeDependentTypeRepr>) const {
15411540
return Bits.LifetimeDependentTypeRepr.NumDependencies;
15421541
}
15431542

15441543
public:
1545-
LifetimeDependentTypeRepr(TypeRepr *base,
1546-
ArrayRef<LifetimeDependenceSpecifier> specifiers)
1544+
LifetimeDependentTypeRepr(TypeRepr *base, ArrayRef<LifetimeEntry> specifiers)
15471545
: SpecifierTypeRepr(TypeReprKind::LifetimeDependent, base,
15481546
specifiers.front().getLoc()) {
15491547
assert(base);
15501548
Bits.LifetimeDependentTypeRepr.NumDependencies = specifiers.size();
15511549
std::uninitialized_copy(specifiers.begin(), specifiers.end(),
1552-
getTrailingObjects<LifetimeDependenceSpecifier>());
1550+
getTrailingObjects<LifetimeEntry>());
15531551
}
15541552

1555-
static LifetimeDependentTypeRepr *
1556-
create(ASTContext &C, TypeRepr *base,
1557-
ArrayRef<LifetimeDependenceSpecifier> specifiers);
1553+
static LifetimeDependentTypeRepr *create(ASTContext &C, TypeRepr *base,
1554+
ArrayRef<LifetimeEntry> specifiers);
15581555

1559-
ArrayRef<LifetimeDependenceSpecifier> getLifetimeDependencies() const {
1560-
return {getTrailingObjects<LifetimeDependenceSpecifier>(),
1556+
ArrayRef<LifetimeEntry> getLifetimeDependencies() const {
1557+
return {getTrailingObjects<LifetimeEntry>(),
15611558
Bits.LifetimeDependentTypeRepr.NumDependencies};
15621559
}
15631560

include/swift/Parse/Parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,8 @@ class Parser {
12701270
ConventionTypeAttr *&result,
12711271
bool justChecking);
12721272

1273-
ParserStatus parseLifetimeDependenceSpecifiers(
1274-
SmallVectorImpl<LifetimeDependenceSpecifier> &specifierList);
1273+
ParserStatus
1274+
parseLifetimeEntries(SmallVectorImpl<LifetimeEntry> &specifierList);
12751275

12761276
ParserResult<ImportDecl> parseDeclImport(ParseDeclOptions Flags,
12771277
DeclAttributes &Attributes);
@@ -1474,7 +1474,7 @@ class Parser {
14741474
SourceLoc ConstLoc;
14751475
SourceLoc SendingLoc;
14761476
SmallVector<TypeOrCustomAttr> Attributes;
1477-
SmallVector<LifetimeDependenceSpecifier> lifetimeDependenceSpecifiers;
1477+
SmallVector<LifetimeEntry> lifetimeEntries;
14781478

14791479
ParsedTypeAttributeList(ParseTypeReason reason) : ParseReason(reason) {}
14801480

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr, void, StringRef>,
35553555
for (auto &dep : T->getLifetimeDependencies()) {
35563556
printFieldRaw(
35573557
[&](raw_ostream &out) {
3558-
out << " " << dep.getLifetimeDependenceSpecifierString() << " ";
3558+
out << " " << dep.getDependsOnString() << " ";
35593559
},
35603560
"");
35613561
}

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4094,7 +4094,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
40944094
if (auto *typeRepr = dyn_cast_or_null<LifetimeDependentTypeRepr>(
40954095
decl->getResultTypeRepr())) {
40964096
for (auto &dep : typeRepr->getLifetimeDependencies()) {
4097-
Printer << " " << dep.getLifetimeDependenceSpecifierString() << " ";
4097+
Printer << " " << dep.getDependsOnString() << " ";
40984098
}
40994099
}
41004100
}
@@ -4331,7 +4331,7 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
43314331
auto *typeRepr =
43324332
cast<LifetimeDependentTypeRepr>(decl->getResultTypeRepr());
43334333
for (auto &dep : typeRepr->getLifetimeDependencies()) {
4334-
Printer << dep.getLifetimeDependenceSpecifierString() << " ";
4334+
Printer << dep.getDependsOnString() << " ";
43354335
}
43364336
// TODO: Handle failable initializers with lifetime dependent returns
43374337
Printer << "Self";

lib/AST/Attr.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,20 +3032,18 @@ AllowFeatureSuppressionAttr *AllowFeatureSuppressionAttr::create(
30323032
}
30333033

30343034
LifetimeAttr::LifetimeAttr(SourceLoc atLoc, SourceRange baseRange,
3035-
bool implicit,
3036-
ArrayRef<LifetimeDependenceSpecifier> entries)
3035+
bool implicit, ArrayRef<LifetimeEntry> entries)
30373036
: DeclAttribute(DeclAttrKind::Lifetime, atLoc, baseRange, implicit),
30383037
NumEntries(entries.size()) {
30393038
std::copy(entries.begin(), entries.end(),
3040-
getTrailingObjects<LifetimeDependenceSpecifier>());
3039+
getTrailingObjects<LifetimeEntry>());
30413040
}
30423041

3043-
LifetimeAttr *
3044-
LifetimeAttr::create(ASTContext &context, SourceLoc atLoc,
3045-
SourceRange baseRange, bool implicit,
3046-
ArrayRef<LifetimeDependenceSpecifier> entries) {
3047-
unsigned size = totalSizeToAlloc<LifetimeDependenceSpecifier>(entries.size());
3048-
void *mem = context.Allocate(size, alignof(LifetimeDependenceSpecifier));
3042+
LifetimeAttr *LifetimeAttr::create(ASTContext &context, SourceLoc atLoc,
3043+
SourceRange baseRange, bool implicit,
3044+
ArrayRef<LifetimeEntry> entries) {
3045+
unsigned size = totalSizeToAlloc<LifetimeEntry>(entries.size());
3046+
void *mem = context.Allocate(size, alignof(LifetimeEntry));
30493047
return new (mem) LifetimeAttr(atLoc, baseRange, implicit, entries);
30503048
}
30513049

lib/AST/LifetimeDependence.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ static bool hasEscapableResultOrYield(AbstractFunctionDecl *afd) {
209209
}
210210

211211
static std::optional<LifetimeDependenceKind>
212-
getLifetimeDependenceKind(LifetimeDependenceSpecifier specifier,
213-
AbstractFunctionDecl *afd, ParamDecl *decl) {
212+
getLifetimeDependenceKind(LifetimeEntry specifier, AbstractFunctionDecl *afd,
213+
ParamDecl *decl) {
214214
auto &ctx = afd->getASTContext();
215215
auto &diags = ctx.Diags;
216216
auto loc = specifier.getLoc();
@@ -268,7 +268,7 @@ LifetimeDependenceInfo::fromDependsOn(AbstractFunctionDecl *afd,
268268
SmallBitVector scopeLifetimeParamIndices(capacity);
269269

270270
auto updateLifetimeDependenceInfo =
271-
[&](LifetimeDependenceSpecifier specifier, unsigned paramIndexToSet,
271+
[&](LifetimeEntry specifier, unsigned paramIndexToSet,
272272
std::optional<LifetimeDependenceKind> lifetimeKind) {
273273
auto loc = specifier.getLoc();
274274
if (!lifetimeKind.has_value()) {
@@ -289,8 +289,8 @@ LifetimeDependenceInfo::fromDependsOn(AbstractFunctionDecl *afd,
289289
};
290290

291291
for (auto specifier : lifetimeDependentRepr->getLifetimeDependencies()) {
292-
switch (specifier.getSpecifierKind()) {
293-
case LifetimeSpecifierKind::Immortal: {
292+
switch (specifier.getLifetimeEntryKind()) {
293+
case LifetimeEntryKind::Immortal: {
294294
auto immortalParam =
295295
std::find_if(afd->getParameters()->begin(),
296296
afd->getParameters()->end(), [](ParamDecl *param) {
@@ -304,7 +304,7 @@ LifetimeDependenceInfo::fromDependsOn(AbstractFunctionDecl *afd,
304304
return LifetimeDependenceInfo(nullptr, nullptr, targetIndex,
305305
/*isImmortal*/ true);
306306
}
307-
case LifetimeSpecifierKind::Named: {
307+
case LifetimeEntryKind::Named: {
308308
unsigned paramIndex = 0;
309309
ParamDecl *candidateParam = nullptr;
310310
for (auto *param : *afd->getParameters()) {
@@ -328,7 +328,7 @@ LifetimeDependenceInfo::fromDependsOn(AbstractFunctionDecl *afd,
328328

329329
break;
330330
}
331-
case LifetimeSpecifierKind::Ordered: {
331+
case LifetimeEntryKind::Ordered: {
332332
auto index = specifier.getIndex();
333333
if (index >= afd->getParameters()->size()) {
334334
diags.diagnose(specifier.getLoc(),
@@ -343,7 +343,7 @@ LifetimeDependenceInfo::fromDependsOn(AbstractFunctionDecl *afd,
343343
}
344344
break;
345345
}
346-
case LifetimeSpecifierKind::Self: {
346+
case LifetimeEntryKind::Self: {
347347
if (!afd->hasImplicitSelfDecl()) {
348348
diags.diagnose(specifier.getLoc(),
349349
diag::lifetime_dependence_invalid_self_in_static);
@@ -390,7 +390,7 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromDependsOn(
390390
SmallBitVector inheritLifetimeParamIndices(capacity);
391391
SmallBitVector scopeLifetimeParamIndices(capacity);
392392

393-
auto updateLifetimeDependenceInfo = [&](LifetimeDependenceSpecifier specifier,
393+
auto updateLifetimeDependenceInfo = [&](LifetimeEntry specifier,
394394
unsigned paramIndexToSet,
395395
ParameterConvention paramConvention) {
396396
auto loc = specifier.getLoc();
@@ -419,8 +419,8 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromDependsOn(
419419
};
420420

421421
for (auto specifier : lifetimeDependentRepr->getLifetimeDependencies()) {
422-
switch (specifier.getSpecifierKind()) {
423-
case LifetimeSpecifierKind::Ordered: {
422+
switch (specifier.getLifetimeEntryKind()) {
423+
case LifetimeEntryKind::Ordered: {
424424
auto index = specifier.getIndex();
425425
if (index > capacity) {
426426
diags.diagnose(specifier.getLoc(),
@@ -434,7 +434,7 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromDependsOn(
434434
}
435435
break;
436436
}
437-
case LifetimeSpecifierKind::Immortal: {
437+
case LifetimeEntryKind::Immortal: {
438438
return LifetimeDependenceInfo(/*inheritLifetimeParamIndices*/ nullptr,
439439
/*scopeLifetimeParamIndices*/ nullptr,
440440
targetIndex,

lib/AST/TypeRepr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,11 @@ SourceLoc SILBoxTypeRepr::getLocImpl() const {
675675
return LBraceLoc;
676676
}
677677

678-
LifetimeDependentTypeRepr *LifetimeDependentTypeRepr::create(
679-
ASTContext &C, TypeRepr *base,
680-
ArrayRef<LifetimeDependenceSpecifier> specifiers) {
681-
auto size = totalSizeToAlloc<LifetimeDependenceSpecifier>(specifiers.size());
682-
auto mem = C.Allocate(size, alignof(LifetimeDependenceSpecifier));
678+
LifetimeDependentTypeRepr *
679+
LifetimeDependentTypeRepr::create(ASTContext &C, TypeRepr *base,
680+
ArrayRef<LifetimeEntry> specifiers) {
681+
auto size = totalSizeToAlloc<LifetimeEntry>(specifiers.size());
682+
auto mem = C.Allocate(size, alignof(LifetimeEntry));
683683
return new (mem) LifetimeDependentTypeRepr(base, specifiers);
684684
}
685685

@@ -699,7 +699,7 @@ void LifetimeDependentTypeRepr::printImpl(ASTPrinter &Printer,
699699
const PrintOptions &Opts) const {
700700
Printer << " ";
701701
for (auto &dep : getLifetimeDependencies()) {
702-
Printer << dep.getLifetimeDependenceSpecifierString() << " ";
702+
Printer << dep.getDependsOnString() << " ";
703703
}
704704

705705
printTypeRepr(getBase(), Printer, Opts);

0 commit comments

Comments
 (0)