Skip to content

Commit a013cd2

Browse files
committed
AST: Replace PrimaryAssociatedTypeAttr with AssociatedTypeDecl::isPrimary() flag
1 parent 7dfc2a2 commit a013cd2

File tree

10 files changed

+25
-16
lines changed

10 files changed

+25
-16
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(distributed, DistributedActor,
661661
APIBreakingToAdd | APIBreakingToRemove,
662662
118)
663663

664-
SIMPLE_DECL_ATTR(_primaryAssociatedType,
665-
PrimaryAssociatedType, OnAssociatedType | UserInaccessible |
666-
APIStableToAdd | ABIStableToAdd | APIBreakingToRemove | ABIStableToRemove,
667-
119)
664+
// 119 is unused
668665

669666
SIMPLE_DECL_ATTR(_assemblyVision, EmitAssemblyVisionRemarks,
670667
OnFunc | UserInaccessible | NotSerialized | OnNominalType |

include/swift/AST/Decl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
505505
IsOpaqueType : 1
506506
);
507507

508+
SWIFT_INLINE_BITFIELD_FULL(AssociatedTypeDecl, AbstractTypeParamDecl, 1,
509+
/// Whether this is a primary associated type.
510+
IsPrimary : 1
511+
);
512+
508513
SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, TypeDecl);
509514

510515
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1+1,
@@ -3208,6 +3213,14 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
32083213
LazyMemberLoader *definitionResolver,
32093214
uint64_t resolverData);
32103215

3216+
bool isPrimary() const {
3217+
return Bits.AssociatedTypeDecl.IsPrimary;
3218+
}
3219+
3220+
void setPrimary() {
3221+
Bits.AssociatedTypeDecl.IsPrimary = true;
3222+
}
3223+
32113224
/// Get the protocol in which this associated type is declared.
32123225
ProtocolDecl *getProtocol() const {
32133226
return cast<ProtocolDecl>(getDeclContext());

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,6 +4539,7 @@ AssociatedTypeDecl::AssociatedTypeDecl(DeclContext *dc, SourceLoc keywordLoc,
45394539
: AbstractTypeParamDecl(DeclKind::AssociatedType, dc, name, nameLoc),
45404540
KeywordLoc(keywordLoc), DefaultDefinition(defaultDefinition),
45414541
TrailingWhere(trailingWhere) {
4542+
Bits.AssociatedTypeDecl.IsPrimary = 0;
45424543
}
45434544

45444545
AssociatedTypeDecl::AssociatedTypeDecl(DeclContext *dc, SourceLoc keywordLoc,

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8040,8 +8040,7 @@ ParserStatus Parser::parsePrimaryAssociatedTypes(
80408040
AssocType->getAttrs() = Attrs;
80418041
if (!Inherited.empty())
80428042
AssocType->setInherited(Context.AllocateCopy(Inherited));
8043-
AssocType->getAttrs().add(new (Context) PrimaryAssociatedTypeAttr(
8044-
/*Implicit=*/true));
8043+
AssocType->setPrimary();
80458044

80468045
AssocTypes.push_back(AssocType);
80478046

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
316316

317317
void visitUnsafeInheritExecutorAttr(UnsafeInheritExecutorAttr *attr);
318318

319-
void visitPrimaryAssociatedTypeAttr(PrimaryAssociatedTypeAttr *attr);
320-
321319
void checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs);
322320
};
323321

@@ -5894,10 +5892,6 @@ void AttributeChecker::visitUnsafeInheritExecutorAttr(
58945892
}
58955893
}
58965894

5897-
void AttributeChecker::visitPrimaryAssociatedTypeAttr(
5898-
PrimaryAssociatedTypeAttr *attr) {
5899-
}
5900-
59015895
namespace {
59025896

59035897
class ClosureAttributeChecker

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ PrimaryAssociatedTypesRequest::evaluate(Evaluator &evaluator,
704704
SmallVector<AssociatedTypeDecl *, 2> assocTypes;
705705

706706
for (auto *assocType : decl->getAssociatedTypeMembers()) {
707-
if (assocType->getAttrs().hasAttribute<PrimaryAssociatedTypeAttr>())
707+
if (assocType->isPrimary())
708708
assocTypes.push_back(assocType);
709709
}
710710

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,8 +1572,6 @@ namespace {
15721572
UNINTERESTING_ATTR(TypeSequence)
15731573
UNINTERESTING_ATTR(CompileTimeConst)
15741574

1575-
UNINTERESTING_ATTR(PrimaryAssociatedType)
1576-
15771575
UNINTERESTING_ATTR(BackDeploy)
15781576

15791577
UNINTERESTING_ATTR(UnsafeInheritExecutor)

lib/Serialization/Deserialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,11 +2777,13 @@ class DeclDeserializer {
27772777
TypeID defaultDefinitionID;
27782778
bool isImplicit;
27792779
ArrayRef<uint64_t> rawOverriddenIDs;
2780+
bool isPrimary;
27802781

27812782
decls_block::AssociatedTypeDeclLayout::readRecord(scratch, nameID,
27822783
contextID,
27832784
defaultDefinitionID,
27842785
isImplicit,
2786+
isPrimary,
27852787
rawOverriddenIDs);
27862788

27872789
auto DC = MF.getDeclContext(contextID);
@@ -2816,6 +2818,9 @@ class DeclDeserializer {
28162818
}
28172819
assocType->setOverriddenDecls(overriddenAssocTypes);
28182820

2821+
if (isPrimary)
2822+
assocType->setPrimary();
2823+
28192824
return assocType;
28202825
}
28212826

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 674; // decl block renumbering
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 675; // primary associated types
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -1233,6 +1233,7 @@ namespace decls_block {
12331233
DeclContextIDField, // context decl
12341234
TypeIDField, // default definition
12351235
BCFixed<1>, // implicit flag
1236+
BCFixed<1>, // is primary
12361237
BCArray<DeclIDField> // overridden associated types
12371238
>;
12381239

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
34653465
contextID.getOpaqueValue(),
34663466
S.addTypeRef(assocType->getDefaultDefinitionType()),
34673467
assocType->isImplicit(),
3468+
assocType->isPrimary(),
34683469
overriddenAssocTypeIDs);
34693470
}
34703471

0 commit comments

Comments
 (0)