@@ -1246,7 +1246,7 @@ struct EnumTypeDescriptor;
1246
1246
// / descriptor is shared for all instantiations of the generic type.
1247
1247
struct NominalTypeDescriptor {
1248
1248
// / The mangled name of the nominal type, with no generic parameters.
1249
- RelativeDirectPointer<char > Name;
1249
+ RelativeDirectPointer<const char > Name;
1250
1250
1251
1251
// / The following fields are kind-dependent.
1252
1252
union {
@@ -1266,7 +1266,7 @@ struct NominalTypeDescriptor {
1266
1266
1267
1267
// / The field names. A doubly-null-terminated list of strings, whose
1268
1268
// / length and order is consistent with that of the field offset vector.
1269
- RelativeDirectPointer<char , /* nullable*/ true > FieldNames;
1269
+ RelativeDirectPointer<const char , /* nullable*/ true > FieldNames;
1270
1270
1271
1271
// / The field type vector accessor. Returns a pointer to an array of
1272
1272
// / type metadata references whose order is consistent with that of the
@@ -1290,7 +1290,7 @@ struct NominalTypeDescriptor {
1290
1290
1291
1291
// / The field names. A doubly-null-terminated list of strings, whose
1292
1292
// / length and order is consistent with that of the field offset vector.
1293
- RelativeDirectPointer<char , /* nullable*/ true > FieldNames;
1293
+ RelativeDirectPointer<const char , /* nullable*/ true > FieldNames;
1294
1294
1295
1295
// / The field type vector accessor. Returns a pointer to an array of
1296
1296
// / type metadata references whose order is consistent with that of the
@@ -1313,7 +1313,7 @@ struct NominalTypeDescriptor {
1313
1313
// / The names of the cases. A doubly-null-terminated list of strings,
1314
1314
// / whose length is NumNonEmptyCases + NumEmptyCases. Cases are named in
1315
1315
// / tag order, non-empty cases first, followed by empty cases.
1316
- RelativeDirectPointer<char , /* nullable*/ true > CaseNames;
1316
+ RelativeDirectPointer<const char , /* nullable*/ true > CaseNames;
1317
1317
// / The field type vector accessor. Returns a pointer to an array of
1318
1318
// / type metadata references whose order is consistent with that of the
1319
1319
// / CaseNames. Only types for payload cases are provided.
@@ -1372,20 +1372,19 @@ typedef void (*ClassIVarDestroyer)(HeapObject *);
1372
1372
struct ClassMetadata : public HeapMetadata {
1373
1373
ClassMetadata () = default ;
1374
1374
constexpr ClassMetadata (const HeapMetadata &base,
1375
- const ClassMetadata *superClass,
1376
- uintptr_t data,
1377
- ClassFlags flags,
1378
- const NominalTypeDescriptor *description,
1379
- ClassIVarDestroyer ivarDestroyer,
1380
- uintptr_t size, uintptr_t addressPoint,
1381
- uintptr_t alignMask,
1382
- uintptr_t classSize, uintptr_t classAddressPoint)
1375
+ const ClassMetadata *superClass,
1376
+ uintptr_t data,
1377
+ ClassFlags flags,
1378
+ ClassIVarDestroyer ivarDestroyer,
1379
+ uintptr_t size, uintptr_t addressPoint,
1380
+ uintptr_t alignMask,
1381
+ uintptr_t classSize, uintptr_t classAddressPoint)
1383
1382
: HeapMetadata(base), SuperClass(superClass),
1384
1383
CacheData{nullptr , nullptr }, Data(data),
1385
1384
Flags (flags), InstanceAddressPoint(addressPoint),
1386
1385
InstanceSize (size), InstanceAlignMask(alignMask),
1387
1386
Reserved (0 ), ClassSize(classSize), ClassAddressPoint(classAddressPoint),
1388
- Description (description ), IVarDestroyer(ivarDestroyer) {}
1387
+ Description (nullptr ), IVarDestroyer(ivarDestroyer) {}
1389
1388
1390
1389
// / The metadata for the superclass. This is null for the root class.
1391
1390
const ClassMetadata *SuperClass;
@@ -1443,7 +1442,8 @@ struct ClassMetadata : public HeapMetadata {
1443
1442
// / if this is an artificial subclass. We currently provide no
1444
1443
// / supported mechanism for making a non-artificial subclass
1445
1444
// / dynamically.
1446
- const NominalTypeDescriptor *Description;
1445
+ FarRelativeDirectPointer<const NominalTypeDescriptor,
1446
+ /* nullable*/ true > Description;
1447
1447
1448
1448
// / A function for destroying instance variables, used to clean up
1449
1449
// / after an early return from a constructor.
@@ -1462,6 +1462,10 @@ struct ClassMetadata : public HeapMetadata {
1462
1462
assert (!isArtificialSubclass ());
1463
1463
return Description;
1464
1464
}
1465
+
1466
+ void setDescription (const NominalTypeDescriptor *description) {
1467
+ Description = description;
1468
+ }
1465
1469
1466
1470
ClassIVarDestroyer getIVarDestroyer () const {
1467
1471
assert (isTypeMetadata ());
@@ -1713,14 +1717,40 @@ struct ForeignClassMetadata : public ForeignTypeMetadata {
1713
1717
}
1714
1718
};
1715
1719
1716
- // / The structure of type metadata for structs.
1717
- struct StructMetadata : public Metadata {
1720
+ // / The common structure of metadata for structs and enums.
1721
+ struct ValueMetadata : public Metadata {
1722
+ ValueMetadata (MetadataKind Kind, const NominalTypeDescriptor *description,
1723
+ const Metadata *parent)
1724
+ : Metadata(Kind), Description(description), Parent(parent)
1725
+ {}
1726
+
1718
1727
// / An out-of-line description of the type.
1719
- const NominalTypeDescriptor * Description;
1728
+ FarRelativeDirectPointer< const NominalTypeDescriptor> Description;
1720
1729
1721
1730
// / The parent type of this member type, or null if this is not a
1722
1731
// / member type.
1723
- const Metadata *Parent;
1732
+ FarRelativeIndirectablePointer<const Metadata, /* nullable*/ true > Parent;
1733
+
1734
+ static bool classof (const Metadata *metadata) {
1735
+ return metadata->getKind () == MetadataKind::Struct
1736
+ || metadata->getKind () == MetadataKind::Enum
1737
+ || metadata->getKind () == MetadataKind::Optional;
1738
+ }
1739
+
1740
+ // / Retrieve the generic arguments of this type.
1741
+ const Metadata * const *getGenericArgs () const {
1742
+ if (Description->GenericParams .NumParams == 0 )
1743
+ return nullptr ;
1744
+
1745
+ const void * const *asWords = reinterpret_cast <const void * const *>(this );
1746
+ asWords += Description->GenericParams .Offset ;
1747
+ return reinterpret_cast <const Metadata * const *>(asWords);
1748
+ }
1749
+ };
1750
+
1751
+ // / The structure of type metadata for structs.
1752
+ struct StructMetadata : public ValueMetadata {
1753
+ using ValueMetadata::ValueMetadata;
1724
1754
1725
1755
// / Get a pointer to the field offset vector, if present, or null.
1726
1756
const uintptr_t *getFieldOffsets () const {
@@ -1740,29 +1770,14 @@ struct StructMetadata : public Metadata {
1740
1770
return getter (this );
1741
1771
}
1742
1772
1743
- // / Retrieve the generic arguments of this struct.
1744
- const Metadata * const *getGenericArgs () const {
1745
- if (Description->GenericParams .NumParams == 0 )
1746
- return nullptr ;
1747
-
1748
- const void * const *asWords = reinterpret_cast <const void * const *>(this );
1749
- asWords += Description->GenericParams .Offset ;
1750
- return reinterpret_cast <const Metadata * const *>(asWords);
1751
- }
1752
-
1753
1773
static bool classof (const Metadata *metadata) {
1754
1774
return metadata->getKind () == MetadataKind::Struct;
1755
1775
}
1756
1776
};
1757
1777
1758
1778
// / The structure of type metadata for enums.
1759
- struct EnumMetadata : public Metadata {
1760
- // / An out-of-line description of the type.
1761
- const NominalTypeDescriptor *Description;
1762
-
1763
- // / The parent type of this member type, or null if this is not a
1764
- // / member type.
1765
- const Metadata *Parent;
1779
+ struct EnumMetadata : public ValueMetadata {
1780
+ using ValueMetadata::ValueMetadata;
1766
1781
1767
1782
// / True if the metadata records the size of the payload area.
1768
1783
bool hasPayloadSize () const {
@@ -1788,16 +1803,6 @@ struct EnumMetadata : public Metadata {
1788
1803
return *asWords;
1789
1804
}
1790
1805
1791
- // / Retrieve the generic arguments of this enum.
1792
- const Metadata * const *getGenericArgs () const {
1793
- const void * const *asWords = reinterpret_cast <const void * const *>(this );
1794
- if (Description->GenericParams .NumParams == 0 )
1795
- return nullptr ;
1796
-
1797
- asWords += Description->GenericParams .Offset ;
1798
- return reinterpret_cast <const Metadata * const *>(asWords);
1799
- }
1800
-
1801
1806
static bool classof (const Metadata *metadata) {
1802
1807
return metadata->getKind () == MetadataKind::Enum
1803
1808
|| metadata->getKind () == MetadataKind::Optional;
@@ -2215,7 +2220,7 @@ struct GenericWitnessTable {
2215
2220
/* nullable*/ true > Protocol;
2216
2221
2217
2222
// / The pattern.
2218
- RelativeDirectPointer<WitnessTable> Pattern;
2223
+ RelativeDirectPointer<const WitnessTable> Pattern;
2219
2224
2220
2225
// / The instantiation function, which is called after the template is copied.
2221
2226
RelativeDirectPointer<void (WitnessTable *instantiatedTable,
@@ -2240,7 +2245,7 @@ struct TypeMetadataRecord {
2240
2245
// Some description of the type that is resolvable at runtime.
2241
2246
union {
2242
2247
// / A direct reference to the metadata.
2243
- RelativeDirectPointer<Metadata> DirectType;
2248
+ RelativeDirectPointer<const Metadata> DirectType;
2244
2249
2245
2250
// / The nominal type descriptor for a resilient or generic type.
2246
2251
RelativeDirectPointer<NominalTypeDescriptor> TypeDescriptor;
@@ -2327,7 +2332,7 @@ struct ProtocolConformanceRecord {
2327
2332
// The conformance, or a generator function for the conformance.
2328
2333
union {
2329
2334
// / A direct reference to the witness table for the conformance.
2330
- RelativeDirectPointer<WitnessTable> WitnessTable;
2335
+ RelativeDirectPointer<const WitnessTable> WitnessTable;
2331
2336
2332
2337
// / A function that produces the witness table given an instance of the
2333
2338
// / type. The function may return null if a specific instance does not
@@ -2502,7 +2507,7 @@ swift_allocateGenericClassMetadata(GenericMetadata *pattern,
2502
2507
2503
2508
// Callback to allocate a generic struct/enum metadata object.
2504
2509
SWIFT_RUNTIME_EXPORT
2505
- extern " C" Metadata *
2510
+ extern " C" ValueMetadata *
2506
2511
swift_allocateGenericValueMetadata (GenericMetadata *pattern,
2507
2512
const void *arguments);
2508
2513
0 commit comments