Skip to content

Commit 93e06fc

Browse files
committed
ABI/API checker: diagnose ObjC name changes as breakages
rdar://54797695
1 parent e7484de commit 93e06fc

File tree

15 files changed

+187
-9
lines changed

15 files changed

+187
-9
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ ERROR(decl_new_witness_table_entry,none,"%0 now requires %select{|no}1 new witne
9696

9797
ERROR(new_decl_without_intro,none,"%0 is a new API without @available attribute", (StringRef))
9898

99+
ERROR(objc_name_change,none,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
100+
99101
#ifndef DIAG_NO_UNDEF
100102
# if defined(DIAG)
101103
# undef DIAG

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ KEY_STRING(IntroiOS, intro_iOS)
151151
KEY_STRING(IntrotvOS, intro_tvOS)
152152
KEY_STRING(IntrowatchOS, intro_watchOS)
153153
KEY_STRING(Introswift, intro_swift)
154+
KEY_STRING(ObjCName, objc_name)
154155

155156
KEY_STRING_ARR(SuperclassNames, superclassNames)
156157
KEY_STRING_ARR(ToolArgs, tool_arguments)

test/api-digester/Inputs/cake.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public protocol P1 {}
44
public protocol P2 {}
55
public protocol P3: P2, P1 {}
6+
67
@frozen
78
public struct S1: P1 {
89
public static func foo1() {}
@@ -123,3 +124,9 @@ public class PlatformIntroClass {}
123124

124125
@available(swift, introduced: 5)
125126
public class SwiftIntroClass {}
127+
128+
@objc(NewObjCClass)
129+
public class SwiftObjcClass {
130+
@objc(ObjCFool:ObjCA:ObjCB:)
131+
public func foo(a:Int, b:Int, c: Int) {}
132+
}

test/api-digester/Inputs/cake_baseline/cake.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,9 @@ public class Zoo {
195195
}
196196

197197
public func returnFunctionTypeOwnershipChange() -> (C1) -> () { return { _ in } }
198+
199+
@objc(OldObjCClass)
200+
public class SwiftObjcClass {
201+
@objc(OldObjCFool:OldObjCA:OldObjCB:)
202+
public func foo(a:Int, b:Int, c: Int) {}
203+
}

test/api-digester/Inputs/cake_current/cake.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,9 @@ public class Zoo {
202202
}
203203

204204
public func returnFunctionTypeOwnershipChange() -> (__owned C1) -> () { return { _ in } }
205+
206+
@objc(NewObjCClass)
207+
public class SwiftObjcClass {
208+
@objc(NewObjCFool:NewObjCA:NewObjCB:)
209+
public func foo(a:Int, b:Int, c: Int) {}
210+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ cake: InfixOperator ..*.. has been changed to a PrefixOperator
2727
cake: Protocol ProtocolToEnum has been changed to a Enum
2828

2929
/* Renamed Decls */
30+
cake: Class SwiftObjcClass has ObjC name change from OldObjCClass to NewObjCClass
3031
cake: Func S1.foo5(x:y:) has been renamed to Func foo5(x:y:z:)
32+
cake: Func SwiftObjcClass.foo(a:b:c:) has ObjC name change from OldObjCFool:OldObjCA:OldObjCB: to NewObjCFool:NewObjCA:NewObjCB:
3133
cake: Struct Somestruct2 has been renamed to Struct NSSomestruct2
3234

3335
/* Type Changes */

test/api-digester/Outputs/Cake.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ cake: InfixOperator ..*.. has been changed to a PrefixOperator
2222
cake: Protocol ProtocolToEnum has been changed to a Enum
2323

2424
/* Renamed Decls */
25+
cake: Class SwiftObjcClass has ObjC name change from OldObjCClass to NewObjCClass
2526
cake: Func S1.foo5(x:y:) has been renamed to Func foo5(x:y:z:)
27+
cake: Func SwiftObjcClass.foo(a:b:c:) has ObjC name change from OldObjCFool:OldObjCA:OldObjCB: to NewObjCFool:NewObjCA:NewObjCB:
2628
cake: Struct Somestruct2 has been renamed to Struct NSSomestruct2
2729

2830
/* Type Changes */

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,58 @@
14341434
"Available"
14351435
]
14361436
},
1437+
{
1438+
"kind": "TypeDecl",
1439+
"name": "SwiftObjcClass",
1440+
"printedName": "SwiftObjcClass",
1441+
"children": [
1442+
{
1443+
"kind": "Function",
1444+
"name": "foo",
1445+
"printedName": "foo(a:b:c:)",
1446+
"children": [
1447+
{
1448+
"kind": "TypeNominal",
1449+
"name": "Void",
1450+
"printedName": "()"
1451+
},
1452+
{
1453+
"kind": "TypeNominal",
1454+
"name": "Int",
1455+
"printedName": "Swift.Int",
1456+
"usr": "s:Si"
1457+
},
1458+
{
1459+
"kind": "TypeNominal",
1460+
"name": "Int",
1461+
"printedName": "Swift.Int",
1462+
"usr": "s:Si"
1463+
},
1464+
{
1465+
"kind": "TypeNominal",
1466+
"name": "Int",
1467+
"printedName": "Swift.Int",
1468+
"usr": "s:Si"
1469+
}
1470+
],
1471+
"declKind": "Func",
1472+
"usr": "c:@M@cake@objc(cs)NewObjCClass(im)ObjCFool:ObjCA:ObjCB:",
1473+
"moduleName": "cake",
1474+
"objc_name": "ObjCFool:ObjCA:ObjCB:",
1475+
"declAttributes": [
1476+
"ObjC"
1477+
],
1478+
"funcSelfKind": "NonMutating"
1479+
}
1480+
],
1481+
"declKind": "Class",
1482+
"usr": "c:@M@cake@objc(cs)NewObjCClass",
1483+
"moduleName": "cake",
1484+
"objc_name": "NewObjCClass",
1485+
"declAttributes": [
1486+
"ObjC"
1487+
]
1488+
},
14371489
{
14381490
"kind": "TypeDecl",
14391491
"name": "Int",
@@ -1774,5 +1826,5 @@
17741826
]
17751827
}
17761828
],
1777-
"json_format_version": 3
1829+
"json_format_version": 4
17781830
}

test/api-digester/Outputs/cake.json

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,58 @@
12791279
"Available"
12801280
]
12811281
},
1282+
{
1283+
"kind": "TypeDecl",
1284+
"name": "SwiftObjcClass",
1285+
"printedName": "SwiftObjcClass",
1286+
"children": [
1287+
{
1288+
"kind": "Function",
1289+
"name": "foo",
1290+
"printedName": "foo(a:b:c:)",
1291+
"children": [
1292+
{
1293+
"kind": "TypeNominal",
1294+
"name": "Void",
1295+
"printedName": "()"
1296+
},
1297+
{
1298+
"kind": "TypeNominal",
1299+
"name": "Int",
1300+
"printedName": "Swift.Int",
1301+
"usr": "s:Si"
1302+
},
1303+
{
1304+
"kind": "TypeNominal",
1305+
"name": "Int",
1306+
"printedName": "Swift.Int",
1307+
"usr": "s:Si"
1308+
},
1309+
{
1310+
"kind": "TypeNominal",
1311+
"name": "Int",
1312+
"printedName": "Swift.Int",
1313+
"usr": "s:Si"
1314+
}
1315+
],
1316+
"declKind": "Func",
1317+
"usr": "c:@M@cake@objc(cs)NewObjCClass(im)ObjCFool:ObjCA:ObjCB:",
1318+
"moduleName": "cake",
1319+
"objc_name": "ObjCFool:ObjCA:ObjCB:",
1320+
"declAttributes": [
1321+
"ObjC"
1322+
],
1323+
"funcSelfKind": "NonMutating"
1324+
}
1325+
],
1326+
"declKind": "Class",
1327+
"usr": "c:@M@cake@objc(cs)NewObjCClass",
1328+
"moduleName": "cake",
1329+
"objc_name": "NewObjCClass",
1330+
"declAttributes": [
1331+
"ObjC"
1332+
]
1333+
},
12821334
{
12831335
"kind": "TypeDecl",
12841336
"name": "Int",
@@ -1622,5 +1674,5 @@
16221674
]
16231675
}
16241676
],
1625-
"json_format_version": 3
1677+
"json_format_version": 4
16261678
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"moduleName": "Foo",
3232
"genericSig": "<Self where Self : Foo.AnotherObjcProt>",
3333
"protocolReq": true,
34+
"objc_name": "anotherFunctionFromProt",
3435
"declAttributes": [
3536
"ObjC"
3637
],
@@ -41,6 +42,7 @@
4142
"declKind": "Protocol",
4243
"usr": "c:objc(pl)AnotherObjcProt",
4344
"moduleName": "Foo",
45+
"objc_name": "AnotherObjcProt",
4446
"declAttributes": [
4547
"ObjC"
4648
]
@@ -72,6 +74,7 @@
7274
"usr": "c:objc(cs)ClangInterface(im)someFunction",
7375
"moduleName": "Foo",
7476
"isOpen": true,
77+
"objc_name": "someFunction",
7578
"declAttributes": [
7679
"ObjC"
7780
],
@@ -94,6 +97,7 @@
9497
"moduleName": "Foo",
9598
"overriding": true,
9699
"implicit": true,
100+
"objc_name": "init",
97101
"declAttributes": [
98102
"Override",
99103
"ObjC"
@@ -104,6 +108,7 @@
104108
"usr": "c:objc(cs)ClangInterface",
105109
"moduleName": "Foo",
106110
"isOpen": true,
111+
"objc_name": "ClangInterface",
107112
"declAttributes": [
108113
"ObjC"
109114
],
@@ -154,6 +159,7 @@
154159
"moduleName": "Foo",
155160
"genericSig": "<Self where Self : Foo.ObjcProt>",
156161
"protocolReq": true,
162+
"objc_name": "someFunctionFromProt",
157163
"declAttributes": [
158164
"ObjC"
159165
],
@@ -164,10 +170,11 @@
164170
"declKind": "Protocol",
165171
"usr": "c:objc(pl)ObjcProt",
166172
"moduleName": "Foo",
173+
"objc_name": "ObjcProt",
167174
"declAttributes": [
168175
"ObjC"
169176
]
170177
}
171178
],
172-
"json_format_version": 3
179+
"json_format_version": 4
173180
}

0 commit comments

Comments
 (0)