Skip to content

Commit a24729a

Browse files
committed
[ABI] Add a mangled superclass type to class context descriptors.
This allows us to recover the complete superclass type from metadata. Currently unused, but we want to stub out the space in the ABI.
1 parent a4778e1 commit a24729a

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

include/swift/ABI/Metadata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,6 +3683,10 @@ class TargetClassDescriptor final
36833683
.class_getResilientSuperclassReferenceKind();
36843684
}
36853685

3686+
/// The type of the superclass, expressed as a mangled type name that can
3687+
/// refer to the generic arguments of the subclass type.
3688+
TargetRelativeDirectPointer<Runtime, const char> SuperclassType;
3689+
36863690
union {
36873691
/// If this descriptor does not have a resilient superclass, this is the
36883692
/// negative size of metadata objects of this class (in words).

lib/IRGen/GenMeta.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,15 @@ namespace {
15891589
}
15901590

15911591
void addLayoutInfo() {
1592+
1593+
// TargetRelativeDirectPointer<Runtime, const char> SuperclassType;
1594+
if (auto superclassType = getType()->getSuperclass()) {
1595+
B.addRelativeAddress(IGM.getTypeRef(superclassType->getCanonicalType(),
1596+
MangledTypeRefRole::Metadata));
1597+
} else {
1598+
B.addInt32(0);
1599+
}
1600+
15921601
auto properties = getType()->getStoredProperties();
15931602

15941603
// union {

test/IRGen/class_metadata.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class B : A {}
5050
// CHECK-SAME: i32 {{.*}} [[B_NAME]]
5151
// Metadata access function.
5252
// CHECK-SAME: i32 {{.*}} @"$s14class_metadata1BCMa"
53-
// Superclass.
54-
// CHECK-SAME: @"$s14class_metadata1ACMn"
53+
// Superclass type.
54+
// CHECK-SAME: @"symbolic \01____ 14class_metadata1AC"
5555
// Negative size in words.
5656
// CHECK-SAME: i32 2,
5757
// Positive size in words.
@@ -88,8 +88,8 @@ class C<T> : B {}
8888
// CHECK-SAME: i32 {{.*}} [[C_NAME]]
8989
// Metadata access function.
9090
// CHECK-SAME: i32 {{.*}} @"$s14class_metadata1CCMa"
91-
// Superclass.
92-
// CHECK-SAME: i32 {{.*}} @"$s14class_metadata1BCMn"
91+
// Superclass type.
92+
// CHECK-SAME: @"symbolic \01____ 14class_metadata1BC"
9393
// Negative size in words.
9494
// CHECK-SAME: i32 2,
9595
// Positive size in words.
@@ -141,16 +141,16 @@ class D : E {}
141141

142142
// CHECK: [[D_NAME:@.*]] = private constant [2 x i8] c"D\00"
143143
// CHECK-LABEL: @"$s14class_metadata1DCMn" =
144-
// Flags. 0x4200_0050 == HasOverrideTable | IndirectSuperclass | Unique | Class
145-
// CHECK-SAME: <i32 0x4200_0050>,
144+
// Flags. 0x4200_0050 == HasOverrideTable | Unique | Class
145+
// CHECK-SAME: <i32 0x4000_0050>,
146146
// Parent.
147147
// CHECK-SAME: i32 {{.*}} @"$s14class_metadataMXM"
148148
// Name.
149149
// CHECK-SAME: i32 {{.*}} [[D_NAME]]
150150
// Metadata access function.
151151
// CHECK-SAME: i32 {{.*}} @"$s14class_metadata1DCMa"
152-
// Superclass.
153-
// CHECK-SAME: @"got.$s14class_metadata1ECMn.1"
152+
// Superclass type.
153+
// CHECK-SAME: @"symbolic \01____ 14class_metadata1EC"
154154
// Negative size in words.
155155
// CHECK-SAME: i32 2,
156156
// Positive size in words.
@@ -174,3 +174,7 @@ class D : E {}
174174
// CHECK-SAME: @"$s14class_metadata1DCACycfC"
175175
// CHECK-SAME: }>, section
176176
class E {}
177+
178+
// CHECK-LABEL: @"$s14class_metadata1FCMn" =
179+
// CHECK-SAME: @"symbolic \01____yq_G 14class_metadata1CC"
180+
class F<T, U> : C<U> { }

test/IRGen/class_resilience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
// CHECK-SAME: @"$s16class_resilience14ResilientChildCMa"
4444
// -- field descriptor:
4545
// CHECK-SAME: @"$s16class_resilience14ResilientChildCMF"
46-
// -- superclass:
47-
// CHECK-SAME: @"got.$s15resilient_class22ResilientOutsideParentCMn"
4846
// -- metadata bounds:
4947
// CHECK-SAME: @"$s16class_resilience14ResilientChildCMo"
5048
// -- metadata positive size in words (not used):
@@ -55,6 +53,8 @@
5553
// CHECK-SAME: i32 1,
5654
// -- field offset vector offset:
5755
// CHECK-SAME: i32 3,
56+
// -- superclass:
57+
// CHECK-SAME: @"got.$s15resilient_class22ResilientOutsideParentCMn"
5858
// -- singleton metadata initialization cache:
5959
// CHECK-SAME: @"$s16class_resilience14ResilientChildCMl"
6060
// -- resilient pattern:

0 commit comments

Comments
 (0)