Skip to content

Commit f7406e6

Browse files
committed
swift-api-digester: diagnose changing of the necessity of new witness table entry as ABI breakage
Protocol requirements may not necessarily add new entries to the witness table if it's inherited from super protocol. This patch teaches the json dump to include a flag indicating whether a protocol requirement requires new witness table entry and diagnoses the change of such flag as ABI breakages. rdar://47657204
1 parent f85ca6c commit f7406e6

16 files changed

+186
-89
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ ERROR(param_ownership_change,none,"%0 has %1 changing from %2 to %3", (StringRef
9292

9393
ERROR(type_witness_change,none,"%0 has type witness type for %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
9494

95+
ERROR(decl_new_witness_table_entry,none,"%0 now requires %select{|no}1 new witness table entry", (StringRef, bool))
96+
9597
#ifndef DIAG_NO_UNDEF
9698
# if defined(DIAG)
9799
# undef DIAG

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ KEY_BOOL(IsInternal, isInternal)
133133
KEY_BOOL(HasStorage, hasStorage)
134134
KEY_BOOL(HasDidset, hasDidset)
135135
KEY_BOOL(HasWillset, hasWillset)
136+
KEY_BOOL(ReqNewWitnessTableEntry, reqNewWitnessTableEntry)
136137

137138
KEY(kind)
138139

test/api-digester/Inputs/cake1.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,13 @@ public protocol AssociatedTypesProtocol {
158158
public class TChangesFromIntToString: AssociatedTypesProtocol {
159159
public typealias T = Int
160160
}
161+
162+
public protocol HasMutatingMethod {
163+
mutating func foo()
164+
var bar: Int { mutating get }
165+
}
166+
167+
public protocol HasMutatingMethodClone: HasMutatingMethod {
168+
mutating func foo()
169+
var bar: Int { mutating get }
170+
}

test/api-digester/Inputs/cake2.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,13 @@ public protocol AssociatedTypesProtocol {
169169
public class TChangesFromIntToString: AssociatedTypesProtocol {
170170
public typealias T = String
171171
}
172+
173+
public protocol HasMutatingMethod {
174+
mutating func foo()
175+
var bar: Int { mutating get }
176+
}
177+
178+
public protocol HasMutatingMethodClone: HasMutatingMethod {
179+
func foo()
180+
var bar: Int { get }
181+
}

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

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

88
/* Removed Decls */
9+
cake1: Accessor GlobalVarChangedToLet.Set() has been removed
10+
cake1: Accessor RemoveSetters.Value.Set() has been removed
911
cake1: AssociatedType RequiementChanges.removedType has been removed
1012
cake1: Class C3 has been removed
1113
cake1: Constructor Somestruct2.init(_:) has been removed
@@ -45,6 +47,7 @@ cake1: Func C1.foo1() is now not static
4547
cake1: Func C5.dy_foo() is now with dynamic
4648
cake1: Func FinalFuncContainer.NewFinalFunc() is now with final
4749
cake1: Func FinalFuncContainer.NoLongerFinalFunc() is now without final
50+
cake1: Func HasMutatingMethodClone.foo() has self access kind changing from Mutating to NonMutating
4851
cake1: Func S1.foo1() has self access kind changing from NonMutating to Mutating
4952
cake1: Func S1.foo3() is now static
5053
cake1: Func _NoResilientClass.NoLongerFinalFunc() is now without final
@@ -73,7 +76,9 @@ cake1: Struct fixedLayoutStruct has removed conformance to P1
7376
cake2: Protocol P3 has added inherited protocol P4
7477

7578
/* Protocol Requirement Change */
79+
cake1: Accessor HasMutatingMethodClone.bar.Get() now requires new witness table entry
7680
cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int
81+
cake1: Func HasMutatingMethodClone.foo() now requires new witness table entry
7782
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault has been added as a protocol requirement
7883
cake2: Func RequiementChanges.addedFunc() has been added as a protocol requirement
7984
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement

test/api-digester/Outputs/Cake.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ cake1: Protocol P3 has generic signature change from <Self : cake.P1, Self : cak
66
/* RawRepresentable Changes */
77

88
/* Removed Decls */
9+
cake1: Accessor GlobalVarChangedToLet.Set() has been removed
10+
cake1: Accessor RemoveSetters.Value.Set() has been removed
911
cake1: AssociatedType RequiementChanges.removedType has been removed
1012
cake1: Constructor Somestruct2.init(_:) has been removed
1113
cake1: Func C4.foo() has been removed
@@ -38,6 +40,7 @@ cake1: TypeAlias TChangesFromIntToString.T has underlying type change from Int t
3840
cake1: Func C1.foo1() is now not static
3941
cake1: Func FinalFuncContainer.NewFinalFunc() is now with final
4042
cake1: Func FinalFuncContainer.NoLongerFinalFunc() is now without final
43+
cake1: Func HasMutatingMethodClone.foo() has self access kind changing from Mutating to NonMutating
4144
cake1: Func S1.foo1() has self access kind changing from NonMutating to Mutating
4245
cake1: Func S1.foo3() is now static
4346
cake1: Var C1.CIIns1 changes from weak to strong
@@ -54,6 +57,7 @@ cake1: AssociatedType AssociatedTypePro.T1 has removed default type Int
5457
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault has been added as a protocol requirement
5558
cake2: Func RequiementChanges.addedFunc() has been added as a protocol requirement
5659
cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
60+
cake1: Accessor ClassWithOpenMember.property.Get() is no longer open for subclassing
5761

5862
/* Class Inheritance Change */
5963
cake1: Class C4 has changed its super class from OldType to NewType

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@
226226
},
227227
{
228228
"kind": "Getter",
229-
"name": "_",
230-
"printedName": "_()",
229+
"name": "Get",
230+
"printedName": "Get()",
231231
"children": [
232232
{
233233
"kind": "TypeNominal",
@@ -254,8 +254,8 @@
254254
},
255255
{
256256
"kind": "Setter",
257-
"name": "_",
258-
"printedName": "_()",
257+
"name": "Set",
258+
"printedName": "Set()",
259259
"children": [
260260
{
261261
"kind": "TypeNominal",
@@ -310,8 +310,8 @@
310310
},
311311
{
312312
"kind": "Getter",
313-
"name": "_",
314-
"printedName": "_()",
313+
"name": "Get",
314+
"printedName": "Get()",
315315
"children": [
316316
{
317317
"kind": "TypeNominal",
@@ -330,8 +330,8 @@
330330
},
331331
{
332332
"kind": "Setter",
333-
"name": "_",
334-
"printedName": "_()",
333+
"name": "Set",
334+
"printedName": "Set()",
335335
"children": [
336336
{
337337
"kind": "TypeNominal",
@@ -522,8 +522,8 @@
522522
},
523523
{
524524
"kind": "Getter",
525-
"name": "_",
526-
"printedName": "_()",
525+
"name": "Get",
526+
"printedName": "Get()",
527527
"children": [
528528
{
529529
"kind": "TypeNominal",
@@ -638,8 +638,8 @@
638638
},
639639
{
640640
"kind": "Getter",
641-
"name": "_",
642-
"printedName": "_()",
641+
"name": "Get",
642+
"printedName": "Get()",
643643
"children": [
644644
{
645645
"kind": "TypeNominal",
@@ -658,8 +658,8 @@
658658
},
659659
{
660660
"kind": "Setter",
661-
"name": "_",
662-
"printedName": "_()",
661+
"name": "Set",
662+
"printedName": "Set()",
663663
"children": [
664664
{
665665
"kind": "TypeNominal",
@@ -705,8 +705,8 @@
705705
},
706706
{
707707
"kind": "Getter",
708-
"name": "_",
709-
"printedName": "_()",
708+
"name": "Get",
709+
"printedName": "Get()",
710710
"children": [
711711
{
712712
"kind": "TypeNominal",
@@ -751,8 +751,8 @@
751751
},
752752
{
753753
"kind": "Getter",
754-
"name": "_",
755-
"printedName": "_()",
754+
"name": "Get",
755+
"printedName": "Get()",
756756
"children": [
757757
{
758758
"kind": "TypeNominal",
@@ -795,8 +795,8 @@
795795
},
796796
{
797797
"kind": "Getter",
798-
"name": "_",
799-
"printedName": "_()",
798+
"name": "Get",
799+
"printedName": "Get()",
800800
"children": [
801801
{
802802
"kind": "TypeNominal",
@@ -895,8 +895,8 @@
895895
},
896896
{
897897
"kind": "Getter",
898-
"name": "_",
899-
"printedName": "_()",
898+
"name": "Get",
899+
"printedName": "Get()",
900900
"children": [
901901
{
902902
"kind": "TypeNominal",
@@ -1009,6 +1009,7 @@
10091009
"moduleName": "cake",
10101010
"genericSig": "<τ_0_0 where τ_0_0 : PSuper>",
10111011
"protocolReq": true,
1012+
"reqNewWitnessTableEntry": true,
10121013
"funcSelfKind": "NonMutating"
10131014
}
10141015
],
@@ -1116,8 +1117,8 @@
11161117
},
11171118
{
11181119
"kind": "Getter",
1119-
"name": "_",
1120-
"printedName": "_()",
1120+
"name": "Get",
1121+
"printedName": "Get()",
11211122
"children": [
11221123
{
11231124
"kind": "TypeNominal",

test/api-digester/Outputs/cake.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@
270270
},
271271
{
272272
"kind": "Getter",
273-
"name": "_",
274-
"printedName": "_()",
273+
"name": "Get",
274+
"printedName": "Get()",
275275
"children": [
276276
{
277277
"kind": "TypeNominal",
@@ -298,8 +298,8 @@
298298
},
299299
{
300300
"kind": "Setter",
301-
"name": "_",
302-
"printedName": "_()",
301+
"name": "Set",
302+
"printedName": "Set()",
303303
"children": [
304304
{
305305
"kind": "TypeNominal",
@@ -353,8 +353,8 @@
353353
},
354354
{
355355
"kind": "Getter",
356-
"name": "_",
357-
"printedName": "_()",
356+
"name": "Get",
357+
"printedName": "Get()",
358358
"children": [
359359
{
360360
"kind": "TypeNominal",
@@ -373,8 +373,8 @@
373373
},
374374
{
375375
"kind": "Setter",
376-
"name": "_",
377-
"printedName": "_()",
376+
"name": "Set",
377+
"printedName": "Set()",
378378
"children": [
379379
{
380380
"kind": "TypeNominal",
@@ -587,8 +587,8 @@
587587
},
588588
{
589589
"kind": "Getter",
590-
"name": "_",
591-
"printedName": "_()",
590+
"name": "Get",
591+
"printedName": "Get()",
592592
"children": [
593593
{
594594
"kind": "TypeNominal",
@@ -703,8 +703,8 @@
703703
},
704704
{
705705
"kind": "Getter",
706-
"name": "_",
707-
"printedName": "_()",
706+
"name": "Get",
707+
"printedName": "Get()",
708708
"children": [
709709
{
710710
"kind": "TypeNominal",
@@ -723,8 +723,8 @@
723723
},
724724
{
725725
"kind": "Setter",
726-
"name": "_",
727-
"printedName": "_()",
726+
"name": "Set",
727+
"printedName": "Set()",
728728
"children": [
729729
{
730730
"kind": "TypeNominal",
@@ -825,8 +825,8 @@
825825
},
826826
{
827827
"kind": "Getter",
828-
"name": "_",
829-
"printedName": "_()",
828+
"name": "Get",
829+
"printedName": "Get()",
830830
"children": [
831831
{
832832
"kind": "TypeNominal",
@@ -956,6 +956,7 @@
956956
"moduleName": "cake",
957957
"genericSig": "<Self where Self : PSuper>",
958958
"protocolReq": true,
959+
"reqNewWitnessTableEntry": true,
959960
"funcSelfKind": "NonMutating"
960961
}
961962
],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"declAttributes": [
3535
"ObjC"
3636
],
37+
"reqNewWitnessTableEntry": true,
3738
"funcSelfKind": "NonMutating"
3839
}
3940
],
@@ -154,6 +155,7 @@
154155
"declAttributes": [
155156
"ObjC"
156157
],
158+
"reqNewWitnessTableEntry": true,
157159
"funcSelfKind": "NonMutating"
158160
}
159161
],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t.mod1)
2+
// RUN: %empty-directory(%t.mod2)
3+
// RUN: %empty-directory(%t.sdk)
4+
// RUN: %empty-directory(%t.module-cache)
5+
// RUN: %swift -emit-module -o %t.mod1/cake.swiftmodule %S/Inputs/cake1.swift -parse-as-library -enable-library-evolution -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource
6+
// RUN: %swift -emit-module -o %t.mod2/cake.swiftmodule %S/Inputs/cake2.swift -parse-as-library -enable-library-evolution -I %S/Inputs/APINotesRight %clang-importer-sdk-nosource
7+
// RUN: %api-digester -dump-sdk -module cake -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod1 -I %S/Inputs/APINotesLeft -abi | sed 's/"cake"/"cake1"/' > %t.dump1.json
8+
// RUN: %api-digester -dump-sdk -module cake -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod2 -I %S/Inputs/APINotesLeft -abi | sed 's/"cake"/"cake2"/' > %t.dump2.json
9+
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json -abi -o %t.result
10+
// RUN: %clang -E -P -x c %S/Outputs/Cake-abi.txt -o - | sed '/^\s*$/d' > %t.abi.expected
11+
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.abi.result.tmp
12+
// RUN: diff -u %t.abi.expected %t.abi.result.tmp

test/api-digester/compare-dump.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@
1111
// RUN: %clang -E -P -x c %S/Outputs/Cake.txt -o - | sed '/^\s*$/d' > %t.expected
1212
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
1313
// RUN: diff -u %t.expected %t.result.tmp
14-
15-
// RUN: %api-digester -dump-sdk -module cake -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod1 -I %S/Inputs/APINotesLeft -abi | sed 's/"cake"/"cake1"/' > %t.dump1.json
16-
// RUN: %api-digester -dump-sdk -module cake -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod2 -I %S/Inputs/APINotesLeft -abi | sed 's/"cake"/"cake2"/' > %t.dump2.json
17-
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json -abi -o %t.result
18-
19-
// RUN: %clang -E -P -x c %S/Outputs/Cake-abi.txt -o - | sed '/^\s*$/d' > %t.abi.expected
20-
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.abi.result.tmp
21-
// RUN: diff -u %t.abi.expected %t.abi.result.tmp

tools/swift-api-digester/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ add_swift_host_tool(swift-api-digester
88
target_link_libraries(swift-api-digester
99
PRIVATE
1010
swiftFrontend
11+
swiftSIL
1112
swiftIDE)

0 commit comments

Comments
 (0)