Skip to content

Commit 478ba26

Browse files
committed
[IRGen] Emit type field descriptors for imported structs
1 parent 3df5928 commit 478ba26

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5618,7 +5618,9 @@ IRGenModule::getAddrOfForeignTypeMetadataCandidate(CanType type) {
56185618
} else if (auto structType = dyn_cast<StructType>(type)) {
56195619
auto structDecl = structType->getDecl();
56205620
assert(isa<ClangModuleUnit>(structDecl->getModuleScopeContext()));
5621-
5621+
5622+
ImportedStructs.insert(structDecl);
5623+
56225624
ForeignStructMetadataBuilder builder(*this, structDecl, init);
56235625
builder.layout();
56245626
addressPoint = builder.getOffsetOfAddressPoint();

lib/IRGen/GenReflection.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,13 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
368368
B.addInt16(fieldRecordSize);
369369

370370
// Imported classes don't need field descriptors
371-
if (NTD->hasClangNode()) {
372-
assert(isa<ClassDecl>(NTD));
371+
if (NTD->hasClangNode() && isa<ClassDecl>(NTD)) {
373372
B.addInt32(0);
374373
return;
375374
}
376375

376+
assert(!NTD->hasClangNode() || isa<StructDecl>(NTD));
377+
377378
auto properties = NTD->getStoredProperties();
378379
B.addInt32(std::distance(properties.begin(), properties.end()));
379380
for (auto property : properties)
@@ -435,6 +436,7 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
435436
void layout() override {
436437
if (NTD->hasClangNode() &&
437438
!isa<ClassDecl>(NTD) &&
439+
!isa<StructDecl>(NTD) &&
438440
!isa<ProtocolDecl>(NTD))
439441
return;
440442

@@ -941,6 +943,9 @@ void IRGenModule::emitBuiltinReflectionMetadata() {
941943
for (auto PD : ImportedProtocols)
942944
emitFieldMetadataRecord(PD);
943945

946+
for (auto SD : ImportedStructs)
947+
emitFieldMetadataRecord(SD);
948+
944949
for (auto builtinType : BuiltinTypes)
945950
emitBuiltinTypeMetadataRecord(builtinType);
946951

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,9 @@ class IRGenModule {
920920
/// Imported protocols referenced by types in this module when emitting
921921
/// reflection metadata.
922922
llvm::SetVector<const ProtocolDecl *> ImportedProtocols;
923+
/// Imported structs referenced by types in this module when emitting
924+
/// reflection metadata.
925+
llvm::SetVector<const StructDecl *> ImportedStructs;
923926

924927
llvm::Constant *getAddrOfStringForTypeRef(StringRef Str);
925928
llvm::Constant *getAddrOfFieldName(StringRef Name);

0 commit comments

Comments
 (0)