Skip to content

Commit 9552692

Browse files
committed
[GSB] Eliminate equivalence-class lookup from type canonicalization.
Make GenericSignatureBuilder::getCanonicalTypeParameter() independent of equivalence classes. This is primarily cleanup, because all of these equivalence-class resolution calls were actually dead from the point where we changed the key for the rewrite-roots DenseMap over to dependent types.
1 parent 0eedacf commit 9552692

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ struct GenericSignatureBuilder::Implementation {
437437
/// Equivalence classes that are not currently being used.
438438
std::vector<void *> FreeEquivalenceClasses;
439439

440-
/// The roots of the rewrite tree, keyed on the canonical types of the
441-
/// anchors.
440+
/// The roots of the rewrite tree, keyed on the canonical, dependent
441+
/// types.
442442
DenseMap<CanType, std::unique_ptr<RewriteTreeNode>> RewriteTreeRoots;
443443

444444
/// The generation number for the term-rewriting system, which is
@@ -2291,7 +2291,7 @@ Type EquivalenceClass::getAnchor(
22912291
for (auto member : members) {
22922292
auto anchorType =
22932293
builder.getCanonicalTypeParameter(
2294-
member->getDependentType(genericParams));
2294+
member->getDependentType(genericParams));
22952295

22962296
#ifndef NDEBUG
22972297
// Check that we get consistent results from all of the anchors.
@@ -3740,13 +3740,8 @@ Type GenericSignatureBuilder::getCanonicalTypeParameter(Type type) {
37403740
GenericTypeParamType::get(initialPath.getBase()->Depth,
37413741
initialPath.getBase()->Index,
37423742
getASTContext());
3743-
auto initialEquivClass =
3744-
resolveEquivalenceClass(genericParamType,
3745-
ArchetypeResolutionKind::WellFormed);
3746-
if (!initialEquivClass) return nullptr;
37473743

37483744
unsigned startIndex = 0;
3749-
auto equivClass = initialEquivClass;
37503745
Type currentType = genericParamType;
37513746
SmallVector<AssociatedTypeDecl *, 4> path(initialPath.getPath().begin(),
37523747
initialPath.getPath().end());
@@ -3783,30 +3778,20 @@ Type GenericSignatureBuilder::getCanonicalTypeParameter(Type type) {
37833778
genericParamType =
37843779
GenericTypeParamType::get(newBase->Depth, newBase->Index,
37853780
getASTContext());
3786-
initialEquivClass =
3787-
resolveEquivalenceClass(genericParamType,
3788-
ArchetypeResolutionKind::WellFormed);
3789-
assert(initialEquivClass && "Must have an equivalence class");
37903781
}
37913782

37923783
// Move back to the beginning; we may have opened up other rewrites.
37933784
simplified = true;
37943785
startIndex = 0;
37953786
currentType = genericParamType;
3796-
equivClass = initialEquivClass;
37973787
continue;
37983788
}
37993789
}
38003790

38013791
// If we've hit the end of the path, we're done.
38023792
if (startIndex >= path.size()) break;
38033793

3804-
// FIXME: It would be nice if there were a better way to get the equivalence
3805-
// class of a named nested type.
38063794
currentType = DependentMemberType::get(currentType, path[startIndex++]);
3807-
equivClass =
3808-
resolveEquivalenceClass(currentType, ArchetypeResolutionKind::WellFormed);
3809-
if (!equivClass) break;
38103795
} while (true);
38113796

38123797
return formDependentType(genericParamType, path);
@@ -4914,21 +4899,21 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
49144899
equivClass->sameTypeConstraints.end(),
49154900
equivClass2->sameTypeConstraints.begin(),
49164901
equivClass2->sameTypeConstraints.end());
4902+
}
49174903

4918-
// Combine the rewrite rules.
4919-
if (auto rewriteRoot2 = Impl->getOrCreateRewriteTreeRoot(anchor2)) {
4920-
if (auto rewriteRoot1 = Impl->getOrCreateRewriteTreeRoot(anchor1)) {
4921-
// Merge the second rewrite tree into the first.
4922-
if (rewriteRoot2->mergeInto(rewriteRoot1))
4923-
++Impl->RewriteGeneration;
4924-
Impl->RewriteTreeRoots.erase(anchor2);
4925-
} else {
4926-
// Take the second rewrite tree and make it the first.
4927-
auto root2Entry = Impl->RewriteTreeRoots.find(anchor2);
4928-
auto root2Ptr = std::move(root2Entry->second);
4929-
Impl->RewriteTreeRoots.erase(root2Entry);
4930-
(void)Impl->RewriteTreeRoots.insert({anchor1, std::move(root2Ptr)});
4931-
}
4904+
// Combine the rewrite rules.
4905+
if (auto rewriteRoot2 = Impl->getOrCreateRewriteTreeRoot(anchor2)) {
4906+
if (auto rewriteRoot1 = Impl->getOrCreateRewriteTreeRoot(anchor1)) {
4907+
// Merge the second rewrite tree into the first.
4908+
if (rewriteRoot2->mergeInto(rewriteRoot1))
4909+
++Impl->RewriteGeneration;
4910+
Impl->RewriteTreeRoots.erase(anchor2);
4911+
} else {
4912+
// Take the second rewrite tree and make it the first.
4913+
auto root2Entry = Impl->RewriteTreeRoots.find(anchor2);
4914+
auto root2Ptr = std::move(root2Entry->second);
4915+
Impl->RewriteTreeRoots.erase(root2Entry);
4916+
(void)Impl->RewriteTreeRoots.insert({anchor1, std::move(root2Ptr)});
49324917
}
49334918
}
49344919

0 commit comments

Comments
 (0)