Skip to content

[GSB] Eliminate concrete potential archetypes by early substitution #14965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 14 additions & 40 deletions include/swift/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1508,17 +1508,13 @@ class GenericSignatureBuilder::PotentialArchetype {
///
/// \c parentOrBuilder determines whether we have a nested type vs. a root.
union PAIdentifier {
/// The associated type or typealias for a resolved nested type.
TypeDecl *assocTypeOrConcrete;
/// The associated type for a resolved nested type.
AssociatedTypeDecl *assocType;

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

PAIdentifier(AssociatedTypeDecl *assocType)
: assocTypeOrConcrete(assocType) { }

PAIdentifier(TypeDecl *concreteDecl)
: assocTypeOrConcrete(concreteDecl) { }
PAIdentifier(AssociatedTypeDecl *assocType) : assocType(assocType) {}

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

/// \brief Construct a new potential archetype for an unresolved
/// associated type.
PotentialArchetype(PotentialArchetype *parent, Identifier name);

/// \brief Construct a new potential archetype for a concrete declaration.
PotentialArchetype(PotentialArchetype *parent, TypeDecl *concreteDecl)
: parentOrContext(parent), identifier(concreteDecl)
{
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType)
: parentOrContext(parent), identifier(assocType) {
assert(parent != nullptr && "Not a nested type?");
assert(!isa<AssociatedTypeDecl>(concreteDecl) ||
cast<AssociatedTypeDecl>(concreteDecl)->getOverriddenDecls().empty());
assert(assocType->getOverriddenDecls().empty());
}

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

/// Retrieve the type declaration to which this nested type was resolved.
TypeDecl *getResolvedType() const {
assert(getParent() && "Not an associated type");
return identifier.assocTypeOrConcrete;
}

/// Retrieve the associated type to which this potential archetype
/// has been resolved.
AssociatedTypeDecl *getResolvedAssociatedType() const {
AssociatedTypeDecl *getResolvedType() const {
assert(getParent() && "Not an associated type");
return dyn_cast<AssociatedTypeDecl>(identifier.assocTypeOrConcrete);
return identifier.assocType;
}

/// Determine whether this is a generic parameter.
Expand Down Expand Up @@ -1640,16 +1623,7 @@ class GenericSignatureBuilder::PotentialArchetype {
/// Retrieve the name of a nested potential archetype.
Identifier getNestedName() const {
assert(getParent() && "Not a nested type");
return identifier.assocTypeOrConcrete->getName();
}

/// Retrieve the concrete type declaration.
TypeDecl *getConcreteTypeDecl() const {
assert(getParent() && "not a nested type");
if (isa<AssociatedTypeDecl>(identifier.assocTypeOrConcrete))
return nullptr;

return identifier.assocTypeOrConcrete;
return identifier.assocType->getName();
}

/// Retrieve the set of nested types.
Expand Down Expand Up @@ -1692,12 +1666,12 @@ class GenericSignatureBuilder::PotentialArchetype {
/// protocol.
///
/// \returns the potential archetype associated with the associated
/// type or typealias of the given protocol, unless the \c kind implies that
/// type of the given protocol, unless the \c kind implies that
/// a potential archetype should not be created if it's missing.
PotentialArchetype *updateNestedTypeForConformance(
GenericSignatureBuilder &builder,
TypeDecl *type,
ArchetypeResolutionKind kind);
PotentialArchetype *
updateNestedTypeForConformance(GenericSignatureBuilder &builder,
AssociatedTypeDecl *assocType,
ArchetypeResolutionKind kind);

/// Retrieve the dependent type that describes this potential
/// archetype.
Expand Down
Loading