Skip to content

Commit 6aa82fd

Browse files
authored
Merge pull request #18490 from DougGregor/irgen-local-conformances
[IRGen] Only emit conformances local to a nominal type along with its metadata
2 parents 5a07d81 + 3c1f6f7 commit 6aa82fd

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,11 @@ llvm::Constant *IRGenModule::getAddrOfAssociatedTypeGenericParamRef(
938938
return var;
939939
}
940940

941-
void IRGenModule::addLazyConformances(NominalTypeDecl *Nominal) {
942-
for (const ProtocolConformance *Conf : Nominal->getAllConformances()) {
943-
IRGen.addLazyWitnessTable(Conf);
941+
void IRGenModule::addLazyConformances(DeclContext *dc) {
942+
for (const ProtocolConformance *conf :
943+
dc->getLocalConformances(ConformanceLookupKind::All,
944+
nullptr, /*sorted=*/true)) {
945+
IRGen.addLazyWitnessTable(conf);
944946
}
945947
}
946948

@@ -3827,6 +3829,8 @@ static bool shouldEmitCategory(IRGenModule &IGM, ExtensionDecl *ext) {
38273829
void IRGenModule::emitExtension(ExtensionDecl *ext) {
38283830
emitNestedTypeDecls(ext->getMembers());
38293831

3832+
addLazyConformances(ext);
3833+
38303834
// Generate a category if the extension either introduces a
38313835
// conformance to an ObjC protocol or introduces a method
38323836
// that requires an Objective-C entry point.

lib/IRGen/IRGenModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,8 @@ private: \
13101310
void emitLazyPrivateDefinitions();
13111311
void addRuntimeResolvableType(NominalTypeDecl *nominal);
13121312

1313-
/// Add all conformances of \p Nominal to LazyWitnessTables.
1314-
void addLazyConformances(NominalTypeDecl *Nominal);
1313+
/// Add all conformances of the given \c DeclContext LazyWitnessTables.
1314+
void addLazyConformances(DeclContext *dc);
13151315

13161316
//--- Global context emission --------------------------------------------------
13171317
public:

test/IRGen/conformance_multifile.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
func g<U>(_ f : (E) throws -> (U)) {}
44

5+
// The extension E: P should not show up in this filel.
6+
// CHECK-NOT: $S21conformance_multifile1EOAA1PAAMc
7+
58
// CHECK: $S21conformance_multifile1tyyF
69
func t() {
710
g(E2.Filter)
811
}
12+
13+
// The extension E: P should not show up in this filel.
14+
// CHECK-NOT: $S21conformance_multifile1EOAA1PAAMc

0 commit comments

Comments
 (0)