Skip to content

Commit 4370190

Browse files
committed
[IRGen] Ensure that all of the field type metadata is properly forced
1 parent 94017f7 commit 4370190

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,27 @@ void IRGenerator::emitLazyDefinitions() {
11541154
!LazyFieldTypes.empty() ||
11551155
!LazyWitnessTables.empty()) {
11561156

1157+
while (!LazyFieldTypes.empty()) {
1158+
auto info = LazyFieldTypes.pop_back_val();
1159+
auto &IGM = *info.IGM;
1160+
1161+
for (auto fieldType : info.fieldTypes) {
1162+
if (fieldType->hasArchetype())
1163+
continue;
1164+
1165+
// All of the required attributes are going to be preserved
1166+
// by field reflection metadata in the mangled name, so
1167+
// there is no need to worry about ownership semantics here.
1168+
if (auto refStorTy = dyn_cast<ReferenceStorageType>(fieldType))
1169+
fieldType = refStorTy.getReferentType();
1170+
1171+
// Make sure that all of the field type metadata is forced,
1172+
// otherwise there might be a problem when fields are accessed
1173+
// through reflection.
1174+
(void)irgen::getOrCreateTypeMetadataAccessFunction(IGM, fieldType);
1175+
}
1176+
}
1177+
11571178
// Emit any lazy type metadata we require.
11581179
while (!LazyMetadata.empty()) {
11591180
NominalTypeDecl *Nominal = LazyMetadata.pop_back_val();
@@ -1171,21 +1192,6 @@ void IRGenerator::emitLazyDefinitions() {
11711192
emitLazyTypeContextDescriptor(*IGM.get(), Nominal);
11721193
}
11731194
}
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-
}
1188-
}
11891195
while (!LazyWitnessTables.empty()) {
11901196
SILWitnessTable *wt = LazyWitnessTables.pop_back_val();
11911197
CurrentIGMPtr IGM = getGenModule(wt->getConformance()->getDeclContext());

0 commit comments

Comments
 (0)