Skip to content

Commit e843c72

Browse files
authored
Merge pull request #35433 from apple/Reflection-Support-OpaqueExistential-in-RecordTypeInfo-readExtraInhabitantIndex
[Reflection] Support OpaqueExistential in RecordTypeInfo::readExtraInhabitantIndex
2 parents 22f15dd + cb1173d commit e843c72

File tree

2 files changed

+303
-1
lines changed

2 files changed

+303
-1
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,19 @@ bool RecordTypeInfo::readExtraInhabitantIndex(remote::MemoryReader &reader,
260260
int *extraInhabitantIndex) const {
261261
switch (SubKind) {
262262
case RecordKind::Invalid:
263-
case RecordKind::OpaqueExistential:
264263
case RecordKind::ClosureContext:
265264
return false;
266265

266+
case RecordKind::OpaqueExistential: {
267+
if (Fields.size() != 1) {
268+
return false;
269+
}
270+
auto metadata = Fields[0];
271+
auto metadataFieldAddress = address + metadata.Offset;
272+
return metadata.TI.readExtraInhabitantIndex(
273+
reader, metadataFieldAddress, extraInhabitantIndex);
274+
}
275+
267276
case RecordKind::ThickFunction: {
268277
if (Fields.size() != 2) {
269278
return false;
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
// validation-test/Reflection/reflect_Optional_Any.swift
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-build-swift -g -lswiftSwiftReflectionTest %s -o %t/reflect_Optional_Any
5+
// RUN: %target-codesign %t/reflect_Optional_Any
6+
7+
// RUN: %target-run %target-swift-reflection-test %t/reflect_Optional_Any | %FileCheck %s --check-prefix=CHECK-%target-ptrsize
8+
9+
// REQUIRES: reflection_test_support
10+
// REQUIRES: executable_test
11+
// UNSUPPORTED: use_os_stdlib
12+
13+
import SwiftReflectionTest
14+
15+
struct TwentyFourByteStruct {
16+
let a: Int64
17+
let b: Int64
18+
let c: Int64
19+
}
20+
21+
// ================================================================
22+
23+
let optionalAnyNonNil: Any? = TwentyFourByteStruct(a: 7, b: 8, c: 9)
24+
reflect(enum: optionalAnyNonNil)
25+
26+
// CHECK-64: Reflecting an enum.
27+
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
28+
// CHECK-64: Type reference:
29+
// CHECK-64: (bound_generic_enum Swift.Optional
30+
// CHECK-64: (protocol_composition))
31+
32+
// CHECK-64: Type info:
33+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483646 bitwise_takable=1
34+
// CHECK-64: (case name=some index=0 offset=0
35+
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1
36+
// CHECK-64: (field name=metadata offset=24
37+
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1))))
38+
// CHECK-64: (case name=none index=1))
39+
40+
// CHECK-64: Mangled name: $sypSg
41+
// CHECK-64: Demangled name: Swift.Optional<Any>
42+
43+
// CHECK-64: Enum value:
44+
// CHECK-64: (enum_value name=some index=0
45+
// CHECK-64: (protocol_composition)
46+
// CHECK-64: )
47+
48+
// CHECK-32: Reflecting an enum.
49+
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
50+
// CHECK-32: Type reference:
51+
// CHECK-32: (bound_generic_enum Swift.Optional
52+
// CHECK-32: (protocol_composition))
53+
54+
// CHECK-32: Type info:
55+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4095 bitwise_takable=1
56+
// CHECK-32: (case name=some index=0 offset=0
57+
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1
58+
// CHECK-32: (field name=metadata offset=12
59+
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1))))
60+
// CHECK-32: (case name=none index=1))
61+
62+
// CHECK-32: Mangled name: $sypSg
63+
// CHECK-32: Demangled name: Swift.Optional<Any>
64+
65+
// CHECK-32: Enum value:
66+
// CHECK-32: (enum_value name=some index=0
67+
// CHECK-32: (protocol_composition)
68+
// CHECK-32: )
69+
70+
// ================================================================
71+
72+
let optionalAnyNil: Any? = nil
73+
reflect(enum: optionalAnyNil)
74+
75+
// CHECK-64: Reflecting an enum.
76+
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
77+
// CHECK-64: Type reference:
78+
// CHECK-64: (bound_generic_enum Swift.Optional
79+
// CHECK-64: (protocol_composition))
80+
81+
// CHECK-64: Type info:
82+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483646 bitwise_takable=1
83+
// CHECK-64: (case name=some index=0 offset=0
84+
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1
85+
// CHECK-64: (field name=metadata offset=24
86+
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1))))
87+
// CHECK-64: (case name=none index=1))
88+
89+
// CHECK-64: Mangled name: $sypSg
90+
// CHECK-64: Demangled name: Swift.Optional<Any>
91+
92+
// CHECK-64: Enum value:
93+
// CHECK-64: (enum_value name=none index=1)
94+
95+
96+
// CHECK-32: Reflecting an enum.
97+
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
98+
// CHECK-32: Type reference:
99+
// CHECK-32: (bound_generic_enum Swift.Optional
100+
// CHECK-32: (protocol_composition))
101+
102+
// CHECK-32: Type info:
103+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4095 bitwise_takable=1
104+
// CHECK-32: (case name=some index=0 offset=0
105+
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1
106+
// CHECK-32: (field name=metadata offset=12
107+
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1))))
108+
// CHECK-32: (case name=none index=1))
109+
110+
// CHECK-32: Mangled name: $sypSg
111+
// CHECK-32: Demangled name: Swift.Optional<Any>
112+
113+
// CHECK-32: Enum value:
114+
// CHECK-32: (enum_value name=none index=1)
115+
116+
// ================================================================
117+
118+
let optionalOptionalAnyNil: Any?? = nil
119+
reflect(enum: optionalOptionalAnyNil)
120+
121+
// CHECK-64: Reflecting an enum.
122+
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
123+
// CHECK-64: Type reference:
124+
// CHECK-64: (bound_generic_enum Swift.Optional
125+
// CHECK-64: (bound_generic_enum Swift.Optional
126+
// CHECK-64: (protocol_composition)))
127+
128+
// CHECK-64: Type info:
129+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483645 bitwise_takable=1
130+
// CHECK-64: (case name=some index=0 offset=0
131+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483646 bitwise_takable=1
132+
// CHECK-64: (case name=some index=0 offset=0
133+
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1
134+
// CHECK-64: (field name=metadata offset=24
135+
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1))))
136+
// CHECK-64: (case name=none index=1)))
137+
// CHECK-64: (case name=none index=1))
138+
139+
// CHECK-64: Mangled name: $sypSgSg
140+
// CHECK-64: Demangled name: Swift.Optional<Swift.Optional<Any>>
141+
142+
// CHECK-64: Enum value:
143+
// CHECK-64: (enum_value name=none index=1)
144+
145+
// CHECK-32: Reflecting an enum.
146+
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
147+
// CHECK-32: Type reference:
148+
// CHECK-32: (bound_generic_enum Swift.Optional
149+
// CHECK-32: (bound_generic_enum Swift.Optional
150+
// CHECK-32: (protocol_composition)))
151+
152+
// CHECK-32: Type info:
153+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4094 bitwise_takable=1
154+
// CHECK-32: (case name=some index=0 offset=0
155+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4095 bitwise_takable=1
156+
// CHECK-32: (case name=some index=0 offset=0
157+
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1
158+
// CHECK-32: (field name=metadata offset=12
159+
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1))))
160+
// CHECK-32: (case name=none index=1)))
161+
// CHECK-32: (case name=none index=1))
162+
163+
// CHECK-32: Mangled name: $sypSgSg
164+
// CHECK-32: Demangled name: Swift.Optional<Swift.Optional<Any>>
165+
166+
// CHECK-32: Enum value:
167+
// CHECK-32: (enum_value name=none index=1)
168+
169+
// ================================================================
170+
171+
let optionalOptionalAnySomeNil: Any?? = .some(nil)
172+
reflect(enum: optionalOptionalAnySomeNil)
173+
174+
// CHECK-64: Reflecting an enum.
175+
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
176+
// CHECK-64: Type reference:
177+
// CHECK-64: (bound_generic_enum Swift.Optional
178+
// CHECK-64: (bound_generic_enum Swift.Optional
179+
// CHECK-64: (protocol_composition)))
180+
181+
// CHECK-64: Type info:
182+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483645 bitwise_takable=1
183+
// CHECK-64: (case name=some index=0 offset=0
184+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483646 bitwise_takable=1
185+
// CHECK-64: (case name=some index=0 offset=0
186+
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1
187+
// CHECK-64: (field name=metadata offset=24
188+
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1))))
189+
// CHECK-64: (case name=none index=1)))
190+
// CHECK-64: (case name=none index=1))
191+
192+
// CHECK-64: Mangled name: $sypSgSg
193+
// CHECK-64: Demangled name: Swift.Optional<Swift.Optional<Any>>
194+
195+
// CHECK-64: Enum value:
196+
// CHECK-64: (enum_value name=some index=0
197+
// CHECK-64: (bound_generic_enum Swift.Optional
198+
// CHECK-64: (protocol_composition))
199+
// CHECK-64: )
200+
201+
// CHECK-32: Reflecting an enum.
202+
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
203+
// CHECK-32: Type reference:
204+
// CHECK-32: (bound_generic_enum Swift.Optional
205+
// CHECK-32: (bound_generic_enum Swift.Optional
206+
// CHECK-32: (protocol_composition)))
207+
208+
// CHECK-32: Type info:
209+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4094 bitwise_takable=1
210+
// CHECK-32: (case name=some index=0 offset=0
211+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4095 bitwise_takable=1
212+
// CHECK-32: (case name=some index=0 offset=0
213+
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1
214+
// CHECK-32: (field name=metadata offset=12
215+
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1))))
216+
// CHECK-32: (case name=none index=1)))
217+
// CHECK-32: (case name=none index=1))
218+
219+
// CHECK-32: Mangled name: $sypSgSg
220+
// CHECK-32: Demangled name: Swift.Optional<Swift.Optional<Any>>
221+
222+
// CHECK-32: Enum value:
223+
// CHECK-32: (enum_value name=some index=0
224+
// CHECK-32: (bound_generic_enum Swift.Optional
225+
// CHECK-32: (protocol_composition))
226+
// CHECK-32: )
227+
228+
// ================================================================
229+
230+
let optionalOptionalAnyNonNil: Any?? = .some(.some(7))
231+
reflect(enum: optionalOptionalAnyNonNil)
232+
233+
// CHECK-64: Reflecting an enum.
234+
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
235+
// CHECK-64: Type reference:
236+
// CHECK-64: (bound_generic_enum Swift.Optional
237+
// CHECK-64: (bound_generic_enum Swift.Optional
238+
// CHECK-64: (protocol_composition)))
239+
240+
// CHECK-64: Type info:
241+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483645 bitwise_takable=1
242+
// CHECK-64: (case name=some index=0 offset=0
243+
// CHECK-64: (single_payload_enum size=32 alignment=8 stride=32 num_extra_inhabitants=2147483646 bitwise_takable=1
244+
// CHECK-64: (case name=some index=0 offset=0
245+
// CHECK-64: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=2147483647 bitwise_takable=1
246+
// CHECK-64: (field name=metadata offset=24
247+
// CHECK-64: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1))))
248+
// CHECK-64: (case name=none index=1)))
249+
// CHECK-64: (case name=none index=1))
250+
251+
// CHECK-64: Mangled name: $sypSgSg
252+
// CHECK-64: Demangled name: Swift.Optional<Swift.Optional<Any>>
253+
254+
// CHECK-64: Enum value:
255+
// CHECK-64: (enum_value name=some index=0
256+
// CHECK-64: (bound_generic_enum Swift.Optional
257+
// CHECK-64: (protocol_composition))
258+
// CHECK-64: )
259+
260+
// CHECK-32: Reflecting an enum.
261+
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
262+
// CHECK-32: Type reference:
263+
// CHECK-32: (bound_generic_enum Swift.Optional
264+
// CHECK-32: (bound_generic_enum Swift.Optional
265+
// CHECK-32: (protocol_composition)))
266+
267+
// CHECK-32: Type info:
268+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4094 bitwise_takable=1
269+
// CHECK-32: (case name=some index=0 offset=0
270+
// CHECK-32: (single_payload_enum size=16 alignment=4 stride=16 num_extra_inhabitants=4095 bitwise_takable=1
271+
// CHECK-32: (case name=some index=0 offset=0
272+
// CHECK-32: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=4096 bitwise_takable=1
273+
// CHECK-32: (field name=metadata offset=12
274+
// CHECK-32: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=4096 bitwise_takable=1))))
275+
// CHECK-32: (case name=none index=1)))
276+
// CHECK-32: (case name=none index=1))
277+
278+
// CHECK-32: Mangled name: $sypSgSg
279+
// CHECK-32: Demangled name: Swift.Optional<Swift.Optional<Any>>
280+
281+
// CHECK-32: Enum value:
282+
// CHECK-32: (enum_value name=some index=0
283+
// CHECK-32: (bound_generic_enum Swift.Optional
284+
// CHECK-32: (protocol_composition))
285+
// CHECK-32: )
286+
287+
// ================================================================
288+
289+
doneReflecting()
290+
291+
// CHECK-64: Done.
292+
293+
// CHECK-32: Done.

0 commit comments

Comments
 (0)