Skip to content

Commit ee440f3

Browse files
committed
AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity considerably over the years, and it seems to be nothing but a source of crashes in practice. I don't want to deal with it anymore, so I've decided to just subsume all usages with LookUpConformanceInModule instead.
1 parent a4ad806 commit ee440f3

18 files changed

+27
-86
lines changed

include/swift/AST/Type.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,6 @@ class LookUpConformanceInModule {
105105
Type dependentType,
106106
ProtocolDecl *proto) const;
107107
};
108-
109-
/// Functor class suitable for use as a \c LookupConformanceFn that provides
110-
/// only abstract conformances for generic types. Asserts that the replacement
111-
/// type is an opaque generic type.
112-
class MakeAbstractConformanceForGenericType {
113-
public:
114-
ProtocolConformanceRef operator()(InFlightSubstitution &IFS,
115-
Type dependentType,
116-
ProtocolDecl *proto) const;
117-
};
118108

119109
/// Flags that can be passed when substituting into a type.
120110
enum class SubstFlags {

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6889,15 +6889,8 @@ CanSILBoxType SILBoxType::get(CanType boxedType) {
68896889
/*mutable*/ true),
68906890
/*captures generic env*/ false);
68916891

6892-
auto subMap =
6893-
SubstitutionMap::get(
6894-
singleGenericParamSignature,
6895-
[&](SubstitutableType *type) -> Type {
6896-
if (type->isEqual(genericParam)) return boxedType;
6897-
6898-
return nullptr;
6899-
},
6900-
MakeAbstractConformanceForGenericType());
6892+
auto subMap = SubstitutionMap::get(singleGenericParamSignature, boxedType,
6893+
LookUpConformanceInModule());
69016894
return get(boxedType->getASTContext(), layout, subMap);
69026895
}
69036896

lib/AST/GenericEnvironment.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ Type MapTypeOutOfContext::operator()(SubstitutableType *type) const {
353353
Type TypeBase::mapTypeOutOfContext() {
354354
assert(!hasTypeParameter() && "already have an interface type");
355355
return Type(this).subst(MapTypeOutOfContext(),
356-
MakeAbstractConformanceForGenericType(),
357-
SubstFlags::PreservePackExpansionLevel |
358-
SubstFlags::SubstitutePrimaryArchetypes);
356+
LookUpConformanceInModule(),
357+
SubstFlags::PreservePackExpansionLevel |
358+
SubstFlags::SubstitutePrimaryArchetypes);
359359
}
360360

361361
auto GenericEnvironment::getOrCreateNestedTypeStorage() -> NestedTypeStorage & {
@@ -684,7 +684,7 @@ GenericEnvironment::mapElementTypeIntoPackContext(Type type) const {
684684

685685
return archetype->getInterfaceType();
686686
},
687-
MakeAbstractConformanceForGenericType(),
687+
LookUpConformanceInModule(),
688688
SubstFlags::PreservePackExpansionLevel |
689689
SubstFlags::SubstitutePrimaryArchetypes |
690690
SubstFlags::SubstituteLocalArchetypes);
@@ -754,7 +754,7 @@ GenericEnvironment::getForwardingSubstitutionMap() const {
754754
auto genericSig = getGenericSignature();
755755
return SubstitutionMap::get(genericSig,
756756
BuildForwardingSubstitutions(this),
757-
MakeAbstractConformanceForGenericType());
757+
LookUpConformanceInModule());
758758
}
759759

760760
OpenedElementContext

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ SubstitutionMap GenericSignatureImpl::getIdentitySubstitutionMap() const {
641641
return param;
642642
return PackType::getSingletonPackExpansion(param);
643643
},
644-
MakeAbstractConformanceForGenericType());
644+
LookUpConformanceInModule());
645645
}
646646

647647
GenericTypeParamType *GenericSignatureImpl::getSugaredType(

lib/AST/LocalArchetypeRequirementCollector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Type swift::mapLocalArchetypesOutOfContext(
214214
GenericSignature baseGenericSig,
215215
ArrayRef<GenericEnvironment *> capturedEnvs) {
216216
return type.subst(MapLocalArchetypesOutOfContext(baseGenericSig, capturedEnvs),
217-
MakeAbstractConformanceForGenericType(),
217+
LookUpConformanceInModule(),
218218
SubstFlags::PreservePackExpansionLevel |
219219
SubstFlags::SubstitutePrimaryArchetypes |
220220
SubstFlags::SubstituteLocalArchetypes);

lib/AST/ProtocolConformanceRef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ ProtocolConformanceRef ProtocolConformanceRef::mapConformanceOutOfContext() cons
118118
if (isConcrete()) {
119119
return getConcrete()->subst(
120120
MapTypeOutOfContext(),
121-
MakeAbstractConformanceForGenericType(),
121+
LookUpConformanceInModule(),
122122
SubstFlags::PreservePackExpansionLevel |
123123
SubstFlags::SubstitutePrimaryArchetypes);
124124
} else if (isPack()) {
125125
return getPack()->subst(
126126
MapTypeOutOfContext(),
127-
MakeAbstractConformanceForGenericType(),
127+
LookUpConformanceInModule(),
128128
SubstFlags::PreservePackExpansionLevel |
129129
SubstFlags::SubstitutePrimaryArchetypes);
130130
} else if (isAbstract()) {

lib/AST/RequirementEnvironment.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "swift/AST/RequirementEnvironment.h"
1919
#include "swift/AST/ASTContext.h"
20+
#include "swift/AST/ConformanceLookup.h"
2021
#include "swift/AST/Decl.h"
2122
#include "swift/AST/DeclContext.h"
2223
#include "swift/AST/GenericEnvironment.h"
@@ -70,7 +71,7 @@ RequirementEnvironment::RequirementEnvironment(
7071
return t;
7172
};
7273
auto conformanceToWitnessThunkConformanceFn =
73-
MakeAbstractConformanceForGenericType();
74+
LookUpConformanceInModule();
7475

7576
auto substConcreteType = concreteType.subst(
7677
conformanceToWitnessThunkTypeFn,
@@ -140,7 +141,7 @@ RequirementEnvironment::RequirementEnvironment(
140141

141142
// All other generic parameters come from the requirement itself
142143
// and conform abstractly.
143-
return MakeAbstractConformanceForGenericType()(IFS, type, proto);
144+
return lookupConformance(type.subst(IFS), proto);
144145
});
145146

146147
// If the requirement itself is non-generic, the witness thunk signature

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ AbstractGenericSignatureRequest::evaluate(
629629
}
630630
return Type(type);
631631
},
632-
MakeAbstractConformanceForGenericType(),
632+
LookUpConformanceInModule(),
633633
SubstFlags::PreservePackExpansionLevel);
634634
resugaredRequirements.push_back(resugaredReq);
635635
}

lib/AST/SubstitutionMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
304304

305305
SubstitutionMap SubstitutionMap::mapReplacementTypesOutOfContext() const {
306306
return subst(MapTypeOutOfContext(),
307-
MakeAbstractConformanceForGenericType(),
307+
LookUpConformanceInModule(),
308308
SubstFlags::PreservePackExpansionLevel |
309309
SubstFlags::SubstitutePrimaryArchetypes);
310310
}

lib/AST/TypeSubstitution.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -120,47 +120,6 @@ operator()(InFlightSubstitution &IFS, Type dependentType,
120120
return ProtocolConformanceRef::forInvalid();
121121
}
122122

123-
ProtocolConformanceRef MakeAbstractConformanceForGenericType::
124-
operator()(InFlightSubstitution &IFS, Type dependentType,
125-
ProtocolDecl *conformedProtocol) const {
126-
auto getConformance = [&](Type conformingReplacementType) {
127-
if (conformingReplacementType->is<ErrorType>())
128-
return ProtocolConformanceRef::forInvalid();
129-
130-
// A class-constrained archetype might conform to the protocol
131-
// concretely.
132-
if (auto *archetypeType = conformingReplacementType->getAs<ArchetypeType>()) {
133-
if (archetypeType->getSuperclass()) {
134-
return lookupConformance(archetypeType, conformedProtocol);
135-
}
136-
}
137-
138-
return ProtocolConformanceRef::forAbstract(
139-
conformingReplacementType, conformedProtocol);
140-
};
141-
142-
// FIXME: Don't recompute this every time.
143-
auto conformingReplacementType = dependentType.subst(IFS);
144-
145-
// The places that use this can also produce conformance packs, generally
146-
// just for singleton pack expansions.
147-
if (auto conformingPack = conformingReplacementType->getAs<PackType>()) {
148-
SmallVector<ProtocolConformanceRef, 4> conformances;
149-
for (auto conformingPackElt : conformingPack->getElementTypes()) {
150-
// Look through pack expansions; there's no equivalent conformance
151-
// expansion right now.
152-
if (auto expansion = conformingPackElt->getAs<PackExpansionType>())
153-
conformingPackElt = expansion->getPatternType();
154-
155-
conformances.push_back(getConformance(conformingPackElt));
156-
}
157-
return ProtocolConformanceRef(
158-
PackConformance::get(conformingPack, conformedProtocol, conformances));
159-
}
160-
161-
return getConformance(conformingReplacementType);
162-
}
163-
164123
InFlightSubstitution::InFlightSubstitution(TypeSubstitutionFn substType,
165124
LookupConformanceFn lookupConformance,
166125
SubstOptions options)

0 commit comments

Comments
 (0)