[GSB] Only build potential archetypes for associated type "anchors".

Use the "override" information in associated type declarations to provide
AST-level access to the associated type "anchor", i.e., the canonical
associated type that will be used in generic signatures, mangling,
etc.

In the Generic Signature Builder, only build potential archetypes for
associated types that are anchors, which reduces the number of
potential archetypes we build when type-checking the standard library
by 14% and type-checking time for the standard library by 16%.

There's a minor regression here in some generic signatures that were
accidentally getting (correct) same-type constraints. There were
existing bugs in this area already (Huon found some of them), while
will be addressed as a follow-up.

Fies SR-5726, where we were failing to type-check due to missed
associated type constraints.
This commit is contained in:
Doug Gregor
2017-10-06 16:23:44 -07:00
parent 15386fa0bf
commit ea1396c364
9 changed files with 79 additions and 22 deletions

View File

@@ -2625,6 +2625,24 @@ SourceRange AssociatedTypeDecl::getSourceRange() const {
return SourceRange(KeywordLoc, endLoc);
}
AssociatedTypeDecl *AssociatedTypeDecl::getAssociatedTypeAnchor() const {
auto overridden = getOverriddenDecls();
// If this declaration does not override any other declarations, it's
// the anchor.
if (overridden.empty()) return const_cast<AssociatedTypeDecl *>(this);
// Find the best anchor among the anchors of the overridden decls.
AssociatedTypeDecl *bestAnchor = nullptr;
for (auto assocType : overridden) {
auto anchor = assocType->getAssociatedTypeAnchor();
if (!bestAnchor || compare(anchor, bestAnchor) < 0)
bestAnchor = anchor;
}
return bestAnchor;
}
AssociatedTypeDecl *AssociatedTypeDecl::getOverriddenDecl() const {
auto overridden = getOverriddenDecls();
return overridden.empty() ? nullptr : overridden.front();