Skip to content

Commit 7d440c1

Browse files
authored
Merge pull request #19539 from nkcsgexi/overriding-proto
swift-module-digester: don't diagnose new protocol requirements if they're inherited.
2 parents a7b00dd + cf03b24 commit 7d440c1

File tree

13 files changed

+225
-25
lines changed

13 files changed

+225
-25
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(overriding)
105106
KEY(protocolReq)
106107
KEY(implicit)
107108
KEY(typeAttributes)

test/api-digester/Inputs/cake.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ public extension ProWithAssociatedType {
6565
func NonReqFunc() {}
6666
var NonReqVar: Int { return 1 }
6767
typealias NonReqAlias = Int
68-
}
68+
}
69+
70+
public protocol PSuper {
71+
associatedtype T
72+
func foo()
73+
}
74+
75+
public protocol PSub: PSuper {
76+
associatedtype T
77+
func foo()
78+
}

test/api-digester/Inputs/cake1.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ public protocol RequiementChanges {
9090
var removedVar: Int {get}
9191
}
9292

93+
/// This protocol shouldn't be complained because its requirements are all derived.
94+
public protocol DerivedProtocolRequiementChanges: RequiementChanges {}
95+
9396
public class SuperClassRemoval: C3 {}
9497

9598
public class ClassToStruct {}
9699
public protocol ProtocolToEnum {}
97100

98101
public class SuperClassChange: C7 {}
102+
103+
public class GenericClass<T> {}
104+
105+
public class SubGenericClass: GenericClass<P1> {}

test/api-digester/Inputs/cake2.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ public protocol RequiementChanges {
9999
var addedVar: Int { get }
100100
}
101101

102+
/// This protocol shouldn't be complained because its requirements are all derived.
103+
public protocol DerivedProtocolRequiementChanges: RequiementChanges {}
104+
102105
public class SuperClassRemoval {}
103106

104107
public struct ClassToStruct {}
105108
public enum ProtocolToEnum {}
106109

107110
public class SuperClassChange: C8 {}
111+
112+
113+
public class GenericClass<T> {}
114+
115+
public class SubGenericClass: GenericClass<P2> {}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
6464

6565
/* Class Inheritance Change */
6666
cake1: Class C4 has changed its super class from OldType to NewType
67+
cake1: Class SubGenericClass has changed its super class from GenericClass<P1> to GenericClass<P2>
6768
cake1: Class SuperClassRemoval has removed its super class C3

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
5050

5151
/* Class Inheritance Change */
5252
cake1: Class C4 has changed its super class from OldType to NewType
53+
cake1: Class SubGenericClass has changed its super class from GenericClass<P1> to GenericClass<P2>
5354
cake1: Class SuperClassRemoval has removed its super class C3

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

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
"moduleName": "cake",
200200
"superclassUsr": "s:4cake2C0C",
201201
"superclassNames": [
202-
"C0"
202+
"C0<S1, S1, S1>"
203203
],
204204
"children": [
205205
{
@@ -379,6 +379,7 @@
379379
"usr": "s:4cake2C1CACycfc",
380380
"location": "",
381381
"moduleName": "cake",
382+
"overriding": true,
382383
"implicit": true,
383384
"children": [
384385
{
@@ -1083,6 +1084,93 @@
10831084
}
10841085
]
10851086
},
1087+
{
1088+
"kind": "TypeDecl",
1089+
"name": "PSuper",
1090+
"printedName": "PSuper",
1091+
"declKind": "Protocol",
1092+
"usr": "s:4cake6PSuperP",
1093+
"location": "",
1094+
"moduleName": "cake",
1095+
"children": [
1096+
{
1097+
"kind": "AssociatedType",
1098+
"name": "T",
1099+
"printedName": "T",
1100+
"declKind": "AssociatedType",
1101+
"usr": "s:4cake6PSuperP1TQa",
1102+
"location": "",
1103+
"moduleName": "cake",
1104+
"protocolReq": true
1105+
},
1106+
{
1107+
"kind": "Function",
1108+
"name": "foo",
1109+
"printedName": "foo()",
1110+
"declKind": "Func",
1111+
"usr": "s:4cake6PSuperP3fooyyF",
1112+
"location": "",
1113+
"moduleName": "cake",
1114+
"genericSig": "<τ_0_0 where τ_0_0 : PSuper>",
1115+
"protocolReq": true,
1116+
"children": [
1117+
{
1118+
"kind": "TypeNominal",
1119+
"name": "Void",
1120+
"printedName": "()"
1121+
}
1122+
]
1123+
}
1124+
]
1125+
},
1126+
{
1127+
"kind": "TypeDecl",
1128+
"name": "PSub",
1129+
"printedName": "PSub",
1130+
"declKind": "Protocol",
1131+
"usr": "s:4cake4PSubP",
1132+
"location": "",
1133+
"moduleName": "cake",
1134+
"genericSig": "<τ_0_0 : PSuper>",
1135+
"conformingProtocols": [
1136+
"PSuper"
1137+
],
1138+
"children": [
1139+
{
1140+
"kind": "AssociatedType",
1141+
"name": "T",
1142+
"printedName": "T",
1143+
"declKind": "AssociatedType",
1144+
"usr": "s:4cake4PSubP1TQa",
1145+
"location": "",
1146+
"moduleName": "cake",
1147+
"protocolReq": true,
1148+
"overriding": true
1149+
},
1150+
{
1151+
"kind": "Function",
1152+
"name": "foo",
1153+
"printedName": "foo()",
1154+
"declKind": "Func",
1155+
"usr": "s:4cake4PSubP3fooyyF",
1156+
"location": "",
1157+
"moduleName": "cake",
1158+
"genericSig": "<τ_0_0 where τ_0_0 : PSub>",
1159+
"protocolReq": true,
1160+
"overriding": true,
1161+
"declAttributes": [
1162+
"Override"
1163+
],
1164+
"children": [
1165+
{
1166+
"kind": "TypeNominal",
1167+
"name": "Void",
1168+
"printedName": "()"
1169+
}
1170+
]
1171+
}
1172+
]
1173+
},
10861174
{
10871175
"kind": "TypeDecl",
10881176
"name": "Int",

test/api-digester/Outputs/cake.json

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
"moduleName": "cake",
207207
"superclassUsr": "s:4cake2C0C",
208208
"superclassNames": [
209-
"C0"
209+
"C0<S1, S1, S1>"
210210
],
211211
"children": [
212212
{
@@ -386,6 +386,7 @@
386386
"usr": "s:4cake2C1CACycfc",
387387
"location": "",
388388
"moduleName": "cake",
389+
"overriding": true,
389390
"implicit": true,
390391
"children": [
391392
{
@@ -1013,6 +1014,93 @@
10131014
}
10141015
]
10151016
},
1017+
{
1018+
"kind": "TypeDecl",
1019+
"name": "PSuper",
1020+
"printedName": "PSuper",
1021+
"declKind": "Protocol",
1022+
"usr": "s:4cake6PSuperP",
1023+
"location": "",
1024+
"moduleName": "cake",
1025+
"children": [
1026+
{
1027+
"kind": "AssociatedType",
1028+
"name": "T",
1029+
"printedName": "T",
1030+
"declKind": "AssociatedType",
1031+
"usr": "s:4cake6PSuperP1TQa",
1032+
"location": "",
1033+
"moduleName": "cake",
1034+
"protocolReq": true
1035+
},
1036+
{
1037+
"kind": "Function",
1038+
"name": "foo",
1039+
"printedName": "foo()",
1040+
"declKind": "Func",
1041+
"usr": "s:4cake6PSuperP3fooyyF",
1042+
"location": "",
1043+
"moduleName": "cake",
1044+
"genericSig": "<Self where Self : PSuper>",
1045+
"protocolReq": true,
1046+
"children": [
1047+
{
1048+
"kind": "TypeNominal",
1049+
"name": "Void",
1050+
"printedName": "()"
1051+
}
1052+
]
1053+
}
1054+
]
1055+
},
1056+
{
1057+
"kind": "TypeDecl",
1058+
"name": "PSub",
1059+
"printedName": "PSub",
1060+
"declKind": "Protocol",
1061+
"usr": "s:4cake4PSubP",
1062+
"location": "",
1063+
"moduleName": "cake",
1064+
"genericSig": "<Self : PSuper>",
1065+
"conformingProtocols": [
1066+
"PSuper"
1067+
],
1068+
"children": [
1069+
{
1070+
"kind": "AssociatedType",
1071+
"name": "T",
1072+
"printedName": "T",
1073+
"declKind": "AssociatedType",
1074+
"usr": "s:4cake4PSubP1TQa",
1075+
"location": "",
1076+
"moduleName": "cake",
1077+
"protocolReq": true,
1078+
"overriding": true
1079+
},
1080+
{
1081+
"kind": "Function",
1082+
"name": "foo",
1083+
"printedName": "foo()",
1084+
"declKind": "Func",
1085+
"usr": "s:4cake4PSubP3fooyyF",
1086+
"location": "",
1087+
"moduleName": "cake",
1088+
"genericSig": "<Self where Self : PSub>",
1089+
"protocolReq": true,
1090+
"overriding": true,
1091+
"declAttributes": [
1092+
"Override"
1093+
],
1094+
"children": [
1095+
{
1096+
"kind": "TypeNominal",
1097+
"name": "Void",
1098+
"printedName": "()"
1099+
}
1100+
]
1101+
}
1102+
]
1103+
},
10161104
{
10171105
"kind": "TypeDecl",
10181106
"name": "Int",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"usr": "c:objc(cs)NSObject(im)init",
5858
"location": "",
5959
"moduleName": "Foo",
60+
"overriding": true,
6061
"implicit": true,
6162
"declAttributes": [
6263
"Override",

test/api-digester/source-stability.swift.expected

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,10 @@ Var Dictionary.values has declared type change from LazyMapCollection<[Key : Val
9090
/* Decl Attribute changes */
9191

9292
/* Protocol Requirement Changes */
93-
AssociatedType BidirectionalCollection.Element has been added as a protocol requirement
94-
AssociatedType BidirectionalCollection.Index has been added as a protocol requirement
95-
AssociatedType BidirectionalCollection.Indices has been added as a protocol requirement
96-
AssociatedType BidirectionalCollection.SubSequence has been added as a protocol requirement
9793
AssociatedType BinaryFloatingPoint.RawExponent has been added as a protocol requirement
9894
AssociatedType BinaryFloatingPoint.RawSignificand has been added as a protocol requirement
9995
AssociatedType BinaryInteger.Words has been added as a protocol requirement
10096
AssociatedType CaseIterable.AllCases has been added as a protocol requirement
101-
AssociatedType Collection.Element has been added as a protocol requirement
10297
AssociatedType Collection.Index has been added as a protocol requirement
10398
AssociatedType ExpressibleByArrayLiteral.ArrayLiteralElement has been added as a protocol requirement
10499
AssociatedType ExpressibleByBooleanLiteral.BooleanLiteralType has been added as a protocol requirement
@@ -113,16 +108,8 @@ AssociatedType FloatingPoint.Exponent has been added as a protocol requirement
113108
AssociatedType IteratorProtocol.Element has been added as a protocol requirement
114109
AssociatedType KeyedDecodingContainerProtocol.Key has been added as a protocol requirement
115110
AssociatedType KeyedEncodingContainerProtocol.Key has been added as a protocol requirement
116-
AssociatedType MutableCollection.Element has been added as a protocol requirement
117-
AssociatedType MutableCollection.Index has been added as a protocol requirement
118-
AssociatedType MutableCollection.SubSequence has been added as a protocol requirement
119111
AssociatedType Numeric.Magnitude has been added as a protocol requirement
120-
AssociatedType RandomAccessCollection.Element has been added as a protocol requirement
121-
AssociatedType RandomAccessCollection.Index has been added as a protocol requirement
122-
AssociatedType RandomAccessCollection.Indices has been added as a protocol requirement
123-
AssociatedType RandomAccessCollection.SubSequence has been added as a protocol requirement
124112
AssociatedType RangeExpression.Bound has been added as a protocol requirement
125-
AssociatedType RangeReplaceableCollection.SubSequence has been added as a protocol requirement
126113
AssociatedType RawRepresentable.RawValue has been added as a protocol requirement
127114
AssociatedType Sequence.Element has been added as a protocol requirement
128115
AssociatedType Sequence.Iterator has been added as a protocol requirement
@@ -135,8 +122,4 @@ AssociatedType _SequenceWrapper.Base has been added as a protocol requirement
135122
Func BinaryInteger.isMultiple(of:) has been added as a protocol requirement
136123

137124
// The subscript changes are bogus because we don't have subscript decls in the baseline.
138-
Subscript BidirectionalCollection.subscript(_:) has been added as a protocol requirement
139125
Subscript Collection.subscript(_:) has been added as a protocol requirement
140-
Subscript MutableCollection.subscript(_:) has been added as a protocol requirement
141-
Subscript RandomAccessCollection.subscript(_:) has been added as a protocol requirement
142-
Subscript RangeReplaceableCollection.subscript(_:) has been added as a protocol requirement

0 commit comments

Comments
 (0)