Skip to content

Commit 75cb941

Browse files
committed
[Constraint System] Kill the ArchetypeOpener; bind type variables instead. NFC
The ArchetypeOpener was used only to replace dependent types with archetypes (or concrete types) within the opening context. We can do the same simply by letting the constraint system create type variables and then binding those type variables to the appropriate archetypes/concrete types in that context. Eliminate the two DependentTypeOpener entry points that were only used by the ArchetypeOpener.
1 parent 168c8f0 commit 75cb941

File tree

3 files changed

+10
-54
lines changed

3 files changed

+10
-54
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,6 @@ static Comparison compareWitnessAndRequirement(TypeChecker &tc, DeclContext *dc,
226226
return proto1? Comparison::Worse : Comparison::Better;
227227
}
228228

229-
namespace {
230-
/// Dependent type opener that maps from a dependent type to its corresponding
231-
/// archetype in the given context.
232-
class ArchetypeOpener : public constraints::DependentTypeOpener {
233-
DeclContext *DC;
234-
235-
public:
236-
explicit ArchetypeOpener(DeclContext *dc) : DC(dc) { }
237-
238-
virtual Type mapGenericTypeParamType(GenericTypeParamType *param) {
239-
return ArchetypeBuilder::mapTypeIntoContext(DC, param);
240-
}
241-
242-
virtual Type mapDependentMemberType(DependentMemberType *memberType) {
243-
return ArchetypeBuilder::mapTypeIntoContext(DC, memberType);
244-
}
245-
};
246-
}
247-
248229
namespace {
249230
/// Describes the relationship between the context types for two declarations.
250231
enum class SelfTypeRelationship {
@@ -596,10 +577,16 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
596577

597578
// Get the type of a reference to the first declaration, swapping in
598579
// archetypes for the dependent types.
599-
ArchetypeOpener opener(decl1->getInnermostDeclContext());
600-
Type openedType1 = cs.openType(type1, locator,
601-
decl1->getInnermostDeclContext(),
602-
&opener);
580+
llvm::DenseMap<CanType, TypeVariableType *> replacements;
581+
auto dc1 = decl1->getInnermostDeclContext();
582+
Type openedType1 = cs.openType(type1, locator, replacements, dc1);
583+
for (const auto &replacement : replacements) {
584+
if (auto mapped = ArchetypeBuilder::mapTypeIntoContext(dc1,
585+
replacement.first)) {
586+
cs.addConstraint(ConstraintKind::Bind, replacement.second, mapped,
587+
locator);
588+
}
589+
}
603590

604591
// Extract the self types from the declarations, if they have them.
605592
Type selfTy1;

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,6 @@ namespace {
570570

571571
// Replace a generic type parameter with its corresponding type variable.
572572
if (auto genericParam = type->getAs<GenericTypeParamType>()) {
573-
if (opener) {
574-
// If we have a mapping for this type parameter, there's nothing else to do.
575-
if (Type replacement = opener->mapGenericTypeParamType(genericParam)){
576-
return replacement;
577-
}
578-
}
579-
580573
auto known = replacements.find(genericParam->getCanonicalType());
581574

582575
if (known == replacements.end())
@@ -588,14 +581,6 @@ namespace {
588581
// Replace a dependent member with a fresh type variable and make it a
589582
// member of its base type.
590583
if (auto dependentMember = type->getAs<DependentMemberType>()) {
591-
if (opener) {
592-
// If we have a mapping for this type parameter, there's nothing else to do.
593-
if (Type replacement
594-
= opener->mapDependentMemberType(dependentMember)) {
595-
return replacement;
596-
}
597-
}
598-
599584
// Check whether we've already dealt with this dependent member.
600585
auto known = replacements.find(dependentMember->getCanonicalType());
601586
if (known != replacements.end())
@@ -940,10 +925,6 @@ void ConstraintSystem::openGeneric(
940925

941926
// Create the type variables for the generic parameters.
942927
for (auto gp : params) {
943-
// If we have a mapping for this type parameter, there's nothing else to do.
944-
if (opener && opener->mapGenericTypeParamType(gp))
945-
continue;
946-
947928
ArchetypeType *archetype = ArchetypeBuilder::mapTypeIntoContext(dc, gp)
948929
->castTo<ArchetypeType>();
949930
auto typeVar = createTypeVariable(getConstraintLocator(

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -979,18 +979,6 @@ class DependentTypeOpener {
979979
public:
980980
virtual ~DependentTypeOpener() { }
981981

982-
/// Directly map a generic type parameter to a type, or return null if
983-
/// the type parameter should be opened.
984-
virtual Type mapGenericTypeParamType(GenericTypeParamType *param) {
985-
return Type();
986-
}
987-
988-
/// Directly map a dependent member type to a type, or return null if
989-
/// the dependent member type should be opened.
990-
virtual Type mapDependentMemberType(DependentMemberType *memberType) {
991-
return Type();
992-
}
993-
994982
/// Invoked when a generic type parameter is opened to a type variable.
995983
///
996984
/// \param param The generic type parameter.

0 commit comments

Comments
 (0)