Skip to content

Commit a64ae05

Browse files
committed
swift-module-digester: keep track of whether a protocol member is a requirement.
1 parent 8788253 commit a64ae05

File tree

7 files changed

+170
-2
lines changed

7 files changed

+170
-2
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ KEY(throwing)
102102
KEY(mutating)
103103
KEY(static)
104104
KEY(deprecated)
105+
KEY(protocolReq)
105106
KEY(implicit)
106107
KEY(typeAttributes)
107108
KEY(declAttributes)

test/api-digester/Inputs/cake.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ public protocol SubsContainer {
6060
subscript(getter i: Int) -> Int { get }
6161
subscript(setter i: Int) -> Int { get set }
6262
}
63+
64+
public extension ProWithAssociatedType {
65+
func NonReqFunc() {}
66+
var NonReqVar: Int { return 1 }
67+
typealias NonReqAlias = Int
68+
}

test/api-digester/Outputs/cake-abi.json

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@
925925
"declKind": "AssociatedType",
926926
"usr": "s:4cake21ProWithAssociatedTypeP1AQa",
927927
"location": "",
928-
"moduleName": "cake"
928+
"moduleName": "cake",
929+
"protocolReq": true
929930
},
930931
{
931932
"kind": "AssociatedType",
@@ -935,6 +936,77 @@
935936
"usr": "s:4cake21ProWithAssociatedTypeP1BQa",
936937
"location": "",
937938
"moduleName": "cake",
939+
"protocolReq": true,
940+
"children": [
941+
{
942+
"kind": "TypeNominal",
943+
"name": "Int",
944+
"printedName": "Int",
945+
"usr": "s:Si"
946+
}
947+
]
948+
},
949+
{
950+
"kind": "Function",
951+
"name": "NonReqFunc",
952+
"printedName": "NonReqFunc()",
953+
"declKind": "Func",
954+
"usr": "s:4cake21ProWithAssociatedTypePAAE10NonReqFuncyyF",
955+
"location": "",
956+
"moduleName": "cake",
957+
"genericSig": "<τ_0_0 where τ_0_0 : ProWithAssociatedType>",
958+
"children": [
959+
{
960+
"kind": "TypeNominal",
961+
"name": "Void",
962+
"printedName": "()"
963+
}
964+
]
965+
},
966+
{
967+
"kind": "Var",
968+
"name": "NonReqVar",
969+
"printedName": "NonReqVar",
970+
"declKind": "Var",
971+
"usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp",
972+
"location": "",
973+
"moduleName": "cake",
974+
"children": [
975+
{
976+
"kind": "TypeNominal",
977+
"name": "Int",
978+
"printedName": "Int",
979+
"usr": "s:Si"
980+
},
981+
{
982+
"kind": "Getter",
983+
"name": "_",
984+
"printedName": "_()",
985+
"declKind": "Accessor",
986+
"usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivg",
987+
"location": "",
988+
"moduleName": "cake",
989+
"genericSig": "<τ_0_0 where τ_0_0 : ProWithAssociatedType>",
990+
"children": [
991+
{
992+
"kind": "TypeNominal",
993+
"name": "Int",
994+
"printedName": "Int",
995+
"usr": "s:Si"
996+
}
997+
]
998+
}
999+
]
1000+
},
1001+
{
1002+
"kind": "TypeAlias",
1003+
"name": "NonReqAlias",
1004+
"printedName": "NonReqAlias",
1005+
"declKind": "TypeAlias",
1006+
"usr": "s:4cake21ProWithAssociatedTypePAAE11NonReqAliasa",
1007+
"location": "",
1008+
"moduleName": "cake",
1009+
"genericSig": "<τ_0_0 where τ_0_0 : ProWithAssociatedType>",
9381010
"children": [
9391011
{
9401012
"kind": "TypeNominal",
@@ -964,6 +1036,7 @@
9641036
"location": "",
9651037
"moduleName": "cake",
9661038
"genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>",
1039+
"protocolReq": true,
9671040
"children": [
9681041
{
9691042
"kind": "TypeNominal",
@@ -988,6 +1061,7 @@
9881061
"location": "",
9891062
"moduleName": "cake",
9901063
"genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>",
1064+
"protocolReq": true,
9911065
"hasSetter": true,
9921066
"children": [
9931067
{

test/api-digester/Outputs/cake.json

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@
855855
"declKind": "AssociatedType",
856856
"usr": "s:4cake21ProWithAssociatedTypeP1AQa",
857857
"location": "",
858-
"moduleName": "cake"
858+
"moduleName": "cake",
859+
"protocolReq": true
859860
},
860861
{
861862
"kind": "AssociatedType",
@@ -865,6 +866,77 @@
865866
"usr": "s:4cake21ProWithAssociatedTypeP1BQa",
866867
"location": "",
867868
"moduleName": "cake",
869+
"protocolReq": true,
870+
"children": [
871+
{
872+
"kind": "TypeNominal",
873+
"name": "Int",
874+
"printedName": "Int",
875+
"usr": "s:Si"
876+
}
877+
]
878+
},
879+
{
880+
"kind": "Function",
881+
"name": "NonReqFunc",
882+
"printedName": "NonReqFunc()",
883+
"declKind": "Func",
884+
"usr": "s:4cake21ProWithAssociatedTypePAAE10NonReqFuncyyF",
885+
"location": "",
886+
"moduleName": "cake",
887+
"genericSig": "<Self where Self : ProWithAssociatedType>",
888+
"children": [
889+
{
890+
"kind": "TypeNominal",
891+
"name": "Void",
892+
"printedName": "()"
893+
}
894+
]
895+
},
896+
{
897+
"kind": "Var",
898+
"name": "NonReqVar",
899+
"printedName": "NonReqVar",
900+
"declKind": "Var",
901+
"usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp",
902+
"location": "",
903+
"moduleName": "cake",
904+
"children": [
905+
{
906+
"kind": "TypeNominal",
907+
"name": "Int",
908+
"printedName": "Int",
909+
"usr": "s:Si"
910+
},
911+
{
912+
"kind": "Getter",
913+
"name": "_",
914+
"printedName": "_()",
915+
"declKind": "Accessor",
916+
"usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivg",
917+
"location": "",
918+
"moduleName": "cake",
919+
"genericSig": "<Self where Self : ProWithAssociatedType>",
920+
"children": [
921+
{
922+
"kind": "TypeNominal",
923+
"name": "Int",
924+
"printedName": "Int",
925+
"usr": "s:Si"
926+
}
927+
]
928+
}
929+
]
930+
},
931+
{
932+
"kind": "TypeAlias",
933+
"name": "NonReqAlias",
934+
"printedName": "NonReqAlias",
935+
"declKind": "TypeAlias",
936+
"usr": "s:4cake21ProWithAssociatedTypePAAE11NonReqAliasa",
937+
"location": "",
938+
"moduleName": "cake",
939+
"genericSig": "<Self where Self : ProWithAssociatedType>",
868940
"children": [
869941
{
870942
"kind": "TypeNominal",
@@ -894,6 +966,7 @@
894966
"location": "",
895967
"moduleName": "cake",
896968
"genericSig": "<Self where Self : SubsContainer>",
969+
"protocolReq": true,
897970
"children": [
898971
{
899972
"kind": "TypeNominal",
@@ -918,6 +991,7 @@
918991
"location": "",
919992
"moduleName": "cake",
920993
"genericSig": "<Self where Self : SubsContainer>",
994+
"protocolReq": true,
921995
"hasSetter": true,
922996
"children": [
923997
{

test/api-digester/Outputs/clang-module-dump.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"location": "",
9292
"moduleName": "Foo",
9393
"genericSig": "<Self where Self : ObjcProt>",
94+
"protocolReq": true,
9495
"declAttributes": [
9596
"ObjC"
9697
],

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct swift::ide::api::SDKNodeInitInfo {
4848
bool IsMutating = false;
4949
bool IsStatic = false;
5050
bool IsDeprecated = false;
51+
bool IsProtocolReq = false;
5152
Optional<uint8_t> SelfIndex;
5253
Optional<unsigned> FixedBinaryOrder;
5354
ReferenceOwnership ReferenceOwnership = ReferenceOwnership::Strong;
@@ -87,6 +88,7 @@ SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
8788
Location(Info.Location), ModuleName(Info.ModuleName),
8889
DeclAttributes(Info.DeclAttrs), IsImplicit(Info.IsImplicit),
8990
IsStatic(Info.IsStatic), IsDeprecated(Info.IsDeprecated),
91+
IsProtocolReq(Info.IsProtocolReq),
9092
ReferenceOwnership(uint8_t(Info.ReferenceOwnership)),
9193
GenericSig(Info.GenericSig) {}
9294

@@ -591,6 +593,9 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
591593
case KeyKind::KK_deprecated:
592594
Info.IsDeprecated = true;
593595
break;
596+
case KeyKind::KK_protocolReq:
597+
Info.IsProtocolReq = true;
598+
break;
594599
case KeyKind::KK_implicit:
595600
Info.IsImplicit = true;
596601
break;
@@ -1053,6 +1058,7 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
10531058
IsThrowing(isFuncThrowing(VD)), IsMutating(isFuncMutating(VD)),
10541059
IsStatic(VD->isStatic()),
10551060
IsDeprecated(VD->getAttrs().getDeprecated(VD->getASTContext())),
1061+
IsProtocolReq(isa<ProtocolDecl>(VD->getDeclContext()) && VD->isProtocolRequirement()),
10561062
SelfIndex(getSelfIndex(VD)), FixedBinaryOrder(getFixedBinaryOrder(VD)),
10571063
ReferenceOwnership(getReferenceOwnership(VD)),
10581064
GenericSig(printGenericSignature(Ctx, VD)) {
@@ -1476,6 +1482,10 @@ struct ObjectTraits<SDKNode *> {
14761482
if (bool isDeprecated = D->isDeprecated())
14771483
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_deprecated).data(),
14781484
isDeprecated);
1485+
if (bool isProtocolReq = D->isProtocolRequirement()) {
1486+
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_protocolReq).data(),
1487+
isProtocolReq);
1488+
}
14791489
if (bool isImplicit = D->isImplicit())
14801490
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_implicit).data(),
14811491
isImplicit);

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ class SDKNodeDecl: public SDKNode {
278278
bool IsImplicit;
279279
bool IsStatic;
280280
bool IsDeprecated;
281+
bool IsProtocolReq;
281282
uint8_t ReferenceOwnership;
282283
StringRef GenericSig;
283284

@@ -301,6 +302,7 @@ class SDKNodeDecl: public SDKNode {
301302
StringRef getFullyQualifiedName() const;
302303
bool isSDKPrivate() const;
303304
bool isDeprecated() const { return IsDeprecated; };
305+
bool isProtocolRequirement() const { return IsProtocolReq; }
304306
bool hasDeclAttribute(DeclAttrKind DAKind) const;
305307
bool isImplicit() const { return IsImplicit; };
306308
bool isStatic() const { return IsStatic; };

0 commit comments

Comments
 (0)