Skip to content

Commit 1685b98

Browse files
authored
Merge pull request swiftlang#33497 from nate-chandler/generic-metadata-prespecialization-components/replace-erase-with-early-return
2 parents bb7fa7d + e23cc54 commit 1685b98

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ static void
11681168
deleteAndReenqueueForEmissionValuesDependentOnCanonicalPrespecializedMetadataRecords(
11691169
IRGenModule &IGM, CanType typeWithCanonicalMetadataPrespecialization,
11701170
NominalTypeDecl &decl) {
1171+
IGM.IRGen.noteLazyReemissionOfNominalTypeDescriptor(&decl);
11711172
// The type context descriptor depends on canonical metadata records because
11721173
// pointers to them are attached as trailing objects to it.
11731174
//

lib/IRGen/GenMeta.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ static void buildMethodDescriptorFields(IRGenModule &IGM,
301301
void IRGenModule::emitNonoverriddenMethodDescriptor(const SILVTable *VTable,
302302
SILDeclRef declRef) {
303303
auto entity = LinkEntity::forMethodDescriptor(declRef);
304-
305304
auto *var = cast<llvm::GlobalVariable>(getAddrOfLLVMVariable(entity, ConstantInit(), DebugTypeInfo()));
306-
var->setInitializer(nullptr);
307-
305+
if (!var->isDeclaration()) {
306+
assert(IRGen.isLazilyReemittingNominalTypeDescriptor(VTable->getClass()));
307+
return;
308+
}
309+
308310
ConstantInitBuilder ib(*this);
309311
ConstantStructBuilder sb(ib.beginStruct(MethodDescriptorStructTy));
310312

lib/IRGen/GenThunk.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static FunctionPointer lookupMethod(IRGenFunction &IGF, SILDeclRef declRef) {
103103
void IRGenModule::emitDispatchThunk(SILDeclRef declRef) {
104104
auto *f = getAddrOfDispatchThunk(declRef, ForDefinition);
105105
if (!f->isDeclaration()) {
106-
f->deleteBody();
106+
return;
107107
}
108108

109109
IRGenFunction IGF(*this, f);
@@ -167,7 +167,8 @@ IRGenModule::getAddrOfMethodLookupFunction(ClassDecl *classDecl,
167167
void IRGenModule::emitMethodLookupFunction(ClassDecl *classDecl) {
168168
auto *f = getAddrOfMethodLookupFunction(classDecl, ForDefinition);
169169
if (!f->isDeclaration()) {
170-
f->deleteBody();
170+
assert(IRGen.isLazilyReemittingNominalTypeDescriptor(classDecl));
171+
return;
171172
}
172173

173174
IRGenFunction IGF(*this, f);

lib/IRGen/IRGenModule.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class IRGenerator {
279279
llvm::SmallVector<std::pair<CanType, TypeMetadataCanonicality>, 4>
280280
LazySpecializedTypeMetadataRecords;
281281

282+
llvm::SmallPtrSet<NominalTypeDecl *, 4> LazilyReemittedTypeContextDescriptors;
283+
282284
/// The queue of metadata accessors to emit.
283285
///
284286
/// The accessors must be emitted after everything else which might result in
@@ -436,6 +438,15 @@ class IRGenerator {
436438
return MetadataPrespecializationsForGenericTypes.lookup(type);
437439
}
438440

441+
void noteLazyReemissionOfNominalTypeDescriptor(NominalTypeDecl *decl) {
442+
LazilyReemittedTypeContextDescriptors.insert(decl);
443+
}
444+
445+
bool isLazilyReemittingNominalTypeDescriptor(NominalTypeDecl *decl) {
446+
return LazilyReemittedTypeContextDescriptors.find(decl) !=
447+
std::end(LazilyReemittedTypeContextDescriptors);
448+
}
449+
439450
void noteUseOfMetadataAccessor(NominalTypeDecl *decl) {
440451
if (LazyMetadataAccessors.count(decl) == 0) {
441452
LazyMetadataAccessors.insert(decl);

0 commit comments

Comments
 (0)