|
1 | 1 | // RUN: %empty-directory(%t)
|
2 | 2 |
|
3 |
| -// RUN: %target-swift-frontend -typecheck %S/stored-properties.swift -module-name StoredProperties -emit-parseable-module-interface-path %t/StoredProperties.swiftinterface |
4 |
| -// RUN: %target-swift-frontend -emit-ir %s -I %t | %FileCheck %s -check-prefix CHECK -check-prefix COMMON |
| 3 | +// 1. Build ../stored-properties.swift to a dylib and emit its interface in %t |
5 | 4 |
|
6 |
| -// RUN: %target-swift-frontend -typecheck %S/stored-properties.swift -enable-library-evolution -module-name StoredProperties -emit-parseable-module-interface-path %t/StoredProperties.swiftinterface |
7 |
| -// RUN: %target-swift-frontend -emit-ir %s -I %t | %FileCheck %s -check-prefix RESILIENT -check-prefix COMMON |
| 5 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(StoredProperties)) -emit-module-interface-path %t/StoredProperties.swiftinterface %S/stored-properties.swift -module-name StoredProperties -swift-version 5 |
8 | 6 |
|
9 |
| -// REQUIRES: rdar_46486517 |
| 7 | +// 2. Build this file and link with StoredProperties |
10 | 8 |
|
11 |
| -import StoredProperties |
12 |
| - |
13 |
| -/// This test makes sure clients of a parseable interface see correct type |
14 |
| -/// layout and use the right access patterns in the presence of a |
15 |
| -/// .swiftinterface file, in both resilient and non-resilient cases. |
| 9 | +// RUN: %target-build-swift %s -I %t -L %t -lStoredProperties -o %t/stored-properties-client %target-rpath(%t) |
16 | 10 |
|
17 |
| -// COMMON: %[[BAGOFVARIABLES:T16StoredProperties14BagOfVariablesV]] = type <{ %TSi, %TSb, [{{(3|7)}} x i8], %TSi }> |
| 11 | +// 3. Codesign and run this, and ensure it exits successfully. |
18 | 12 |
|
19 |
| -// This type is non-@_fixed_layout, so it becomes opaque in a resilient module |
20 |
| -// CHECK: %[[HASSTOREDPROPERTIES:T16StoredProperties03HasaB0V]] = type <{ %TSi, %TSi, %TSb, [{{(3|7)}} x i8], %TSi, %TSb, [{{3|7}} x i8], %TSi }> |
21 |
| -// RESILIENT: %[[HASSTOREDPROPERTIES:swift.opaque]] = type opaque |
| 13 | +// RUN: %target-codesign %t/stored-properties-client %t/%target-library-name(StoredProperties) |
| 14 | +// RUN: %target-run %t/stored-properties-client %t/%target-library-name(StoredProperties) |
22 | 15 |
|
23 |
| -// COMMON: %[[HASSTOREDPROPERTIESFIXEDLAYOUT:T16StoredProperties03HasaB11FixedLayoutV]] = type <{ %[[BAGOFVARIABLES]], %[[BAGOFVARIABLES]] }> |
| 16 | +// 4. Repeat these steps, with library evolution enabled. |
24 | 17 |
|
25 |
| -// These are here just to make sure the compiler doesn't optimize away accesses. |
26 |
| -// They're overloaded instead of generic so we avoid generic dispatch. |
| 18 | +// RUN: %empty-directory(%t) |
27 | 19 |
|
28 |
| -@inline(never) |
29 |
| -func _blackHole(_ value: Int) {} |
| 20 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(StoredProperties)) -emit-module-interface-path %t/StoredProperties.swiftinterface %S/stored-properties.swift -module-name StoredProperties -swift-version 5 -enable-library-evolution |
30 | 21 |
|
31 |
| -@inline(never) |
32 |
| -func _blackHole(_ value: Bool) {} |
| 22 | +// RUN: %target-build-swift %s -I %t -L %t -lStoredProperties -o %t/stored-properties-client %target-rpath(%t) |
| 23 | +// RUN: %target-codesign %t/stored-properties-client %t/%target-library-name(StoredProperties) |
| 24 | +// RUN: %target-run %t/stored-properties-client %t/%target-library-name(StoredProperties) |
33 | 25 |
|
34 |
| -@inline(never) |
35 |
| -func _blackHole(_ value: BagOfVariables) {} |
| 26 | +import StdlibUnittest |
| 27 | +import StoredProperties |
36 | 28 |
|
37 |
| -/// In the following code, getting and setting is split because otherwise |
38 |
| -/// the resulting IR is ordered differently. |
| 29 | +/// This test makes sure clients of a parseable interface see correct type |
| 30 | +/// layout and use the right access patterns in the presence of a |
| 31 | +/// .swiftinterface file, in both resilient and non-resilient cases. |
39 | 32 |
|
40 | 33 | /// Test that we call the correct accessors in a resilient module, and that
|
41 | 34 | /// we use trivial storage accesses in a non-resilient module.
|
42 | 35 |
|
43 |
| -func testGetting() { |
44 |
| - // CHECK: %[[VALUE:.*]] = alloca %[[HASSTOREDPROPERTIES]] |
45 |
| - // CHECK: call swiftcc void @"$s16StoredProperties03HasaB0VACycfC"(%[[HASSTOREDPROPERTIES]]* {{.*}} %[[VALUE]]) |
46 |
| - // RESILIENT: %[[VALUE:.*]] = alloca i8, [[WORD:i[0-9]+]] %size |
47 |
| - // RESILIENT: %[[VALUECAST:.*]] = bitcast i8* %value to %[[HASSTOREDPROPERTIES]]* |
48 |
| - // RESILIENT: call swiftcc void @"$s16StoredProperties03HasaB0VACycfC"(%[[HASSTOREDPROPERTIES]]* noalias nocapture sret %[[VALUECAST]]) |
49 |
| - var value = HasStoredProperties() |
50 |
| - |
51 |
| - // CHECK: getelementptr inbounds %[[HASSTOREDPROPERTIES]], %[[HASSTOREDPROPERTIES]]* %[[VALUE]], i32 0, i32 1 |
52 |
| - // CHECK: getelementptr inbounds %[[HASSTOREDPROPERTIES]], %[[HASSTOREDPROPERTIES]]* %[[VALUE]], i32 0, i32 2 |
53 |
| - |
54 |
| - // These are accessed in declaration order so the IR is emitted in the same |
55 |
| - // order. |
56 |
| - |
57 |
| - // COMMON: call swiftcc [[WORD:i[0-9]+]] @"$s16StoredProperties03HasaB0V14computedGetterSivg" |
58 |
| - _blackHole(value.computedGetter) |
59 |
| - |
60 |
| - // COMMON: call swiftcc [[WORD]] @"$s16StoredProperties03HasaB0V14computedGetSetSivg" |
61 |
| - _blackHole(value.computedGetSet) |
62 |
| - |
63 |
| - // CHECK: getelementptr inbounds %[[HASSTOREDPROPERTIES]], %[[HASSTOREDPROPERTIES]]* %[[VALUE]], i32 0, i32 0 |
64 |
| - // CHECK: getelementptr inbounds %[[HASSTOREDPROPERTIES]], %[[HASSTOREDPROPERTIES]]* %[[VALUE]], i32 0, i32 4 |
65 |
| - |
66 |
| - // RESILIENT: call swiftcc [[WORD]] @"$s16StoredProperties03HasaB0V06simpleA9ImmutableSivg" |
67 |
| - _blackHole(value.simpleStoredImmutable) |
| 36 | +var StoredPropertyTests = TestSuite("StoredProperty") |
68 | 37 |
|
69 |
| - // RESILIENT: call swiftcc [[WORD]] @"$s16StoredProperties03HasaB0V06simpleA7MutableSivg" |
70 |
| - _blackHole(value.simpleStoredMutable) |
71 |
| - |
72 |
| - // RESILIENT: call swiftcc i1 @"$s16StoredProperties03HasaB0V19storedWithObserversSbvg" |
73 |
| - _blackHole(value.storedWithObservers) |
74 |
| - |
75 |
| - // RESILIENT: call swiftcc [[WORD]] @"$s16StoredProperties03HasaB0V16storedPrivateSetSivg" |
76 |
| - _blackHole(value.storedPrivateSet) |
| 38 | +StoredPropertyTests.test("Getting/NonFixedLayout") { |
| 39 | + var value = HasStoredProperties() |
| 40 | + expectEqual(3, value.computedGetter) |
| 41 | + expectEqual(3, value.computedGetSet) |
| 42 | + expectEqual(0, value.simpleStoredImmutable) |
| 43 | + expectEqual(0, value.simpleStoredMutable) |
| 44 | + expectEqual(false, value.storedWithObservers) |
| 45 | + expectEqual(0, value.storedPrivateSet) |
77 | 46 | }
|
78 | 47 |
|
79 |
| -func testSetting() { |
80 |
| - // CHECK: call swiftcc void @"$s16StoredProperties03HasaB0VACycfC"(%[[HASSTOREDPROPERTIES]]* {{.*}}) |
81 |
| - // RESILIENT: call swiftcc %swift.metadata_response @"$s16StoredProperties03HasaB0VMa"([[WORD]] 0) |
82 |
| - // RESILIENT: %[[VALUEALLOC:.*]] = alloca i8, [[WORD]] %size |
83 |
| - // RESILIENT: bitcast i8* %[[VALUEALLOC]] to %[[HASSTOREDPROPERTIES]]* |
| 48 | +StoredPropertyTests.test("Setting/NonFixedLayout") { |
84 | 49 | var value = HasStoredProperties()
|
85 |
| - |
86 |
| - // COMMON: call swiftcc void @"$s16StoredProperties03HasaB0V19storedWithObserversSbvs"(i1 false, %[[HASSTOREDPROPERTIES]]* {{.*}}) |
87 |
| - value.storedWithObservers = false |
88 |
| - |
89 |
| - // COMMON-NEXT: call swiftcc void @"$s16StoredProperties03HasaB0V14computedGetSetSivs"([[WORD]] 4, %[[HASSTOREDPROPERTIES]]* {{.*}}) |
| 50 | + value.storedWithObservers = true |
90 | 51 | value.computedGetSet = 4
|
91 |
| - |
92 |
| - // CHECK: %[[MUTABLE_PTR:.*]] = getelementptr inbounds %[[HASSTOREDPROPERTIES]], %[[HASSTOREDPROPERTIES]]* {{.*}}, i32 0, i32 1 |
93 |
| - // CHECK: %[[MUTABLE_INT_PTR:.*]] = getelementptr inbounds %TSi, %TSi* %[[MUTABLE_PTR]], i32 0, i32 0 |
94 |
| - // CHECK: store [[WORD]] 4, [[WORD]]* %[[MUTABLE_INT_PTR]] |
95 |
| - // RESILIENT: call swiftcc void @"$s16StoredProperties03HasaB0V06simpleA7MutableSivs"([[WORD]] 4, %[[HASSTOREDPROPERTIES]]* {{.*}}) |
96 | 52 | value.simpleStoredMutable = 4
|
97 |
| -} |
98 |
| - |
99 |
| -testGetting() |
100 |
| -testSetting() |
101 | 53 |
|
102 |
| -/// Test that we always use trivial access patterns for @_fixed_layout types |
103 |
| -/// in resilient or non-resilient modules. |
| 54 | + expectEqual(3, value.computedGetter) |
| 55 | + expectEqual(3, value.computedGetSet) |
| 56 | + expectEqual(0, value.simpleStoredImmutable) |
| 57 | + expectEqual(4, value.simpleStoredMutable) |
| 58 | + expectEqual(true, value.storedWithObservers) |
| 59 | + expectEqual(0, value.storedPrivateSet) |
| 60 | +} |
104 | 61 |
|
105 |
| -func testFixedLayoutGetting() { |
106 |
| - // COMMON: %[[VALUEALLOCA:.*]] = alloca %[[HASSTOREDPROPERTIESFIXEDLAYOUT]] |
107 |
| - // COMMON: call swiftcc void @"$s16StoredProperties03HasaB11FixedLayoutVACycfC"(%[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* {{.*}} %[[VALUEALLOCA]]) |
| 62 | +StoredPropertyTests.test("Getting/FixedLayout") { |
108 | 63 | var value = HasStoredPropertiesFixedLayout()
|
| 64 | + expectEqual(0, value.simpleStoredMutable.a) |
| 65 | + expectEqual(false, value.simpleStoredMutable.b) |
| 66 | + expectEqual(0, value.simpleStoredMutable.c) |
109 | 67 |
|
110 |
| - // These next two tests just make sure we don't use resilient access patterns |
111 |
| - // for these fixed_layout structs. |
112 |
| - |
113 |
| - // COMMON: getelementptr inbounds %[[HASSTOREDPROPERTIESFIXEDLAYOUT]], %[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* %[[VALUEALLOCA]], i32 0, i32 0 |
114 |
| - // COMMON: getelementptr inbounds %[[HASSTOREDPROPERTIESFIXEDLAYOUT]], %[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* %[[VALUEALLOCA]], i32 0, i32 1 |
115 |
| - |
116 |
| - // COMMON: call swiftcc void @"$s4main10_blackHoleyy16StoredProperties14BagOfVariablesVF"([[WORD]] %{{.*}}, i1 %{{.*}}, [[WORD]] %{{.*}}) |
117 |
| - _blackHole(value.simpleStoredMutable) |
118 |
| - |
119 |
| - // COMMON: call swiftcc void @"$s4main10_blackHoleyy16StoredProperties14BagOfVariablesVF"([[WORD]] %{{.*}}, i1 %{{.*}}, [[WORD]] %{{.*}}) |
120 |
| - _blackHole(value.storedWithObservers) |
| 68 | + expectEqual(0, value.storedWithObservers.a) |
| 69 | + expectEqual(false, value.storedWithObservers.b) |
| 70 | + expectEqual(0, value.storedWithObservers.c) |
121 | 71 | }
|
122 | 72 |
|
123 |
| -func testFixedLayoutSetting() { |
124 |
| - // COMMON: %[[VALUEALLOCA:.*]] = alloca %[[HASSTOREDPROPERTIESFIXEDLAYOUT]] |
125 |
| - // COMMON: call swiftcc void @"$s16StoredProperties03HasaB11FixedLayoutVACycfC"(%[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* {{.*}} %[[VALUEALLOCA]]) |
| 73 | +StoredPropertyTests.test("Setting/FixedLayout") { |
126 | 74 | var value = HasStoredPropertiesFixedLayout()
|
127 | 75 |
|
128 |
| - // COMMON: call swiftcc void @"$s16StoredProperties03HasaB11FixedLayoutV19storedWithObserversAA14BagOfVariablesVvs" |
129 |
| - value.storedWithObservers = BagOfVariables() |
130 |
| - |
131 |
| - // COMMON: %[[PROP:.*]] = getelementptr inbounds %[[HASSTOREDPROPERTIESFIXEDLAYOUT]], %[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* %value, i32 0, i32 0 |
132 |
| - // COMMON: %[[PROPA:.*]] = getelementptr inbounds %[[BAGOFVARIABLES]], %[[BAGOFVARIABLES]]* %[[PROP]], i32 0, i32 0 |
133 |
| - // COMMON: %[[PROPAVAL:.*]] = getelementptr inbounds %TSi, %TSi* %[[PROPA]], i32 0, i32 0 |
134 |
| - // COMMON: store [[WORD]] {{.*}} %[[PROPAVAL]] |
135 |
| - // COMMON: %[[PROPB:.*]] = getelementptr inbounds %[[BAGOFVARIABLES]], %[[BAGOFVARIABLES]]* %[[PROP]], i32 0, i32 1 |
136 |
| - // COMMON: %[[PROPBVAL:.*]] = getelementptr inbounds %TSb, %TSb* %[[PROPB]], i32 0, i32 0 |
137 |
| - // COMMON: store i1 {{.*}} %[[PROPBVAL]] |
138 |
| - // COMMON: %[[PROPC:.*]] = getelementptr inbounds %[[BAGOFVARIABLES]], %[[BAGOFVARIABLES]]* %[[PROP]], i32 0, i32 3 |
139 |
| - // COMMON: %[[PROPCVAL:.*]] = getelementptr inbounds %TSi, %TSi* %[[PROPC]], i32 0, i32 0 |
140 |
| - // COMMON: store [[WORD]] {{.*}} %[[PROPCVAL]] |
141 | 76 | value.simpleStoredMutable = BagOfVariables()
|
| 77 | + expectEqual(0, value.simpleStoredMutable.a) |
| 78 | + expectEqual(false, value.simpleStoredMutable.b) |
| 79 | + expectEqual(0, value.simpleStoredMutable.c) |
| 80 | + |
| 81 | + value.storedWithObservers = BagOfVariables() |
| 82 | + expectEqual(0, value.storedWithObservers.a) |
| 83 | + expectEqual(false, value.storedWithObservers.b) |
| 84 | + expectEqual(0, value.storedWithObservers.c) |
142 | 85 | }
|
143 | 86 |
|
144 |
| -testFixedLayoutGetting() |
145 |
| -testFixedLayoutSetting() |
| 87 | +runAllTests() |
0 commit comments