Skip to content

Commit 05e1592

Browse files
committed
swift-module-digester: diagnose reordering of members in a fixed layout type under ABI mode.
1 parent 0eb756f commit 05e1592

File tree

13 files changed

+385
-8
lines changed

13 files changed

+385
-8
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ KEY(hasDefaultArg)
110110
KEY(conformingProtocols)
111111
KEY(enumRawTypeName)
112112
KEY(genericSig)
113+
KEY(fixedbinaryorder)
113114

114115
KNOWN_TYPE(Optional)
115116
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: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@
469469
"usr": "s:4cake6NumberO3oneyA2CmF",
470470
"location": "",
471471
"moduleName": "cake",
472+
"fixedbinaryorder": 0,
472473
"children": [
473474
{
474475
"kind": "TypeFunc",
@@ -687,6 +688,131 @@
687688
}
688689
]
689690
},
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+
},
690816
{
691817
"kind": "TypeDecl",
692818
"name": "Int",

test/api-digester/Outputs/cake.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@
476476
"usr": "s:4cake6NumberO3oneyA2CmF",
477477
"location": "",
478478
"moduleName": "cake",
479+
"fixedbinaryorder": 0,
479480
"children": [
480481
{
481482
"kind": "TypeFunc",
@@ -701,6 +702,131 @@
701702
}
702703
]
703704
},
705+
{
706+
"kind": "TypeDecl",
707+
"name": "fixedLayoutStruct",
708+
"printedName": "fixedLayoutStruct",
709+
"declKind": "Struct",
710+
"usr": "s:4cake17fixedLayoutStructV",
711+
"location": "",
712+
"moduleName": "cake",
713+
"declAttributes": [
714+
"FixedLayout"
715+
],
716+
"children": [
717+
{
718+
"kind": "Var",
719+
"name": "a",
720+
"printedName": "a",
721+
"declKind": "Var",
722+
"usr": "s:4cake17fixedLayoutStructV1aSivp",
723+
"location": "",
724+
"moduleName": "cake",
725+
"fixedbinaryorder": 0,
726+
"declAttributes": [
727+
"HasInitialValue"
728+
],
729+
"children": [
730+
{
731+
"kind": "TypeNominal",
732+
"name": "Int",
733+
"printedName": "Int",
734+
"usr": "s:Si"
735+
},
736+
{
737+
"kind": "Getter",
738+
"name": "_",
739+
"printedName": "_()",
740+
"declKind": "Accessor",
741+
"usr": "s:4cake17fixedLayoutStructV1aSivg",
742+
"location": "",
743+
"moduleName": "cake",
744+
"implicit": true,
745+
"declAttributes": [
746+
"Transparent"
747+
],
748+
"children": [
749+
{
750+
"kind": "TypeNominal",
751+
"name": "Int",
752+
"printedName": "Int",
753+
"usr": "s:Si"
754+
}
755+
]
756+
},
757+
{
758+
"kind": "Setter",
759+
"name": "_",
760+
"printedName": "_()",
761+
"declKind": "Accessor",
762+
"usr": "s:4cake17fixedLayoutStructV1aSivs",
763+
"location": "",
764+
"moduleName": "cake",
765+
"implicit": true,
766+
"mutating": true,
767+
"declAttributes": [
768+
"Transparent"
769+
],
770+
"children": [
771+
{
772+
"kind": "TypeNominal",
773+
"name": "Void",
774+
"printedName": "()"
775+
},
776+
{
777+
"kind": "TypeNominal",
778+
"name": "Int",
779+
"printedName": "Int",
780+
"usr": "s:Si"
781+
}
782+
]
783+
}
784+
]
785+
},
786+
{
787+
"kind": "Constructor",
788+
"name": "init",
789+
"printedName": "init(a:)",
790+
"declKind": "Constructor",
791+
"usr": "s:4cake17fixedLayoutStructV1aACSi_tcfc",
792+
"location": "",
793+
"moduleName": "cake",
794+
"implicit": true,
795+
"children": [
796+
{
797+
"kind": "TypeNominal",
798+
"name": "fixedLayoutStruct",
799+
"printedName": "fixedLayoutStruct",
800+
"usr": "s:4cake17fixedLayoutStructV"
801+
},
802+
{
803+
"kind": "TypeNominal",
804+
"name": "Int",
805+
"printedName": "Int",
806+
"usr": "s:Si"
807+
}
808+
]
809+
},
810+
{
811+
"kind": "Constructor",
812+
"name": "init",
813+
"printedName": "init()",
814+
"declKind": "Constructor",
815+
"usr": "s:4cake17fixedLayoutStructVACycfc",
816+
"location": "",
817+
"moduleName": "cake",
818+
"implicit": true,
819+
"children": [
820+
{
821+
"kind": "TypeNominal",
822+
"name": "fixedLayoutStruct",
823+
"printedName": "fixedLayoutStruct",
824+
"usr": "s:4cake17fixedLayoutStructV"
825+
}
826+
]
827+
}
828+
]
829+
},
704830
{
705831
"kind": "TypeDecl",
706832
"name": "Int",

0 commit comments

Comments
 (0)