Skip to content

Commit 674c762

Browse files
authored
Merge pull request #77062 from tbkka/tbkka-remotemirror-133890406
Let indirect enum cases export spare bits
2 parents 9af4d6e + 3abefd1 commit 674c762

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,12 +2039,21 @@ class EnumTypeInfoBuilder {
20392039
// We don't have typeinfo; something is very broken.
20402040
Invalid = true;
20412041
return nullptr;
2042+
} else if (Case.Indirect) {
2043+
// An indirect case is non-empty (it stores a pointer)
2044+
// and acts like a non-generic (because the pointer has spare bits)
2045+
++NonGenericNonEmptyPayloadCases;
2046+
LastPayloadCaseTR = CaseTR;
20422047
} else if (Case.Generic) {
2048+
// Otherwise, we never consider spare bits from generic cases
20432049
++GenericPayloadCases;
20442050
LastPayloadCaseTR = CaseTR;
20452051
} else if (CaseTI->getSize() == 0) {
2052+
// Needed to distinguish a "single-payload enum"
2053+
// whose only case is empty.
20462054
++NonGenericEmptyPayloadCases;
20472055
} else {
2056+
// Finally, we consider spare bits from regular payloads
20482057
++NonGenericNonEmptyPayloadCases;
20492058
LastPayloadCaseTR = CaseTR;
20502059
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -lswiftSwiftReflectionTest %s -o %t/reflect_Enum_values12
3+
// RUN: %target-codesign %t/reflect_Enum_values12
4+
5+
// RUN: %target-run %target-swift-reflection-test %t/reflect_Enum_values12 | tee /dev/stderr | %FileCheck %s --check-prefix=CHECK%target-ptrsize --check-prefix=CHECKALL --dump-input=fail %add_num_extra_inhabitants
6+
7+
// REQUIRES: objc_interop
8+
// REQUIRES: executable_test
9+
// REQUIRES: reflection_test_support
10+
// UNSUPPORTED: use_os_stdlib
11+
// UNSUPPORTED: asan
12+
13+
import SwiftReflectionTest
14+
15+
indirect enum Outer<T> {
16+
case a(T)
17+
case b(T)
18+
}
19+
20+
class C {
21+
var outer: Outer<Int>
22+
init() { outer = .a(99) }
23+
}
24+
25+
reflect(enumValue: Outer<Int>.a(12))
26+
27+
// CHECKALL: Reflecting an enum value.
28+
// CHECKALL-NEXT: Type reference:
29+
// CHECKALL-NEXT: (bound_generic_enum reflect_Enum_values12.Outer
30+
// CHECKALL-NEXT: (struct Swift.Int))
31+
// CHECKALL-NEXT: Value: .a(_)
32+
33+
reflect(enumValue: Outer<Int>.b(7))
34+
35+
// CHECKALL: Reflecting an enum value.
36+
// CHECKALL-NEXT: Type reference:
37+
// CHECKALL-NEXT: (bound_generic_enum reflect_Enum_values12.Outer
38+
// CHECKALL-NEXT: (struct Swift.Int))
39+
// CHECKALL-NEXT: Value: .b(_)
40+
41+
reflect(enumValue: Optional<Outer<Int>>.some(.a(12)))
42+
43+
// CHECKALL: Reflecting an enum value.
44+
// CHECKALL-NEXT: Type reference:
45+
// CHECKALL-NEXT: (bound_generic_enum Swift.Optional
46+
// CHECKALL-NEXT: (bound_generic_enum reflect_Enum_values12.Outer
47+
// CHECKALL-NEXT: (struct Swift.Int)))
48+
// CHECKALL-NEXT: Value: .some(.a(_))
49+
50+
reflect(enumValue: Optional<Outer<Int>>.some(.b(7)))
51+
52+
// CHECKALL: Reflecting an enum value.
53+
// CHECKALL-NEXT: Type reference:
54+
// CHECKALL-NEXT: (bound_generic_enum Swift.Optional
55+
// CHECKALL-NEXT: (bound_generic_enum reflect_Enum_values12.Outer
56+
// CHECKALL-NEXT: (struct Swift.Int)))
57+
// CHECKALL-NEXT: Value: .some(.b(_))
58+
59+
reflect(enumValue: Optional<Outer<Int>>.none)
60+
61+
// CHECKALL: Reflecting an enum value.
62+
// CHECKALL-NEXT: Type reference:
63+
// CHECKALL-NEXT: (bound_generic_enum Swift.Optional
64+
// CHECKALL-NEXT: (bound_generic_enum reflect_Enum_values12.Outer
65+
// CHECKALL-NEXT: (struct Swift.Int)))
66+
// CHECKALL-NEXT: Value: .none
67+
68+
reflect(object: C())
69+
70+
// CHECKALL: Reflecting an object.
71+
// CHECKALL-NEXT: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
72+
// CHECKALL-NEXT: Type reference:
73+
// CHECKALL-NEXT: (class reflect_Enum_values12.C)
74+
75+
// CHECKALL: Type info:
76+
77+
// CHECK64-NEXT: (class_instance size=24 alignment=8 stride=24 num_extra_inhabitants=0 bitwise_takable=1
78+
// CHECK64-NEXT: (field name=outer offset=16
79+
// x86_64 and arm64 have different spare bit pointer masks, hence different numbers of extra inhabitants here
80+
// CHECK64-NEXT: (multi_payload_enum size=8 alignment=8 stride=8 num_extra_inhabitants={{[0-9]+}} bitwise_takable=1
81+
82+
// CHECK32-NEXT: (class_instance size=12 alignment=4 stride=12 num_extra_inhabitants=0 bitwise_takable=1
83+
// CHECK32-NEXT: (field name=outer offset=8
84+
// CHECK32-NEXT: (multi_payload_enum size=4 alignment=4 stride=4 num_extra_inhabitants=2 bitwise_takable=1
85+
86+
// CHECKALL-NEXT: (case name=a index=0 offset=0
87+
// CHECKALL-NEXT: (reference kind=strong refcounting=native))
88+
// CHECKALL-NEXT: (case name=b index=1 offset=0
89+
// CHECKALL-NEXT: (reference kind=strong refcounting=native)))))
90+
91+
92+
doneReflecting()
93+
94+
// CHECKALL: Done.
95+

0 commit comments

Comments
 (0)