Skip to content

Commit 555ee21

Browse files
authored
Merge pull request #19373 from nkcsgexi/diagnose-reorder
swift-module-digester: diagnose reordering and adding decls in fixed layout types.
2 parents 4624858 + 05e1592 commit 555ee21

16 files changed

+443
-14
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ ERROR(decl_attr_change,none,"%0 changes from %1 to %2", (StringRef, StringRef, S
5252

5353
ERROR(decl_new_attr,none,"%0 is now %1", (StringRef, StringRef))
5454

55+
ERROR(decl_reorder,none,"%0 in a fixed layout type changes position from %1 to %2", (StringRef, unsigned, unsigned))
56+
5557
#ifndef DIAG_NO_UNDEF
5658
# if defined(DIAG)
5759
# undef DIAG

include/swift/IDE/DigesterEnums.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ KEY(throwing)
100100
KEY(mutating)
101101
KEY(static)
102102
KEY(deprecated)
103+
KEY(implicit)
103104
KEY(typeAttributes)
104105
KEY(declAttributes)
105106
KEY(declKind)
@@ -109,6 +110,7 @@ KEY(hasDefaultArg)
109110
KEY(conformingProtocols)
110111
KEY(enumRawTypeName)
111112
KEY(genericSig)
113+
KEY(fixedbinaryorder)
112114

113115
KNOWN_TYPE(Optional)
114116
KNOWN_TYPE(ImplicitlyUnwrappedOptional)

test/api-digester/Inputs/cake.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ public func foo3(_ a: [Int: String]) {}
4040

4141
public extension Int {
4242
public func foo() {}
43-
}
43+
}
44+
45+
@_fixed_layout
46+
public struct fixedLayoutStruct {
47+
public var a = 1
48+
}

test/api-digester/Inputs/cake1.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,17 @@ public protocol P2 {}
4747
public extension P1 where Self: P2 {
4848
func P1Constraint() {}
4949
}
50+
51+
@_fixed_layout
52+
public struct fixedLayoutStruct {
53+
public var b = 2
54+
public func foo() {}
55+
public var a = 1
56+
}
57+
58+
@_frozen
59+
public enum FrozenKind {
60+
case Unchanged
61+
case Fixed
62+
case Rigid
63+
}

test/api-digester/Inputs/cake2.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,17 @@ public protocol P2 {}
4747
public extension P1 {
4848
func P1Constraint() {}
4949
}
50+
51+
@_fixed_layout
52+
public struct fixedLayoutStruct {
53+
public var a = 1
54+
public var b = 2
55+
public func foo() {}
56+
}
57+
58+
@_frozen
59+
public enum FrozenKind {
60+
case Unchanged
61+
case Rigid
62+
case Fixed
63+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cake1: Func P1.P1Constraint() has generic signature change from <τ_0_0 where τ
66

77
/* Removed Decls */
88
cake1: Constructor Somestruct2.init(_:) has been removed
9+
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
910
cake1: Func C4.foo() has been removed
1011

1112
/* Moved Decls */
@@ -29,3 +30,9 @@ cake1: Func S1.foo3() is now static
2930
cake1: Struct C6 is now with @_fixed_layout
3031
cake1: Var C1.CIIns1 changes from weak to strong
3132
cake1: Var C1.CIIns2 changes from strong to weak
33+
34+
/* Fixed-layout Type changes */
35+
cake1: EnumElement FrozenKind.Fixed in a fixed layout type changes position from 1 to 2
36+
cake1: EnumElement FrozenKind.Rigid in a fixed layout type changes position from 2 to 1
37+
cake1: Var fixedLayoutStruct.a in a fixed layout type changes position from 1 to 0
38+
cake1: Var fixedLayoutStruct.b in a fixed layout type changes position from 0 to 1

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cake1: Func P1.P1Constraint() has generic signature change from <Self where Self
66

77
/* Removed Decls */
88
cake1: Constructor Somestruct2.init(_:) has been removed
9+
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
910
cake1: Func C4.foo() has been removed
1011

1112
/* Moved Decls */

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

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"usr": "s:4cake2S1VACycfc",
9696
"location": "",
9797
"moduleName": "cake",
98+
"implicit": true,
9899
"children": [
99100
{
100101
"kind": "TypeNominal",
@@ -125,6 +126,7 @@
125126
"location": "",
126127
"moduleName": "cake",
127128
"genericSig": "<τ_0_0, τ_0_1, τ_0_2>",
129+
"implicit": true,
128130
"children": [
129131
{
130132
"kind": "TypeNominal",
@@ -241,6 +243,7 @@
241243
"usr": "s:4cake2C1C3InsACSgXwvg",
242244
"location": "",
243245
"moduleName": "cake",
246+
"implicit": true,
244247
"declAttributes": [
245248
"Transparent"
246249
],
@@ -269,6 +272,7 @@
269272
"usr": "s:4cake2C1C3InsACSgXwvs",
270273
"location": "",
271274
"moduleName": "cake",
275+
"implicit": true,
272276
"declAttributes": [
273277
"Transparent"
274278
],
@@ -323,6 +327,7 @@
323327
"usr": "s:4cake2C1C4Ins2ACXovg",
324328
"location": "",
325329
"moduleName": "cake",
330+
"implicit": true,
326331
"declAttributes": [
327332
"Transparent"
328333
],
@@ -343,6 +348,7 @@
343348
"usr": "s:4cake2C1C4Ins2ACXovs",
344349
"location": "",
345350
"moduleName": "cake",
351+
"implicit": true,
346352
"declAttributes": [
347353
"Transparent"
348354
],
@@ -370,6 +376,7 @@
370376
"usr": "s:4cake2C1CACycfc",
371377
"location": "",
372378
"moduleName": "cake",
379+
"implicit": true,
373380
"children": [
374381
{
375382
"kind": "TypeNominal",
@@ -462,6 +469,7 @@
462469
"usr": "s:4cake6NumberO3oneyA2CmF",
463470
"location": "",
464471
"moduleName": "cake",
472+
"fixedbinaryorder": 0,
465473
"children": [
466474
{
467475
"kind": "TypeFunc",
@@ -499,6 +507,7 @@
499507
"usr": "s:4cake6NumberO8RawValuea",
500508
"location": "",
501509
"moduleName": "cake",
510+
"implicit": true,
502511
"children": [
503512
{
504513
"kind": "TypeNominal",
@@ -516,6 +525,7 @@
516525
"usr": "s:4cake6NumberO9hashValueSivp",
517526
"location": "",
518527
"moduleName": "cake",
528+
"implicit": true,
519529
"children": [
520530
{
521531
"kind": "TypeNominal",
@@ -531,6 +541,7 @@
531541
"usr": "s:4cake6NumberO9hashValueSivg",
532542
"location": "",
533543
"moduleName": "cake",
544+
"implicit": true,
534545
"children": [
535546
{
536547
"kind": "TypeNominal",
@@ -550,6 +561,7 @@
550561
"usr": "s:4cake6NumberO4hash4intoys6HasherVz_tF",
551562
"location": "",
552563
"moduleName": "cake",
564+
"implicit": true,
553565
"children": [
554566
{
555567
"kind": "TypeNominal",
@@ -572,6 +584,7 @@
572584
"usr": "s:4cake6NumberO8rawValueACSgSi_tcfc",
573585
"location": "",
574586
"moduleName": "cake",
587+
"implicit": true,
575588
"declAttributes": [
576589
"Inlinable"
577590
],
@@ -606,6 +619,7 @@
606619
"usr": "s:4cake6NumberO8rawValueSivp",
607620
"location": "",
608621
"moduleName": "cake",
622+
"implicit": true,
609623
"children": [
610624
{
611625
"kind": "TypeNominal",
@@ -621,6 +635,7 @@
621635
"usr": "s:4cake6NumberO8rawValueSivg",
622636
"location": "",
623637
"moduleName": "cake",
638+
"implicit": true,
624639
"declAttributes": [
625640
"Inlinable"
626641
],
@@ -673,6 +688,131 @@
673688
}
674689
]
675690
},
691+
{
692+
"kind": "TypeDecl",
693+
"name": "fixedLayoutStruct",
694+
"printedName": "fixedLayoutStruct",
695+
"declKind": "Struct",
696+
"usr": "s:4cake17fixedLayoutStructV",
697+
"location": "",
698+
"moduleName": "cake",
699+
"declAttributes": [
700+
"FixedLayout"
701+
],
702+
"children": [
703+
{
704+
"kind": "Var",
705+
"name": "a",
706+
"printedName": "a",
707+
"declKind": "Var",
708+
"usr": "s:4cake17fixedLayoutStructV1aSivp",
709+
"location": "",
710+
"moduleName": "cake",
711+
"fixedbinaryorder": 0,
712+
"declAttributes": [
713+
"HasInitialValue"
714+
],
715+
"children": [
716+
{
717+
"kind": "TypeNominal",
718+
"name": "Int",
719+
"printedName": "Int",
720+
"usr": "s:Si"
721+
},
722+
{
723+
"kind": "Getter",
724+
"name": "_",
725+
"printedName": "_()",
726+
"declKind": "Accessor",
727+
"usr": "s:4cake17fixedLayoutStructV1aSivg",
728+
"location": "",
729+
"moduleName": "cake",
730+
"implicit": true,
731+
"declAttributes": [
732+
"Transparent"
733+
],
734+
"children": [
735+
{
736+
"kind": "TypeNominal",
737+
"name": "Int",
738+
"printedName": "Int",
739+
"usr": "s:Si"
740+
}
741+
]
742+
},
743+
{
744+
"kind": "Setter",
745+
"name": "_",
746+
"printedName": "_()",
747+
"declKind": "Accessor",
748+
"usr": "s:4cake17fixedLayoutStructV1aSivs",
749+
"location": "",
750+
"moduleName": "cake",
751+
"implicit": true,
752+
"mutating": true,
753+
"declAttributes": [
754+
"Transparent"
755+
],
756+
"children": [
757+
{
758+
"kind": "TypeNominal",
759+
"name": "Void",
760+
"printedName": "()"
761+
},
762+
{
763+
"kind": "TypeNominal",
764+
"name": "Int",
765+
"printedName": "Int",
766+
"usr": "s:Si"
767+
}
768+
]
769+
}
770+
]
771+
},
772+
{
773+
"kind": "Constructor",
774+
"name": "init",
775+
"printedName": "init(a:)",
776+
"declKind": "Constructor",
777+
"usr": "s:4cake17fixedLayoutStructV1aACSi_tcfc",
778+
"location": "",
779+
"moduleName": "cake",
780+
"implicit": true,
781+
"children": [
782+
{
783+
"kind": "TypeNominal",
784+
"name": "fixedLayoutStruct",
785+
"printedName": "fixedLayoutStruct",
786+
"usr": "s:4cake17fixedLayoutStructV"
787+
},
788+
{
789+
"kind": "TypeNominal",
790+
"name": "Int",
791+
"printedName": "Int",
792+
"usr": "s:Si"
793+
}
794+
]
795+
},
796+
{
797+
"kind": "Constructor",
798+
"name": "init",
799+
"printedName": "init()",
800+
"declKind": "Constructor",
801+
"usr": "s:4cake17fixedLayoutStructVACycfc",
802+
"location": "",
803+
"moduleName": "cake",
804+
"implicit": true,
805+
"children": [
806+
{
807+
"kind": "TypeNominal",
808+
"name": "fixedLayoutStruct",
809+
"printedName": "fixedLayoutStruct",
810+
"usr": "s:4cake17fixedLayoutStructV"
811+
}
812+
]
813+
}
814+
]
815+
},
676816
{
677817
"kind": "TypeDecl",
678818
"name": "Int",

0 commit comments

Comments
 (0)