Skip to content

Commit 0159627

Browse files
committed
As promised, split up struct_add_remove_conformances library evolution test
We now test four setups, with the four {before, after}^2 runs of each: a) Client adds conformance -vs- library adds public conformance -- fixed-layout struct b) Client adds conformance -vs- library removes internal conformance -- fixed-layout struct c) Client adds conformance -vs- library adds public conformance -- resilient struct d) Client adds conformance -vs- library removes internal conformance -- resilient struct The first two pass, but a) requires a hack to ensure we don't directly reference conformance table, otherwise the 'after_before' version doesn't link. I think the right idea here is to weakly reference conformance tables where the deployment target is lower than the availability of the conformance. The second two are XFAIL'd until protocol conformance tables can reference resilient types from other modules. This requires emitting indirect metadata symbols, since the client doesn't know if the resilient type's metadata is direct or a template, and the conformance table cannot use the metadata accessor either. These tests will also become important if we decide to revisit synthesized accessors, and make them lazy again for structs.
1 parent a230d40 commit 0159627

9 files changed

+397
-81
lines changed

validation-test/Evolution/Inputs/struct_add_remove_conformances.swift renamed to validation-test/Evolution/Inputs/struct_fixed_layout_add_conformance.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public func getVersion() -> Int {
77
#endif
88
}
99

10-
@_fixed_layout public struct AddRemoveConformance {
10+
@_fixed_layout public struct AddConformance {
1111
public init() {
1212
x = 0
1313
y = 0
@@ -35,6 +35,6 @@ public protocol Point3DLike {
3535
}
3636

3737
#if AFTER
38-
extension AddRemoveConformance : PointLike {}
39-
extension AddRemoveConformance : Point3DLike {}
38+
extension AddConformance : PointLike {}
39+
extension AddConformance : Point3DLike {}
4040
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
@_fixed_layout public struct RemoveConformance {
3+
public init() {
4+
x = 0
5+
y = 0
6+
}
7+
8+
public var x: Int
9+
public var y: Int
10+
11+
public var z: Int {
12+
get { return x + y }
13+
set {
14+
x = newValue / 2
15+
y = newValue - x
16+
}
17+
}
18+
}
19+
20+
#if BEFORE
21+
protocol InternalProtocol {
22+
var x: Int { get set }
23+
var y: Int { get set }
24+
var z: Int { get set }
25+
}
26+
27+
extension RemoveConformance : InternalProtocol {}
28+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
public func getVersion() -> Int {
3+
#if BEFORE
4+
return 0
5+
#else
6+
return 1
7+
#endif
8+
}
9+
10+
public struct AddConformance {
11+
public init() {
12+
x = 0
13+
y = 0
14+
}
15+
16+
public var x: Int
17+
public var y: Int
18+
19+
public var z: Int {
20+
get { return x + y }
21+
set {
22+
x = newValue / 2
23+
y = newValue - x
24+
}
25+
}
26+
}
27+
28+
public protocol PointLike {
29+
var x: Int { get set }
30+
var y: Int { get set }
31+
}
32+
33+
public protocol Point3DLike {
34+
var z: Int { get set }
35+
}
36+
37+
#if AFTER
38+
extension AddConformance : PointLike {}
39+
extension AddConformance : Point3DLike {}
40+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
public struct RemoveConformance {
3+
public init() {
4+
x = 0
5+
y = 0
6+
}
7+
8+
public var x: Int
9+
public var y: Int
10+
11+
public var z: Int {
12+
get { return x + y }
13+
set {
14+
x = newValue / 2
15+
y = newValue - x
16+
}
17+
}
18+
}
19+
20+
#if BEFORE
21+
protocol InternalProtocol {
22+
var x: Int { get set }
23+
var y: Int { get set }
24+
var z: Int { get set }
25+
}
26+
27+
extension RemoveConformance : InternalProtocol {}
28+
#endif

validation-test/Evolution/test_struct_add_remove_conformances.swift

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2+
3+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_fixed_layout_add_conformance.swift -o %t/before/struct_fixed_layout_add_conformance.o
4+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_fixed_layout_add_conformance.swift -o %t/before/struct_fixed_layout_add_conformance.o
5+
6+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_fixed_layout_add_conformance.swift -o %t/after/struct_fixed_layout_add_conformance.o
7+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_fixed_layout_add_conformance.swift -o %t/after/struct_fixed_layout_add_conformance.o
8+
9+
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10+
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11+
12+
// RUN: %target-build-swift %t/before/struct_fixed_layout_add_conformance.o %t/before/main.o -o %t/before_before
13+
// RUN: %target-build-swift %t/before/struct_fixed_layout_add_conformance.o %t/after/main.o -o %t/before_after
14+
// RUN: %target-build-swift %t/after/struct_fixed_layout_add_conformance.o %t/before/main.o -o %t/after_before
15+
// RUN: %target-build-swift %t/after/struct_fixed_layout_add_conformance.o %t/after/main.o -o %t/after_after
16+
17+
// RUN: %target-run %t/before_before
18+
// RUN: %target-run %t/before_after
19+
// RUN: %target-run %t/after_before
20+
// RUN: %target-run %t/after_after
21+
22+
import StdlibUnittest
23+
import struct_fixed_layout_add_conformance
24+
25+
var StructFixedLayoutAddConformanceTest = TestSuite("StructFixedLayoutAddConformance")
26+
27+
// FIXME: Once we have availability information for conformances, we can
28+
// make this non-generic as long as we're careful to never directly
29+
// reference an unavailable conformance table symbol
30+
@inline(never) func workWithPointLike<T>(t: T) {
31+
if getVersion() > 0 {
32+
var p = t as! PointLike
33+
p.x = 30
34+
p.y = 40
35+
expectEqual(p.x, 30)
36+
expectEqual(p.y, 40)
37+
} else {
38+
expectEqual(t is PointLike, false)
39+
}
40+
}
41+
42+
StructFixedLayoutAddConformanceTest.test("AddConformance") {
43+
var t = AddConformance()
44+
45+
do {
46+
t.x = 10
47+
t.y = 20
48+
expectEqual(t.x, 10)
49+
expectEqual(t.y, 20)
50+
}
51+
52+
workWithPointLike(t)
53+
}
54+
55+
#if AFTER
56+
protocol MyPointLike {
57+
var x: Int { get set }
58+
var y: Int { get set }
59+
}
60+
61+
protocol MyPoint3DLike {
62+
var z: Int { get set }
63+
}
64+
65+
extension AddConformance : MyPointLike {}
66+
extension AddConformance : MyPoint3DLike {}
67+
68+
StructFixedLayoutAddConformanceTest.test("MyPointLike") {
69+
var p: MyPointLike = AddConformance()
70+
71+
do {
72+
p.x = 50
73+
p.y = 60
74+
expectEqual(p.x, 50)
75+
expectEqual(p.y, 60)
76+
}
77+
}
78+
#endif
79+
80+
runAllTests()
81+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2+
3+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_fixed_layout_remove_conformance.swift -o %t/before/struct_fixed_layout_remove_conformance.o
4+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_fixed_layout_remove_conformance.swift -o %t/before/struct_fixed_layout_remove_conformance.o
5+
6+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_fixed_layout_remove_conformance.swift -o %t/after/struct_fixed_layout_remove_conformance.o
7+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_fixed_layout_remove_conformance.swift -o %t/after/struct_fixed_layout_remove_conformance.o
8+
9+
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10+
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11+
12+
// RUN: %target-build-swift %t/before/struct_fixed_layout_remove_conformance.o %t/before/main.o -o %t/before_before
13+
// RUN: %target-build-swift %t/before/struct_fixed_layout_remove_conformance.o %t/after/main.o -o %t/before_after
14+
// RUN: %target-build-swift %t/after/struct_fixed_layout_remove_conformance.o %t/before/main.o -o %t/after_before
15+
// RUN: %target-build-swift %t/after/struct_fixed_layout_remove_conformance.o %t/after/main.o -o %t/after_after
16+
17+
// RUN: %target-run %t/before_before
18+
// RUN: %target-run %t/before_after
19+
// RUN: %target-run %t/after_before
20+
// RUN: %target-run %t/after_after
21+
22+
import StdlibUnittest
23+
import struct_fixed_layout_remove_conformance
24+
25+
var StructFixedLayoutRemoveConformanceTest = TestSuite("StructFixedLayoutRemoveConformance")
26+
27+
StructFixedLayoutRemoveConformanceTest.test("RemoveConformance") {
28+
var t = RemoveConformance()
29+
30+
do {
31+
t.x = 10
32+
t.y = 20
33+
expectEqual(t.x, 10)
34+
expectEqual(t.y, 20)
35+
}
36+
}
37+
38+
#if AFTER
39+
protocol MyPointLike {
40+
var x: Int { get set }
41+
var y: Int { get set }
42+
}
43+
44+
protocol MyPoint3DLike {
45+
var z: Int { get set }
46+
}
47+
48+
extension RemoveConformance : MyPointLike {}
49+
extension RemoveConformance : MyPoint3DLike {}
50+
51+
StructFixedLayoutRemoveConformanceTest.test("MyPointLike") {
52+
var p: MyPointLike = RemoveConformance()
53+
54+
do {
55+
p.x = 50
56+
p.y = 60
57+
expectEqual(p.x, 50)
58+
expectEqual(p.y, 60)
59+
}
60+
}
61+
#endif
62+
63+
runAllTests()
64+

0 commit comments

Comments
 (0)