Skip to content

Commit ea70b2e

Browse files
authored
Merge pull request swiftlang#19487 from nkcsgexi/add-prot-req
swift-module-digester: diagnose added protocol requirements
2 parents c05238a + 4e3f8f4 commit ea70b2e

15 files changed

+263
-2
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ ERROR(conformance_added,none,"%0 has added inherited protocol %1", (StringRef, S
6666

6767
ERROR(default_associated_type_removed,none,"%0 has removed default type %1", (StringRef, StringRef))
6868

69+
ERROR(protocol_req_added,none,"%0 has been added as a protocol requirement", (StringRef))
70+
6971
#ifndef DIAG_NO_UNDEF
7072
# if defined(DIAG)
7173
# undef DIAG

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/Inputs/cake1.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ public class RemoveSetters {
8383
set(newValue) {}
8484
}
8585
}
86+
87+
public protocol RequiementChanges {
88+
func removedFunc()
89+
associatedtype removedType
90+
var removedVar: Int {get}
91+
}

test/api-digester/Inputs/cake2.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ public class RemoveSetters {
9090
}
9191
}
9292

93+
public protocol RequiementChanges {
94+
associatedtype addedTypeWithDefault = Int
95+
associatedtype addedTypeWithoutDefault
96+
func addedFunc()
97+
var addedVar: Int { get }
98+
}

test/api-digester/Outputs/Cake-abi.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ cake1: Protocol P3 has generic signature change from <τ_0_0 : P1, τ_0_0 : P2>
66
/* RawRepresentable Changes */
77

88
/* Removed Decls */
9+
cake1: AssociatedType RequiementChanges.removedType has been removed
910
cake1: Constructor Somestruct2.init(_:) has been removed
1011
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1112
cake1: Func C4.foo() has been removed
13+
cake1: Func RequiementChanges.removedFunc() has been removed
1214
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter
1315
cake1: Var RemoveSetters.Value has removed its setter
16+
cake1: Var RequiementChanges.removedVar has been removed
1417

1518
/* Moved Decls */
1619

@@ -53,3 +56,6 @@ cake1: Struct fixedLayoutStruct has removed conformance to P1
5356

5457
/* Protocol Requirement Change */
5558
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int
59+
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault has been added as a protocol requirement
60+
cake2: Func RequiementChanges.addedFunc() has been added as a protocol requirement
61+
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement

test/api-digester/Outputs/Cake.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ cake1: Protocol P3 has generic signature change from <Self : P1, Self : P2> to <
66
/* RawRepresentable Changes */
77

88
/* Removed Decls */
9+
cake1: AssociatedType RequiementChanges.removedType has been removed
910
cake1: Constructor Somestruct2.init(_:) has been removed
1011
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
1112
cake1: Func C4.foo() has been removed
13+
cake1: Func RequiementChanges.removedFunc() has been removed
1214
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter
1315
cake1: Var RemoveSetters.Value has removed its setter
16+
cake1: Var RequiementChanges.removedVar has been removed
1417

1518
/* Moved Decls */
1619

@@ -39,3 +42,6 @@ cake1: Struct fixedLayoutStruct has removed conformance to P1
3942

4043
/* Protocol Requirement Change */
4144
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int
45+
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault has been added as a protocol requirement
46+
cake2: Func RequiementChanges.addedFunc() has been added as a protocol requirement
47+
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement

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
],

0 commit comments

Comments
 (0)