Skip to content

Commit a00157e

Browse files
committed
IRGen: Refactor LocalTypeData a bit
The "abstract conformance is just a ProtocolDecl" assumption is pretty fundamental here, so we have to fudge a bit at the API boundary for now. Eventually, LocalTypeDataKind should just contain a ProtocolConformanceRef instead of duplicating the representation, however this would require fixing various calls to LocalTypeDataKind::forAbstractProtocolWitnessTable() which pass in a ProtocolDecl to pass in a ProtocolConformanceRef instead.
1 parent f7b0b72 commit a00157e

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,8 +3402,7 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
34023402
}
34033403

34043404
case Component::Kind::OutOfLineBaseProtocol: {
3405-
auto conformance = sourceKey.Kind.getProtocolConformance();
3406-
auto protocol = conformance.getRequirement();
3405+
auto protocol = sourceKey.Kind.getConformedProtocol();
34073406
auto &pi = IGF.IGM.getProtocolInfo(protocol,
34083407
ProtocolInfoKind::RequirementSignature);
34093408

@@ -3413,9 +3412,10 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
34133412

34143413
sourceKey.Kind =
34153414
LocalTypeDataKind::forAbstractProtocolWitnessTable(inheritedProtocol);
3416-
if (conformance.isConcrete()) {
3415+
if (sourceKey.Kind.isConcreteProtocolConformance()) {
34173416
auto inheritedConformance =
3418-
conformance.getConcrete()->getInheritedConformance(inheritedProtocol);
3417+
sourceKey.Kind.getConcreteProtocolConformance()
3418+
->getInheritedConformance(inheritedProtocol);
34193419
if (inheritedConformance) {
34203420
sourceKey.Kind = LocalTypeDataKind::forConcreteProtocolWitnessTable(
34213421
inheritedConformance);
@@ -3438,8 +3438,8 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
34383438

34393439
case Component::Kind::AssociatedConformance: {
34403440
auto sourceType = sourceKey.Type;
3441-
auto sourceConformance = sourceKey.Kind.getProtocolConformance();
3442-
auto sourceProtocol = sourceConformance.getRequirement();
3441+
auto sourceConformance = sourceKey.Kind.getProtocolConformance(sourceType);
3442+
auto sourceProtocol = sourceKey.Kind.getConformedProtocol();
34433443
auto &pi = IGF.IGM.getProtocolInfo(sourceProtocol,
34443444
ProtocolInfoKind::RequirementSignature);
34453445

@@ -3473,7 +3473,8 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
34733473
// In Embedded Swift associated-conformance entries simply point to the witness table
34743474
// of the associated conformance.
34753475
llvm::Value *sourceWTable = source.getMetadata();
3476-
llvm::Value *associatedWTable = emitAssociatedConformanceValue(IGF, sourceWTable, associatedConformanceRef);
3476+
llvm::Value *associatedWTable = emitAssociatedConformanceValue(
3477+
IGF, sourceWTable, associatedConformanceRef);
34773478
return MetadataResponse::forComplete(associatedWTable);
34783479
}
34793480

@@ -3562,13 +3563,13 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
35623563
}
35633564

35643565
case Component::Kind::ConditionalConformance: {
3565-
auto sourceConformance = sourceKey.Kind.getProtocolConformance();
3566+
auto sourceConformance = sourceKey.Kind.getConcreteProtocolConformance();
35663567

35673568
auto reqtIndex = component.getPrimaryIndex();
35683569

35693570
ProtocolDecl *conformingProto;
35703571
auto found = SILWitnessTable::enumerateWitnessTableConditionalConformances(
3571-
sourceConformance.getConcrete(),
3572+
sourceConformance,
35723573
[&](unsigned index, CanType type, ProtocolDecl *proto) {
35733574
if (reqtIndex == index) {
35743575
conformingProto = proto;

lib/IRGen/LocalTypeDataKind.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef SWIFT_IRGEN_LOCALTYPEDATAKIND_H
2020
#define SWIFT_IRGEN_LOCALTYPEDATAKIND_H
2121

22+
#include "swift/AST/PackConformance.h"
23+
#include "swift/AST/ProtocolConformance.h"
2224
#include "swift/AST/ProtocolConformanceRef.h"
2325
#include "swift/AST/Type.h"
2426
#include "swift/IRGen/ValueWitness.h"
@@ -183,13 +185,23 @@ class LocalTypeDataKind {
183185
return reinterpret_cast<PackConformance*>(Value - Kind_PackConformance);
184186
}
185187

186-
ProtocolConformanceRef getProtocolConformance() const {
188+
ProtocolDecl *getConformedProtocol() const {
189+
assert(!isSingletonKind());
190+
if ((Value & KindMask) == Kind_Decl) {
191+
return getAbstractProtocolConformance();
192+
} else if ((Value & KindMask) == Kind_PackConformance) {
193+
return getPackProtocolConformance()->getProtocol();
194+
} else {
195+
assert((Value & KindMask) == Kind_Conformance);
196+
return getConcreteProtocolConformance()->getProtocol();
197+
}
198+
}
199+
200+
ProtocolConformanceRef getProtocolConformance(Type conformingType) const {
187201
assert(!isSingletonKind());
188202
if ((Value & KindMask) == Kind_Decl) {
189-
// FIXME: Passing an empty Type() here temporarily while staging in
190-
// new representation for abstract conformances
191203
return ProtocolConformanceRef::forAbstract(
192-
Type(), getAbstractProtocolConformance());
204+
conformingType, getAbstractProtocolConformance());
193205
} else if ((Value & KindMask) == Kind_PackConformance) {
194206
return ProtocolConformanceRef(getPackProtocolConformance());
195207
} else {

0 commit comments

Comments
 (0)