Skip to content

Commit 2d256cb

Browse files
committed
[NFC] Hide VarDecl::setIntroducer
1 parent 539a5b3 commit 2d256cb

10 files changed

+46
-25
lines changed

include/swift/AST/Decl.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5060,6 +5060,13 @@ class VarDecl : public AbstractStorageDecl {
50605060
SourceLoc nameLoc, Identifier name, DeclContext *dc,
50615061
StorageIsMutable_t supportsMutation);
50625062

5063+
protected:
5064+
// Only \c ParamDecl::setSpecifier is allowed to flip this - and it's also
5065+
// on the way out of that business.
5066+
void setIntroducer(Introducer value) {
5067+
Bits.VarDecl.Introducer = uint8_t(value);
5068+
}
5069+
50635070
public:
50645071
VarDecl(bool isStatic, Introducer introducer,
50655072
SourceLoc nameLoc, Identifier name, DeclContext *dc)
@@ -5263,10 +5270,6 @@ class VarDecl : public AbstractStorageDecl {
52635270
return Introducer(Bits.VarDecl.Introducer);
52645271
}
52655272

5266-
void setIntroducer(Introducer value) {
5267-
Bits.VarDecl.Introducer = uint8_t(value);
5268-
}
5269-
52705273
CaptureListExpr *getParentCaptureList() const {
52715274
if (!Parent)
52725275
return nullptr;

lib/Sema/DerivedConformanceActor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ static ValueDecl *deriveActor_unownedExecutor(DerivedConformance &derived) {
138138
}
139139
Type executorType = executorDecl->getDeclaredInterfaceType();
140140

141-
auto propertyPair =
142-
derived.declareDerivedProperty(ctx.Id_unownedExecutor,
143-
executorType, executorType,
144-
/*static*/ false, /*final*/ false);
141+
auto propertyPair = derived.declareDerivedProperty(
142+
DerivedConformance::SynthesizedIntroducer::Var, ctx.Id_unownedExecutor,
143+
executorType, executorType,
144+
/*static*/ false, /*final*/ false);
145145
auto property = propertyPair.first;
146146
property->setSynthesized(true);
147147
property->getAttrs().add(new (ctx) SemanticsAttr(SEMANTICS_DEFAULT_ACTOR,

lib/Sema/DerivedConformanceAdditiveArithmetic.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ static ValueDecl *deriveAdditiveArithmetic_zero(DerivedConformance &derived) {
302302
VarDecl *propDecl;
303303
PatternBindingDecl *pbDecl;
304304
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
305-
C.Id_zero, returnInterfaceTy, returnTy, /*isStatic*/ true,
305+
DerivedConformance::SynthesizedIntroducer::Var, C.Id_zero,
306+
returnInterfaceTy, returnTy, /*isStatic*/ true,
306307
/*isFinal*/ true);
307308

308309
// Create property getter.

lib/Sema/DerivedConformanceCaseIterable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ ValueDecl *DerivedConformance::deriveCaseIterable(ValueDecl *requirement) {
9898

9999
VarDecl *propDecl;
100100
PatternBindingDecl *pbDecl;
101-
std::tie(propDecl, pbDecl) =
102-
declareDerivedProperty(Context.Id_allCases, returnTy, returnTy,
103-
/*isStatic=*/true, /*isFinal=*/true);
101+
std::tie(propDecl, pbDecl) = declareDerivedProperty(
102+
SynthesizedIntroducer::Var, Context.Id_allCases, returnTy, returnTy,
103+
/*isStatic=*/true, /*isFinal=*/true);
104104

105105
// Define the getter.
106106
auto *getterDecl = addGetterToReadOnlyDerivedProperty(propDecl, returnTy);

lib/Sema/DerivedConformanceCodingKey.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ static ValueDecl *deriveProperty(DerivedConformance &derived, Type type,
160160
// Define the property.
161161
VarDecl *propDecl;
162162
PatternBindingDecl *pbDecl;
163-
std::tie(propDecl, pbDecl) =
164-
derived.declareDerivedProperty(name, type, type,
165-
/*isStatic=*/false, /*isFinal=*/false);
163+
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
164+
DerivedConformance::SynthesizedIntroducer::Var, name, type, type,
165+
/*isStatic=*/false, /*isFinal=*/false);
166166

167167
// Define the getter.
168168
auto *getterDecl = derived.addGetterToReadOnlyDerivedProperty(

lib/Sema/DerivedConformanceDistributedActor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ static ValueDecl *deriveDistributedActor_id(DerivedConformance &derived) {
112112
VarDecl *propDecl;
113113
PatternBindingDecl *pbDecl;
114114
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
115-
C.Id_id,
116-
propertyType, propertyType,
115+
DerivedConformance::SynthesizedIntroducer::Let, C.Id_id, propertyType,
116+
propertyType,
117117
/*isStatic=*/false, /*isFinal=*/true);
118118

119119
// mark as nonisolated, allowing access to it from everywhere
@@ -141,7 +141,7 @@ static ValueDecl *deriveDistributedActor_actorSystem(
141141
VarDecl *propDecl;
142142
PatternBindingDecl *pbDecl;
143143
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
144-
C.Id_actorSystem,
144+
DerivedConformance::SynthesizedIntroducer::Let, C.Id_actorSystem,
145145
propertyType, propertyType,
146146
/*isStatic=*/false, /*isFinal=*/true);
147147

lib/Sema/DerivedConformanceError.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ deriveBridgedNSError_enum_nsErrorDomain(
9797
VarDecl *propDecl;
9898
PatternBindingDecl *pbDecl;
9999
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
100+
DerivedConformance::SynthesizedIntroducer::Var,
100101
derived.Context.Id_nsErrorDomain, stringTy, stringTy, /*isStatic=*/true,
101102
/*isFinal=*/true);
102103

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ static VarDecl *deriveRawRepresentable_raw(DerivedConformance &derived) {
165165
VarDecl *propDecl;
166166
PatternBindingDecl *pbDecl;
167167
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
168-
C.Id_rawValue, rawInterfaceType, rawType, /*isStatic=*/false,
168+
DerivedConformance::SynthesizedIntroducer::Var, C.Id_rawValue,
169+
rawInterfaceType, rawType, /*isStatic=*/false,
169170
/*isFinal=*/false);
170171

171172
// Define the getter.

lib/Sema/DerivedConformances.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,27 @@ DerivedConformance::declareDerivedPropertyGetter(VarDecl *property,
498498
return getterDecl;
499499
}
500500

501+
static VarDecl::Introducer
502+
mapIntroducer(DerivedConformance::SynthesizedIntroducer intro) {
503+
switch (intro) {
504+
case DerivedConformance::SynthesizedIntroducer::Let:
505+
return VarDecl::Introducer::Let;
506+
case DerivedConformance::SynthesizedIntroducer::Var:
507+
return VarDecl::Introducer::Var;
508+
}
509+
llvm_unreachable("Invalid synthesized introducer!");
510+
}
511+
501512
std::pair<VarDecl *, PatternBindingDecl *>
502-
DerivedConformance::declareDerivedProperty(Identifier name,
513+
DerivedConformance::declareDerivedProperty(SynthesizedIntroducer intro,
514+
Identifier name,
503515
Type propertyInterfaceType,
504516
Type propertyContextType,
505517
bool isStatic, bool isFinal) {
506518
auto parentDC = getConformanceContext();
507519

508-
VarDecl *propDecl = new (Context)
509-
VarDecl(/*IsStatic*/ isStatic, VarDecl::Introducer::Var,
510-
SourceLoc(), name, parentDC);
520+
VarDecl *propDecl = new (Context) VarDecl(
521+
/*IsStatic*/ isStatic, mapIntroducer(intro), SourceLoc(), name, parentDC);
511522
propDecl->setImplicit();
512523
propDecl->setSynthesized();
513524
propDecl->copyFormalAccessFrom(Nominal, /*sourceIsParentContext*/ true);

lib/Sema/DerivedConformances.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class ValueDecl;
4949
class VarDecl;
5050

5151
class DerivedConformance {
52+
public:
53+
enum class SynthesizedIntroducer : bool { Let, Var };
54+
5255
public:
5356
ASTContext &Context;
5457
Decl *ConformanceDecl;
@@ -335,8 +338,9 @@ class DerivedConformance {
335338

336339
/// Declare a read-only property.
337340
std::pair<VarDecl *, PatternBindingDecl *>
338-
declareDerivedProperty(Identifier name, Type propertyInterfaceType,
339-
Type propertyContextType, bool isStatic, bool isFinal);
341+
declareDerivedProperty(SynthesizedIntroducer intro, Identifier name,
342+
Type propertyInterfaceType, Type propertyContextType,
343+
bool isStatic, bool isFinal);
340344

341345
/// Add a getter to a derived property. The property becomes read-only.
342346
static AccessorDecl *

0 commit comments

Comments
 (0)