-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathreflect_existential.swift
172 lines (140 loc) · 7.21 KB
/
reflect_existential.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -lswiftSwiftReflectionTest %s -o %t/reflect_existential
// RUN: %target-run %target-swift-reflection-test %t/reflect_existential 2>&1 | %FileCheck %s --check-prefix=CHECK-%target-ptrsize
// REQUIRES: objc_interop
// REQUIRES: executable_test
import SwiftReflectionTest
class TestGeneric<T> {
var t: T
init(_ t: T) {
self.t = t
}
}
protocol P {}
protocol CP : class {}
class C : CP {}
class D : C, P {}
reflect(object: TestGeneric(D() as Any))
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class reflect_existential.TestGeneric
// CHECK-64: (protocol_composition))
// CHECK-64: Type info:
// CHECK-64: (class_instance size=48 alignment=8 stride=48 num_extra_inhabitants=0
// CHECK-64: (field name=t offset=16
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=0
// CHECK-64: (field name=metadata offset=24
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647)))))
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class reflect_existential.TestGeneric
// CHECK-32: (protocol_composition))
// CHECK-32: Type info:
// CHECK-32: (class_instance size=24 alignment=4 stride=24 num_extra_inhabitants=0
// CHECK-32: (field name=t offset=8
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=0
// CHECK-32: (field name=metadata offset=12
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096)))))
reflect(object: TestGeneric(D() as P))
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class reflect_existential.TestGeneric
// CHECK-64: (protocol_composition
// CHECK-64: (protocol reflect_existential.P)))
// CHECK-64: Type info:
// CHECK-64: (class_instance size=56 alignment=8 stride=56 num_extra_inhabitants=0
// CHECK-64: (field name=t offset=16
// CHECK-64: (opaque_existential size=40 alignment=8 stride=40 num_extra_inhabitants=0
// CHECK-64: (field name=metadata offset=24
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647))
// CHECK-64: (field name=wtable offset=32
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1)))))
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class reflect_existential.TestGeneric
// CHECK-32: (protocol_composition
// CHECK-32: (protocol reflect_existential.P)))
// CHECK-32: Type info:
// CHECK-32: (class_instance size=28 alignment=4 stride=28 num_extra_inhabitants=0
// CHECK-32: (field name=t offset=8
// CHECK-32: (opaque_existential size=20 alignment=4 stride=20 num_extra_inhabitants=0
// CHECK-32: (field name=metadata offset=12
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096))
// CHECK-32: (field name=wtable offset=16
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=1)))))
reflect(object: TestGeneric(D() as (P & AnyObject)))
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class reflect_existential.TestGeneric
// CHECK-64: (protocol_composition any_object
// CHECK-64: (protocol reflect_existential.P)))
// CHECK-64: Type info:
// CHECK-64: (class_instance size=32 alignment=8 stride=32 num_extra_inhabitants=0
// CHECK-64: (field name=t offset=16
// CHECK-64: (class_existential size=16 alignment=8 stride=16 num_extra_inhabitants=2147483647
// CHECK-64: (field name=object offset=0
// CHECK-64: (reference kind=strong refcounting=unknown))
// CHECK-64: (field name=wtable offset=8
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1)))))
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class reflect_existential.TestGeneric
// CHECK-32: (protocol_composition any_object
// CHECK-32: (protocol reflect_existential.P)))
// CHECK-32: Type info:
// CHECK-32: (class_instance size=16 alignment=4 stride=16 num_extra_inhabitants=0
// CHECK-32: (field name=t offset=8
// CHECK-32: (class_existential size=8 alignment=4 stride=8 num_extra_inhabitants=4096
// CHECK-32: (field name=object offset=0
// CHECK-32: (reference kind=strong refcounting=unknown))
// CHECK-32: (field name=wtable offset=4
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=1)))))
reflect(object: TestGeneric(D() as CP))
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class reflect_existential.TestGeneric
// CHECK-64: (protocol_composition any_object
// CHECK-64: (protocol reflect_existential.CP)))
// CHECK-64: Type info:
// CHECK-64: (class_instance size=32 alignment=8 stride=32 num_extra_inhabitants=0
// CHECK-64: (field name=t offset=16
// CHECK-64: (class_existential size=16 alignment=8 stride=16 num_extra_inhabitants=2147483647
// CHECK-64: (field name=object offset=0
// CHECK-64: (reference kind=strong refcounting=unknown))
// CHECK-64: (field name=wtable offset=8
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1)))))
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class reflect_existential.TestGeneric
// CHECK-32: (protocol_composition any_object
// CHECK-32: (protocol reflect_existential.CP)))
// CHECK-32: Type info:
// CHECK-32: (class_instance size=16 alignment=4 stride=16 num_extra_inhabitants=0
// CHECK-32: (field name=t offset=8
// CHECK-32: (class_existential size=8 alignment=4 stride=8 num_extra_inhabitants=4096
// CHECK-32: (field name=object offset=0
// CHECK-32: (reference kind=strong refcounting=unknown))
// CHECK-32: (field name=wtable offset=4
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=1)))))
reflect(object: TestGeneric(D() as (C & P)))
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class reflect_existential.TestGeneric
// CHECK-64: (protocol_composition any_object
// CHECK-64: (class reflect_existential.C)
// CHECK-64: (protocol reflect_existential.P)))
// CHECK-64: Type info:
// CHECK-64: (class_instance size=32 alignment=8 stride=32 num_extra_inhabitants=0
// CHECK-64: (field name=t offset=16
// CHECK-64: (class_existential size=16 alignment=8 stride=16 num_extra_inhabitants=2147483647
// CHECK-64: (field name=object offset=0
// CHECK-64: (reference kind=strong refcounting=native))
// CHECK-64: (field name=wtable offset=8
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1)))))
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class reflect_existential.TestGeneric
// CHECK-32: (protocol_composition any_object
// CHECK-32: (class reflect_existential.C)
// CHECK-32: (protocol reflect_existential.P)))
// CHECK-32: Type info:
// CHECK-32: (class_instance size=16 alignment=4 stride=16 num_extra_inhabitants=0
// CHECK-32: (field name=t offset=8
// CHECK-32: (class_existential size=8 alignment=4 stride=8 num_extra_inhabitants=4096
// CHECK-32: (field name=object offset=0
// CHECK-32: (reference kind=strong refcounting=native))
// CHECK-32: (field name=wtable offset=4
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=1)))))
doneReflecting()
// CHECK-64: Done.
// CHECK-32: Done.