Skip to content

Commit ebdd56a

Browse files
committed
[AST] Eliminate the "interface type" from protocol conformances.
We don't need this notion.
1 parent b4e6044 commit ebdd56a

File tree

6 files changed

+20
-32
lines changed

6 files changed

+20
-32
lines changed

include/swift/AST/ProtocolConformance.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,9 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
9494
/// conformance definition.
9595
Type ConformingType;
9696

97-
/// \brief The interface type that conforms to the protocol.
98-
Type ConformingInterfaceType;
99-
10097
protected:
101-
ProtocolConformance(ProtocolConformanceKind kind, Type conformingType,
102-
Type conformingInterfaceType)
103-
: Kind(kind), ConformingType(conformingType),
104-
ConformingInterfaceType(conformingInterfaceType) { }
98+
ProtocolConformance(ProtocolConformanceKind kind, Type conformingType)
99+
: Kind(kind), ConformingType(conformingType) { }
105100

106101
public:
107102
/// Determine the kind of protocol conformance.
@@ -110,9 +105,6 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
110105
/// Get the conforming type.
111106
Type getType() const { return ConformingType; }
112107

113-
/// Get the conforming interface type.
114-
Type getInterfaceType() const { return ConformingInterfaceType; }
115-
116108
/// Get the protocol being conformed to.
117109
ProtocolDecl *getProtocol() const;
118110

@@ -357,9 +349,7 @@ class NormalProtocolConformance : public ProtocolConformance,
357349
NormalProtocolConformance(Type conformingType, ProtocolDecl *protocol,
358350
SourceLoc loc, DeclContext *dc,
359351
ProtocolConformanceState state)
360-
: ProtocolConformance(ProtocolConformanceKind::Normal, conformingType,
361-
// FIXME: interface type should be passed in
362-
dc->getDeclaredInterfaceType()),
352+
: ProtocolConformance(ProtocolConformanceKind::Normal, conformingType),
363353
ProtocolAndState(protocol, state), Loc(loc), ContextAndInvalid(dc, false)
364354
{
365355
}
@@ -369,9 +359,7 @@ class NormalProtocolConformance : public ProtocolConformance,
369359
ProtocolDecl *protocol,
370360
SourceLoc loc, AbstractStorageDecl *behaviorStorage,
371361
ProtocolConformanceState state)
372-
: ProtocolConformance(ProtocolConformanceKind::Normal, conformingType,
373-
// FIXME: interface type should be passed in
374-
conformingInterfaceType),
362+
: ProtocolConformance(ProtocolConformanceKind::Normal, conformingType),
375363
ProtocolAndState(protocol, state), Loc(loc),
376364
ContextAndInvalid(behaviorStorage, false)
377365
{
@@ -640,9 +628,7 @@ class InheritedProtocolConformance : public ProtocolConformance,
640628

641629
InheritedProtocolConformance(Type conformingType,
642630
ProtocolConformance *inheritedConformance)
643-
: ProtocolConformance(ProtocolConformanceKind::Inherited, conformingType,
644-
// FIXME: interface type should be passed in
645-
inheritedConformance->getDeclContext()->getDeclaredInterfaceType()),
631+
: ProtocolConformance(ProtocolConformanceKind::Inherited, conformingType),
646632
InheritedConformance(inheritedConformance)
647633
{
648634
}

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,10 @@ void ASTMangler::appendProtocolConformance(const ProtocolConformance *conformanc
18391839
appendProtocolName(conformance->getProtocol());
18401840
appendIdentifier(behaviorStorage->getName().str());
18411841
} else {
1842-
appendType(conformance->getInterfaceType()->getCanonicalType());
1842+
auto conformanceDC = conformance->getDeclContext();
1843+
auto conformingType =
1844+
conformanceDC->mapTypeOutOfContext(conformance->getType());
1845+
appendType(conformingType->getCanonicalType());
18431846
appendProtocolName(conformance->getProtocol());
18441847
appendModule(conformance->getDeclContext()->getParentModule());
18451848
}

lib/AST/ProtocolConformance.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
266266
bool ProtocolConformance::hasFixedLayout() const {
267267
// A conformance/witness table has fixed layout if type has a fixed layout in
268268
// all resilience domains, and the conformance is externally visible.
269-
if (auto nominal = getInterfaceType()->getAnyNominal())
269+
if (auto nominal = getType()->getAnyNominal())
270270
if (nominal->hasFixedLayout() &&
271271
getProtocol()->getEffectiveAccess() >= Accessibility::Public &&
272272
nominal->getEffectiveAccess() >= Accessibility::Public)
@@ -652,11 +652,7 @@ SpecializedProtocolConformance::SpecializedProtocolConformance(
652652
Type conformingType,
653653
ProtocolConformance *genericConformance,
654654
SubstitutionList substitutions)
655-
: ProtocolConformance(ProtocolConformanceKind::Specialized, conformingType,
656-
// FIXME: interface type should be passed in.
657-
// assumes specialized conformance is always fully
658-
// specialized
659-
conformingType),
655+
: ProtocolConformance(ProtocolConformanceKind::Specialized, conformingType),
660656
GenericConformance(genericConformance),
661657
GenericSubstitutions(substitutions)
662658
{
@@ -1068,8 +1064,6 @@ bool ProtocolConformance::isCanonical() const {
10681064

10691065
if (!getType()->isCanonical())
10701066
return false;
1071-
if (!getInterfaceType()->isCanonical())
1072-
return false;
10731067

10741068
switch (getKind()) {
10751069
case ProtocolConformanceKind::Normal: {

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class AssociatedTypeMetadataBuilder : public ReflectionMetadataBuilder {
283283
void layout() override {
284284
// If the conforming type is generic, we just want to emit the
285285
// unbound generic type here.
286-
auto *Nominal = Conformance->getInterfaceType()->getAnyNominal();
286+
auto *Nominal = Conformance->getType()->getAnyNominal();
287287
assert(Nominal && "Structural conformance?");
288288

289289
PrettyStackTraceDecl DebugStack("emitting associated type metadata",

lib/SILGen/SILGenType.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
608608
genericEnv = witnessRef.getDecl()->getInnermostDeclContext()
609609
->getGenericEnvironmentOfContext();
610610

611-
Type concreteTy = conformance->getInterfaceType();
611+
auto conformanceDC = conformance->getDeclContext();
612+
Type concreteTy =
613+
conformanceDC->mapTypeOutOfContext(conformance->getType());
612614

613615
// FIXME: conformance substitutions should be in terms of interface types
614616
auto specialized = conformance;
@@ -672,7 +674,9 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
672674
// If the witness is a free function, there is no Self type.
673675
if (!isFree) {
674676
if (conformance) {
675-
selfInterfaceType = conformance->getInterfaceType();
677+
auto conformanceDC = conformance->getDeclContext();
678+
selfInterfaceType =
679+
conformanceDC->mapTypeOutOfContext(conformance->getType());
676680
} else {
677681
auto *proto = cast<ProtocolDecl>(requirement.getDecl()->getDeclContext());
678682
selfInterfaceType = proto->getSelfInterfaceType();

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,8 @@ static void checkVarBehavior(VarDecl *decl, TypeChecker &TC) {
31513151

31523152
auto dc = decl->getDeclContext();
31533153
auto behaviorSelf = conformance->getType();
3154-
auto behaviorInterfaceSelf = conformance->getInterfaceType();
3154+
auto behaviorInterfaceSelf =
3155+
conformance->getDeclContext()->mapTypeOutOfContext(behaviorSelf);
31553156
auto behaviorProto = conformance->getProtocol();
31563157
auto behaviorProtoTy = behaviorProto->getDeclaredType();
31573158

0 commit comments

Comments
 (0)