Skip to content

Commit d864e95

Browse files
authored
Merge pull request #35497 from apple/Reflection-Support-OpaqueExistential-in-RecordTypeInfo-readExtraInhabitantIndex-release-5.4
[Reflection] Support OpaqueExistential in RecordTypeInfo::readExtraInhabitantIndex
2 parents 0d0f08c + 1b38159 commit d864e95

File tree

2 files changed

+304
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)