Skip to content

Commit 7458640

Browse files
committed
[Runtime] Add nominal type descriptor field to foreign class metadata.
Like other nominal type metadata, include a nominal type descriptor in foreign class metadata.
1 parent 06dfe86 commit 7458640

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

docs/ABI/TypeMetadata.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ parameter vector contains witness tables for those protocols, as if laid out::
273273
AnsibleWitnessTable *U_Ansible;
274274
};
275275

276+
Foreign Class Metadata
277+
~~~~~~~~~~~~~~~~~~~~~~
278+
279+
Foreign class metadata describes "foreign" class types, which support Swift
280+
reference counting but are otherwise opaque to the Swift runtime.
281+
282+
- The `nominal type descriptor`_ for the most-derived class type is stored at
283+
**offset 0**.
284+
- The **super pointer** pointing to the metadata record for the superclass is
285+
stored at **offset 1**. If the class is a root class, it is null.
286+
- Three **pointer-sized fields**, starting at **offset 2**, are reserved for
287+
future use.
288+
276289
Nominal Type Descriptor
277290
~~~~~~~~~~~~~~~~~~~~~~~
278291

include/swift/Runtime/Metadata.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ template <typename Runtime> struct TargetClassMetadata;
729729
template <typename Runtime> struct TargetStructMetadata;
730730
template <typename Runtime> struct TargetOpaqueMetadata;
731731
template <typename Runtime> struct TargetValueMetadata;
732+
template <typename Runtime> struct TargetForeignClassMetadata;
732733

733734
// FIXME: https://bugs.swift.org/browse/SR-1155
734735
#pragma clang diagnostic push
@@ -907,6 +908,8 @@ struct TargetMetadata {
907908
return static_cast<const TargetValueMetadata<Runtime> *>(this)
908909
->Description;
909910
case MetadataKind::ForeignClass:
911+
return static_cast<const TargetForeignClassMetadata<Runtime> *>(this)
912+
->Description;
910913
case MetadataKind::Opaque:
911914
case MetadataKind::Tuple:
912915
case MetadataKind::Function:
@@ -1812,9 +1815,12 @@ struct TargetForeignClassMetadata
18121815
: public TargetForeignTypeMetadata<Runtime> {
18131816
using StoredPointer = typename Runtime::StoredPointer;
18141817

1818+
/// An out-of-line description of the type.
1819+
const TargetNominalTypeDescriptor<Runtime> *Description;
1820+
18151821
/// The superclass of the foreign class, if any.
18161822
ConstTargetMetadataPointer<Runtime, swift::TargetForeignClassMetadata>
1817-
SuperClass;
1823+
SuperClass;
18181824

18191825
/// Reserved space. For now, these should be zero-initialized.
18201826
StoredPointer Reserved[3];

lib/IRGen/GenMeta.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,6 +4901,7 @@ namespace {
49014901

49024902
void layout() {
49034903
super::layout();
4904+
asImpl().addNominalTypeDescriptor();
49044905
asImpl().addSuperClass();
49054906
asImpl().addReservedWord();
49064907
asImpl().addReservedWord();
@@ -5053,6 +5054,11 @@ namespace {
50535054
B.addInt(IGM.MetadataKindTy, (unsigned) MetadataKind::ForeignClass);
50545055
}
50555056

5057+
void addNominalTypeDescriptor() {
5058+
auto descriptor = ClassNominalTypeDescriptorBuilder(this->IGM, Target).emit();
5059+
B.add(descriptor);
5060+
}
5061+
50565062
void addSuperClass() {
50575063
// TODO: superclasses
50585064
B.addNullPointer(IGM.TypeMetadataPtrTy);

test/IRGen/cf.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
// CHECK-32: @_T0So14CCRefrigeratorCN = linkonce_odr hidden global <{ {{.*}} }> <{
1313
// CHECK-32-SAME: [[REFRIGERATOR_NAME]] to i32
1414
// CHECK-32-SAME: i32 0,
15-
// CHECK-32-SAME: i8** @_T0BOWV, i32 16, [[TYPE]]* null, i8* null, i8* null, i8* null }>
15+
// CHECK-32-SAME: i8** @_T0BOWV, i32 16, {{.*}}_T0So14CCRefrigeratorCMn, [[TYPE]]* null, i8* null, i8* null, i8* null }>
1616

1717
// CHECK-64: @_T0So14CCRefrigeratorCN = linkonce_odr hidden global <{ {{.*}} }> <{
1818
// CHECK-64-SAME: i32 0,
1919
// CHECK-64-SAME: i32 trunc {{.*}} [[REFRIGERATOR_NAME]] to i64
2020
// CHECK-64-SAME: i64 0,
21-
// CHECK-64-SAME: i8** @_T0BOWV, i64 16, [[TYPE]]* null, i8* null, i8* null, i8* null }>
21+
// CHECK-64-SAME: i8** @_T0BOWV, i64 16, {{.*}}_T0So14CCRefrigeratorCMn, [[TYPE]]* null, i8* null, i8* null, i8* null }>
2222

2323
sil_stage canonical
2424

0 commit comments

Comments
 (0)