Skip to content

Commit e226c20

Browse files
authored
Merge pull request #14965 from xedin/potential-archetype-only-assoc
[GSB] Eliminate concrete potential archetypes by early substitution
2 parents 347ff6a + 4b05449 commit e226c20

File tree

5 files changed

+124
-200
lines changed

5 files changed

+124
-200
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,17 +1508,13 @@ class GenericSignatureBuilder::PotentialArchetype {
15081508
///
15091509
/// \c parentOrBuilder determines whether we have a nested type vs. a root.
15101510
union PAIdentifier {
1511-
/// The associated type or typealias for a resolved nested type.
1512-
TypeDecl *assocTypeOrConcrete;
1511+
/// The associated type for a resolved nested type.
1512+
AssociatedTypeDecl *assocType;
15131513

15141514
/// The generic parameter key for a root.
15151515
GenericParamKey genericParam;
15161516

1517-
PAIdentifier(AssociatedTypeDecl *assocType)
1518-
: assocTypeOrConcrete(assocType) { }
1519-
1520-
PAIdentifier(TypeDecl *concreteDecl)
1521-
: assocTypeOrConcrete(concreteDecl) { }
1517+
PAIdentifier(AssociatedTypeDecl *assocType) : assocType(assocType) {}
15221518

15231519
PAIdentifier(GenericParamKey genericParam) : genericParam(genericParam) { }
15241520
} identifier;
@@ -1562,17 +1558,11 @@ class GenericSignatureBuilder::PotentialArchetype {
15621558
/// that share a name.
15631559
llvm::MapVector<Identifier, StoredNestedType> NestedTypes;
15641560

1565-
/// \brief Construct a new potential archetype for an unresolved
1566-
/// associated type.
1567-
PotentialArchetype(PotentialArchetype *parent, Identifier name);
1568-
15691561
/// \brief Construct a new potential archetype for a concrete declaration.
1570-
PotentialArchetype(PotentialArchetype *parent, TypeDecl *concreteDecl)
1571-
: parentOrContext(parent), identifier(concreteDecl)
1572-
{
1562+
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType)
1563+
: parentOrContext(parent), identifier(assocType) {
15731564
assert(parent != nullptr && "Not a nested type?");
1574-
assert(!isa<AssociatedTypeDecl>(concreteDecl) ||
1575-
cast<AssociatedTypeDecl>(concreteDecl)->getOverriddenDecls().empty());
1565+
assert(assocType->getOverriddenDecls().empty());
15761566
}
15771567

15781568
/// \brief Construct a new potential archetype for a generic parameter.
@@ -1602,16 +1592,9 @@ class GenericSignatureBuilder::PotentialArchetype {
16021592
}
16031593

16041594
/// Retrieve the type declaration to which this nested type was resolved.
1605-
TypeDecl *getResolvedType() const {
1606-
assert(getParent() && "Not an associated type");
1607-
return identifier.assocTypeOrConcrete;
1608-
}
1609-
1610-
/// Retrieve the associated type to which this potential archetype
1611-
/// has been resolved.
1612-
AssociatedTypeDecl *getResolvedAssociatedType() const {
1595+
AssociatedTypeDecl *getResolvedType() const {
16131596
assert(getParent() && "Not an associated type");
1614-
return dyn_cast<AssociatedTypeDecl>(identifier.assocTypeOrConcrete);
1597+
return identifier.assocType;
16151598
}
16161599

16171600
/// Determine whether this is a generic parameter.
@@ -1640,16 +1623,7 @@ class GenericSignatureBuilder::PotentialArchetype {
16401623
/// Retrieve the name of a nested potential archetype.
16411624
Identifier getNestedName() const {
16421625
assert(getParent() && "Not a nested type");
1643-
return identifier.assocTypeOrConcrete->getName();
1644-
}
1645-
1646-
/// Retrieve the concrete type declaration.
1647-
TypeDecl *getConcreteTypeDecl() const {
1648-
assert(getParent() && "not a nested type");
1649-
if (isa<AssociatedTypeDecl>(identifier.assocTypeOrConcrete))
1650-
return nullptr;
1651-
1652-
return identifier.assocTypeOrConcrete;
1626+
return identifier.assocType->getName();
16531627
}
16541628

16551629
/// Retrieve the set of nested types.
@@ -1692,12 +1666,12 @@ class GenericSignatureBuilder::PotentialArchetype {
16921666
/// protocol.
16931667
///
16941668
/// \returns the potential archetype associated with the associated
1695-
/// type or typealias of the given protocol, unless the \c kind implies that
1669+
/// type of the given protocol, unless the \c kind implies that
16961670
/// a potential archetype should not be created if it's missing.
1697-
PotentialArchetype *updateNestedTypeForConformance(
1698-
GenericSignatureBuilder &builder,
1699-
TypeDecl *type,
1700-
ArchetypeResolutionKind kind);
1671+
PotentialArchetype *
1672+
updateNestedTypeForConformance(GenericSignatureBuilder &builder,
1673+
AssociatedTypeDecl *assocType,
1674+
ArchetypeResolutionKind kind);
17011675

17021676
/// Retrieve the dependent type that describes this potential
17031677
/// archetype.

0 commit comments

Comments
 (0)