Skip to content

Commit 5cec731

Browse files
committed
GSB: DerivedSameTypeComponent can store a Type instead of a PotentialArchetype *
1 parent 3c0104d commit 5cec731

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ class GenericSignatureBuilder {
160160
/// Describes a component within the graph of same-type constraints within
161161
/// the equivalence class that is held together by derived constraints.
162162
struct DerivedSameTypeComponent {
163-
/// The potential archetype that acts as the anchor for this component.
164-
UnresolvedType anchor;
163+
/// The type that acts as the anchor for this component.
164+
Type type;
165165

166166
/// The (best) requirement source within the component that makes the
167167
/// potential archetypes in this component equivalent to the concrete

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ namespace {
6969
typedef EquivalenceClass::DerivedSameTypeComponent DerivedSameTypeComponent;
7070
typedef GenericSignatureBuilder::DelayedRequirement DelayedRequirement;
7171
typedef GenericSignatureBuilder::ResolvedType ResolvedType;
72-
typedef GenericSignatureBuilder::UnresolvedType GSBUnresolvedType;
7372
typedef GenericSignatureBuilder::RequirementRHS RequirementRHS;
7473
} // end anonymous namespace
7574

@@ -547,20 +546,6 @@ void GenericSignatureBuilder::Implementation::deallocateEquivalenceClass(
547546
++NumEquivalenceClassesFreed;
548547
}
549548

550-
namespace {
551-
/// Retrieve the type described by the given unresolved tyoe.
552-
Type getUnresolvedType(GSBUnresolvedType type,
553-
TypeArrayView<GenericTypeParamType> genericParams) {
554-
if (auto concrete = type.dyn_cast<Type>())
555-
return concrete;
556-
557-
if (auto pa = type.dyn_cast<PotentialArchetype *>())
558-
return pa->getDependentType(genericParams);
559-
560-
return Type();
561-
}
562-
}
563-
564549
#pragma mark Requirement sources
565550

566551
#ifndef NDEBUG
@@ -6006,8 +5991,7 @@ void GenericSignatureBuilder::checkConformanceConstraints(
60065991
namespace swift {
60075992
bool operator<(const DerivedSameTypeComponent &lhs,
60085993
const DerivedSameTypeComponent &rhs) {
6009-
return compareDependentTypes(getUnresolvedType(lhs.anchor, {}),
6010-
getUnresolvedType(rhs.anchor, {})) < 0;
5994+
return compareDependentTypes(lhs.type, rhs.type) < 0;
60115995
}
60125996
} // namespace swift
60135997

@@ -6117,17 +6101,18 @@ static void computeDerivedSameTypeComponents(
61176101
auto &components = equivClass->derivedSameTypeComponents;
61186102
for (unsigned i : indices(equivClass->members)) {
61196103
auto pa = equivClass->members[i];
6120-
CanType depType = pa->getDependentType({ })->getCanonicalType();
6104+
auto depType = pa->getDependentType(builder.getGenericParams());
6105+
CanType canType = depType->getCanonicalType();
61216106

61226107
// Find the representative of this set.
6123-
assert(parentIndices.count(depType) == 1 && "Unknown member?");
6124-
unsigned index = parentIndices[depType];
6108+
assert(parentIndices.count(canType) == 1 && "Unknown member?");
6109+
unsigned index = parentIndices[canType];
61256110
unsigned representative = findRepresentative(parents, index);
61266111

61276112
// If this is the representative, add a component for it.
61286113
if (representative == index) {
6129-
componentOf[depType] = components.size();
6130-
components.push_back(DerivedSameTypeComponent{pa, nullptr});
6114+
componentOf[canType] = components.size();
6115+
components.push_back(DerivedSameTypeComponent{depType, nullptr});
61316116
continue;
61326117
}
61336118

@@ -6139,13 +6124,12 @@ static void computeDerivedSameTypeComponents(
61396124
assert(componentOf.count(representativeDepTy) == 1 &&
61406125
"Missing representative component?");
61416126
unsigned componentIndex = componentOf[representativeDepTy];
6142-
componentOf[depType] = componentIndex;
6127+
componentOf[canType] = componentIndex;
61436128

61446129
// If this is a better anchor, record it.
6145-
if (compareDependentTypes(
6146-
depType, getUnresolvedType(components[componentIndex].anchor, {})) <
6147-
0)
6148-
components[componentIndex].anchor = pa;
6130+
if (compareDependentTypes(depType, components[componentIndex].type) < 0) {
6131+
components[componentIndex].type = depType;
6132+
}
61496133
}
61506134

61516135
// If there is a concrete type, figure out the best concrete type anchor
@@ -6459,7 +6443,7 @@ static void collapseSameTypeComponents(
64596443
unsigned newIndex = newComponents.size();
64606444
newIndices[oldIndex] = newIndex;
64616445
newComponents.push_back(
6462-
{oldComponent.anchor, oldComponent.concreteTypeSource});
6446+
{oldComponent.type, oldComponent.concreteTypeSource});
64636447
continue;
64646448
}
64656449

@@ -6471,9 +6455,9 @@ static void collapseSameTypeComponents(
64716455
auto &newComponent = newComponents[newRepresentativeIndex];
64726456

64736457
// If the old component has a better anchor, keep it.
6474-
if (compareDependentTypes(getUnresolvedType(oldComponent.anchor, {}),
6475-
getUnresolvedType(newComponent.anchor, {})) < 0)
6476-
newComponent.anchor = oldComponent.anchor;
6458+
if (compareDependentTypes(oldComponent.type, newComponent.type) < 0) {
6459+
newComponent.type = oldComponent.type;
6460+
}
64776461

64786462
// If the old component has a better concrete type source, keep it.
64796463
if (!newComponent.concreteTypeSource ||
@@ -6957,12 +6941,8 @@ namespace {
69576941

69586942
static int compareSameTypeComponents(const SameTypeComponentRef *lhsPtr,
69596943
const SameTypeComponentRef *rhsPtr){
6960-
Type lhsType = getUnresolvedType(
6961-
lhsPtr->first->derivedSameTypeComponents[lhsPtr->second].anchor,
6962-
{ });
6963-
Type rhsType = getUnresolvedType(
6964-
rhsPtr->first->derivedSameTypeComponents[rhsPtr->second].anchor,
6965-
{ });
6944+
Type lhsType = lhsPtr->first->derivedSameTypeComponents[lhsPtr->second].type;
6945+
Type rhsType = rhsPtr->first->derivedSameTypeComponents[rhsPtr->second].type;
69666946

69676947
return compareDependentTypes(lhsType, rhsType);
69686948
}
@@ -6993,7 +6973,7 @@ void GenericSignatureBuilder::enumerateRequirements(
69936973
// Dig out the subject type and its corresponding component.
69946974
auto equivClass = subject.first;
69956975
auto &component = equivClass->derivedSameTypeComponents[subject.second];
6996-
Type subjectType = getUnresolvedType(component.anchor, genericParams);
6976+
Type subjectType = component.type;
69976977

69986978
// If this equivalence class is bound to a concrete type, equate the
69996979
// anchor with a concrete type.
@@ -7031,8 +7011,7 @@ void GenericSignatureBuilder::enumerateRequirements(
70317011
// FIXME: Distinguish between explicit and inferred here?
70327012
auto &nextComponent =
70337013
equivClass->derivedSameTypeComponents[subject.second + 1];
7034-
Type otherSubjectType =
7035-
getUnresolvedType(nextComponent.anchor, genericParams);
7014+
Type otherSubjectType = nextComponent.type;
70367015
deferredSameTypeRequirement =
70377016
[&f, subjectType, otherSubjectType, this] {
70387017
f(RequirementKind::SameType, subjectType, otherSubjectType,

0 commit comments

Comments
 (0)