Skip to content

Commit f6be62d

Browse files
committed
[IRGen] Remove lazy field type accessor functions
All of their usages have been replaced with new runtime `swift_getFieldAt` method.
1 parent 9d6dc72 commit f6be62d

File tree

11 files changed

+48
-365
lines changed

11 files changed

+48
-365
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,16 +1289,6 @@ struct TargetClassMetadata : public TargetHeapMetadata<Runtime> {
12891289
auto asWords = reinterpret_cast<const void * const*>(this);
12901290
return reinterpret_cast<const StoredPointer *>(asWords + offset);
12911291
}
1292-
1293-
/// Get a pointer to the field type vector, if present, or null.
1294-
const FieldType *getFieldTypes() const {
1295-
assert(isTypeMetadata());
1296-
auto *getter = getDescription()->GetFieldTypes.get();
1297-
if (!getter)
1298-
return nullptr;
1299-
1300-
return getter(this);
1301-
}
13021292

13031293
uint32_t getSizeInWords() const {
13041294
assert(isTypeMetadata());
@@ -1571,15 +1561,6 @@ struct TargetStructMetadata : public TargetValueMetadata<Runtime> {
15711561
auto asWords = reinterpret_cast<const void * const*>(this);
15721562
return reinterpret_cast<const StoredPointer *>(asWords + offset);
15731563
}
1574-
1575-
/// Get a pointer to the field type vector, if present, or null.
1576-
const FieldType *getFieldTypes() const {
1577-
auto *getter = getDescription()->GetFieldTypes.get();
1578-
if (!getter)
1579-
return nullptr;
1580-
1581-
return getter(this);
1582-
}
15831564

15841565
static bool classof(const TargetMetadata<Runtime> *metadata) {
15851566
return metadata->getKind() == MetadataKind::Struct;
@@ -3177,12 +3158,6 @@ class TargetClassDescriptor final
31773158
/// length and order is consistent with that of the field offset vector.
31783159
RelativeDirectPointer<const char, /*nullable*/ true> FieldNames;
31793160

3180-
/// The field type vector accessor. Returns a pointer to an array of
3181-
/// type metadata references whose order is consistent with that of the
3182-
/// field offset vector.
3183-
RelativeDirectPointer<const FieldType *
3184-
(const TargetMetadata<Runtime> *)> GetFieldTypes;
3185-
31863161
/// True if metadata records for this type have a field offset vector for
31873162
/// its stored properties.
31883163
bool hasFieldOffsetVector() const { return FieldOffsetVectorOffset != 0; }
@@ -3286,12 +3261,6 @@ class TargetStructDescriptor final
32863261
/// The field names. A doubly-null-terminated list of strings, whose
32873262
/// length and order is consistent with that of the field offset vector.
32883263
RelativeDirectPointer<const char, /*nullable*/ true> FieldNames;
3289-
3290-
/// The field type vector accessor. Returns a pointer to an array of
3291-
/// type metadata references whose order is consistent with that of the
3292-
/// field offset vector.
3293-
RelativeDirectPointer<const FieldType *
3294-
(const TargetMetadata<Runtime> *)> GetFieldTypes;
32953264

32963265
/// True if metadata records for this type have a field offset vector for
32973266
/// its stored properties.
@@ -3340,13 +3309,6 @@ class TargetEnumDescriptor final
33403309
/// tag order, non-empty cases first, followed by empty cases.
33413310
RelativeDirectPointer<const char, /*nullable*/ true> CaseNames;
33423311

3343-
/// The field type vector accessor. Returns a pointer to an array of
3344-
/// type metadata references whose order is consistent with that of the
3345-
/// CaseNames. Only types for payload cases are provided.
3346-
RelativeDirectPointer<
3347-
const FieldType * (const TargetMetadata<Runtime> *)>
3348-
GetCaseTypes;
3349-
33503312
uint32_t getNumPayloadCases() const {
33513313
return NumPayloadCasesAndPayloadSizeOffset & 0x00FFFFFFU;
33523314
}

lib/IRGen/GenDecl.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ void IRGenerator::emitLazyDefinitions() {
11511151
while (!LazyMetadata.empty() ||
11521152
!LazyTypeContextDescriptors.empty() ||
11531153
!LazyFunctionDefinitions.empty() ||
1154-
!LazyFieldTypeAccessors.empty() ||
1154+
!LazyFieldTypes.empty() ||
11551155
!LazyWitnessTables.empty()) {
11561156

11571157
// Emit any lazy type metadata we require.
@@ -1171,10 +1171,20 @@ void IRGenerator::emitLazyDefinitions() {
11711171
emitLazyTypeContextDescriptor(*IGM.get(), Nominal);
11721172
}
11731173
}
1174-
while (!LazyFieldTypeAccessors.empty()) {
1175-
auto accessor = LazyFieldTypeAccessors.pop_back_val();
1176-
emitFieldTypeAccessor(*accessor.IGM, accessor.type, accessor.fn,
1177-
accessor.fieldTypes);
1174+
while (!LazyFieldTypes.empty()) {
1175+
auto info = LazyFieldTypes.pop_back_val();
1176+
auto &IGM = *info.IGM;
1177+
1178+
for (auto fieldType : info.fieldTypes) {
1179+
if (fieldType->isAnyExistentialType())
1180+
continue;
1181+
1182+
// Ensure that all of the foreign metadata is forced, otherwise
1183+
// there might be a problem when fields are accessed through
1184+
// reflection.
1185+
if (IGM.requiresForeignTypeMetadata(fieldType))
1186+
(void)IGM.getAddrOfForeignTypeMetadataCandidate(fieldType);
1187+
}
11781188
}
11791189
while (!LazyWitnessTables.empty()) {
11801190
SILWitnessTable *wt = LazyWitnessTables.pop_back_val();

0 commit comments

Comments
 (0)