Skip to content

Commit 3efc8b9

Browse files
author
Harlan Haskins
committed
[test] Change stored-properties-client to an executable test
This test was overfitting what it was trying to test, causing different targets (and even different assert configurations) to fail to match. Instead, make this an executable test and ensure that round-tripping through setting and getting behaves as expected. Fixes rdar://46486517
1 parent 986d5ca commit 3efc8b9

File tree

2 files changed

+56
-111
lines changed

2 files changed

+56
-111
lines changed
Lines changed: 53 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,87 @@
11
// RUN: %empty-directory(%t)
22

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
54

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
86

9-
// REQUIRES: rdar_46486517
7+
// 2. Build this file and link with StoredProperties
108

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)
1610

17-
// COMMON: %[[BAGOFVARIABLES:T16StoredProperties14BagOfVariablesV]] = type <{ %TSi, %TSb, [{{(3|7)}} x i8], %TSi }>
11+
// 3. Codesign and run this, and ensure it exits successfully.
1812

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)
2215

23-
// COMMON: %[[HASSTOREDPROPERTIESFIXEDLAYOUT:T16StoredProperties03HasaB11FixedLayoutV]] = type <{ %[[BAGOFVARIABLES]], %[[BAGOFVARIABLES]] }>
16+
// 4. Repeat these steps, with library evolution enabled.
2417

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)
2719

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
3021

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)
3325

34-
@inline(never)
35-
func _blackHole(_ value: BagOfVariables) {}
26+
import StdlibUnittest
27+
import StoredProperties
3628

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.
3932

4033
/// Test that we call the correct accessors in a resilient module, and that
4134
/// we use trivial storage accesses in a non-resilient module.
4235

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")
6837

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)
7746
}
7847

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") {
8449
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
9051
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]]* {{.*}})
9652
value.simpleStoredMutable = 4
97-
}
98-
99-
testGetting()
100-
testSetting()
10153

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+
}
10461

105-
func testFixedLayoutGetting() {
106-
// COMMON: %[[VALUEALLOCA:.*]] = alloca %[[HASSTOREDPROPERTIESFIXEDLAYOUT]]
107-
// COMMON: call swiftcc void @"$s16StoredProperties03HasaB11FixedLayoutVACycfC"(%[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* {{.*}} %[[VALUEALLOCA]])
62+
StoredPropertyTests.test("Getting/FixedLayout") {
10863
var value = HasStoredPropertiesFixedLayout()
64+
expectEqual(0, value.simpleStoredMutable.a)
65+
expectEqual(false, value.simpleStoredMutable.b)
66+
expectEqual(0, value.simpleStoredMutable.c)
10967

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)
12171
}
12272

123-
func testFixedLayoutSetting() {
124-
// COMMON: %[[VALUEALLOCA:.*]] = alloca %[[HASSTOREDPROPERTIESFIXEDLAYOUT]]
125-
// COMMON: call swiftcc void @"$s16StoredProperties03HasaB11FixedLayoutVACycfC"(%[[HASSTOREDPROPERTIESFIXEDLAYOUT]]* {{.*}} %[[VALUEALLOCA]])
73+
StoredPropertyTests.test("Setting/FixedLayout") {
12674
var value = HasStoredPropertiesFixedLayout()
12775

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]]
14176
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)
14285
}
14386

144-
testFixedLayoutGetting()
145-
testFixedLayoutSetting()
87+
runAllTests()

test/ParseableInterface/stored-properties.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public struct HasStoredProperties {
7777
// COMMON: @_fixed_layout public struct BagOfVariables {
7878
@_fixed_layout
7979
public struct BagOfVariables {
80+
// COMMON: private let hidden: [[INT]] = 0
81+
private let hidden: Int = 0
82+
8083
// COMMON: public let a: [[INT]] = 0
8184
public let a: Int = 0
8285

0 commit comments

Comments
 (0)