Skip to content

Commit 42fa720

Browse files
author
ematejska
authored
Merge pull request #7074 from jckarter/use-assoc-type-conformance-3.1
[3.1] SILGen: Mark associated type conformances as "used".
2 parents 8ea6cfb + daf0596 commit 42fa720

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,9 @@ void SILGenModule::emitExternalDefinition(Decl *d) {
12421242
case DeclKind::Struct:
12431243
case DeclKind::Class: {
12441244
// Emit witness tables.
1245-
for (auto c : cast<NominalTypeDecl>(d)->getLocalConformances(
1246-
ConformanceLookupKind::All,
1247-
nullptr, /*sorted=*/true)) {
1245+
auto nom = cast<NominalTypeDecl>(d);
1246+
for (auto c : nom->getLocalConformances(ConformanceLookupKind::All,
1247+
nullptr, /*sorted=*/true)) {
12481248
auto *proto = c->getProtocol();
12491249
if (Lowering::TypeConverter::protocolRequiresWitnessTable(proto) &&
12501250
isa<NormalProtocolConformance>(c) &&
@@ -1606,7 +1606,7 @@ class SILGenConformance : public SILGenWitnessTable<SILGenConformance> {
16061606

16071607
ProtocolConformanceRef conformance(protocol);
16081608
// If the associated type requirement is satisfied by an associated type,
1609-
// these will all be null.
1609+
// these will all be abstract conformances.
16101610
if (witness.getConformances()[0].isConcrete()) {
16111611
auto foundConformance = std::find_if(witness.getConformances().begin(),
16121612
witness.getConformances().end(),
@@ -1616,6 +1616,7 @@ class SILGenConformance : public SILGenWitnessTable<SILGenConformance> {
16161616
assert(foundConformance != witness.getConformances().end());
16171617
conformance = *foundConformance;
16181618
}
1619+
SGM.useConformance(conformance);
16191620

16201621
Entries.push_back(SILWitnessTable::AssociatedTypeProtocolWitness{
16211622
td, protocol, conformance
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@import Foundation;
2+
3+
extern NSErrorDomain const BadErrorDomain;
4+
5+
typedef enum __attribute__((ns_error_domain(BadErrorDomain), swift_name("BadError")))
6+
BadError: NSInteger {
7+
BadBig,
8+
BadSmall,
9+
} BadError;
10+
11+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -emit-silgen -import-objc-header %S/Inputs/external-associated-type-conformance.h %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
extension BadError: LocalizedError {}
5+
6+
// -- The _BridgedStoredNSError conformance...
7+
// CHECK-LABEL: sil_witness_table shared [fragile] BadError: _BridgedStoredNSError module __ObjC {
8+
// -- uses the `Code` type's _ErrorCodeProtocol conformance...
9+
// CHECK: associated_type_protocol (Code: _ErrorCodeProtocol): BadError.Code: _ErrorCodeProtocol module __ObjC
10+
// CHECK: }
11+
// -- so we have to emit that too
12+
// CHECK-LABEL: sil_witness_table shared [fragile] BadError.Code: _ErrorCodeProtocol module __ObjC

0 commit comments

Comments
 (0)