Skip to content

Commit c063d49

Browse files
authored
Merge pull request #10714 from DougGregor/gsb-no-unresolved-potential-archetypes
2 parents 1803c04 + dbc0422 commit c063d49

File tree

10 files changed

+197
-529
lines changed

10 files changed

+197
-529
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 7 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ class DiagnosticEngine;
6363

6464
/// Determines how to resolve a dependent type to a potential archetype.
6565
enum class ArchetypeResolutionKind {
66-
/// Always create a new potential archetype to describe this dependent type,
67-
/// which might be invalid and may not provide complete information.
68-
AlwaysPartial,
69-
7066
/// Only create a potential archetype when it is well-formed (e.g., a nested
7167
/// type should exist) and make sure we have complete information about
7268
/// that potential archetype.
@@ -274,10 +270,6 @@ class GenericSignatureBuilder {
274270
GenericSignatureBuilder(const GenericSignatureBuilder &) = delete;
275271
GenericSignatureBuilder &operator=(const GenericSignatureBuilder &) = delete;
276272

277-
/// Record that the given potential archetype is unresolved, so we know to
278-
/// resolve it later.
279-
void recordUnresolvedType(PotentialArchetype *unresolvedPA);
280-
281273
/// When a particular requirement cannot be resolved due to, e.g., a
282274
/// currently-unresolvable or nested type, this routine should be
283275
/// called to cope with the unresolved requirement.
@@ -315,10 +307,6 @@ class GenericSignatureBuilder {
315307
ProtocolDecl *Proto,
316308
const RequirementSource *Source);
317309

318-
/// Try to resolve the given unresolved potential archetype.
319-
ConstraintResult resolveUnresolvedType(PotentialArchetype *pa,
320-
bool allowTypoCorrection);
321-
322310
public:
323311
/// \brief Add a new same-type requirement between two fully resolved types
324312
/// (output of \c GenericSignatureBuilder::resolve).
@@ -567,12 +555,6 @@ class GenericSignatureBuilder {
567555
ArrayRef<GenericTypeParamType *> genericParams,
568556
bool allowConcreteGenericParams=false);
569557

570-
/// Diagnose any remaining renames.
571-
///
572-
/// \returns \c true if there were any remaining renames to diagnose.
573-
bool diagnoseRemainingRenames(SourceLoc loc,
574-
ArrayRef<GenericTypeParamType *> genericParams);
575-
576558
/// Process any delayed requirements that can be handled now.
577559
void processDelayedRequirements();
578560

@@ -1294,21 +1276,14 @@ class GenericSignatureBuilder::PotentialArchetype {
12941276

12951277
/// The identifier describing this particular archetype.
12961278
///
1297-
/// \c parentOrBuilder determines whether we have a nested type vs. a root,
1298-
/// while `isUnresolvedNestedType` determines whether we have an unresolved
1299-
/// nested type (vs. a resolved one);
1279+
/// \c parentOrBuilder determines whether we have a nested type vs. a root.
13001280
union PAIdentifier {
1301-
/// The name of an unresolved, nested type.
1302-
Identifier name;
1303-
13041281
/// The associated type or typealias for a resolved nested type.
13051282
TypeDecl *assocTypeOrConcrete;
13061283

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

1310-
PAIdentifier(Identifier name) : name(name) { }
1311-
13121287
PAIdentifier(AssociatedTypeDecl *assocType)
13131288
: assocTypeOrConcrete(assocType) { }
13141289

@@ -1357,55 +1332,32 @@ class GenericSignatureBuilder::PotentialArchetype {
13571332
/// that share a name.
13581333
llvm::MapVector<Identifier, StoredNestedType> NestedTypes;
13591334

1360-
/// Tracks the number of conformances that
1361-
unsigned numConformancesInNestedType = 0;
1362-
1363-
/// Whether this is an unresolved nested type.
1364-
unsigned isUnresolvedNestedType : 1;
1365-
13661335
/// \brief Recursively conforms to itself.
13671336
unsigned IsRecursive : 1;
13681337

1369-
/// Whether this potential archetype is invalid, e.g., because it could not
1370-
/// be resolved.
1371-
unsigned Invalid : 1;
1372-
1373-
/// Whether we have diagnosed a rename.
1374-
unsigned DiagnosedRename : 1;
1375-
1376-
/// If we have renamed this (nested) type due to typo correction,
1377-
/// the old name.
1378-
Identifier OrigName;
1379-
13801338
/// \brief Construct a new potential archetype for an unresolved
13811339
/// associated type.
13821340
PotentialArchetype(PotentialArchetype *parent, Identifier name);
13831341

13841342
/// \brief Construct a new potential archetype for an associated type.
13851343
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType)
1386-
: parentOrBuilder(parent), identifier(assocType),
1387-
isUnresolvedNestedType(false), IsRecursive(false), Invalid(false),
1388-
DiagnosedRename(false)
1344+
: parentOrBuilder(parent), identifier(assocType), IsRecursive(false)
13891345
{
13901346
assert(parent != nullptr && "Not an associated type?");
13911347
}
13921348

13931349
/// \brief Construct a new potential archetype for a concrete declaration.
13941350
PotentialArchetype(PotentialArchetype *parent, TypeDecl *concreteDecl)
1395-
: parentOrBuilder(parent), identifier(concreteDecl),
1396-
isUnresolvedNestedType(false),
1397-
IsRecursive(false), Invalid(false),
1398-
DiagnosedRename(false)
1351+
: parentOrBuilder(parent), identifier(concreteDecl), IsRecursive(false)
13991352
{
14001353
assert(parent != nullptr && "Not an associated type?");
14011354
}
14021355

14031356
/// \brief Construct a new potential archetype for a generic parameter.
1404-
PotentialArchetype(GenericSignatureBuilder *builder, GenericParamKey genericParam)
1357+
PotentialArchetype(GenericSignatureBuilder *builder,
1358+
GenericParamKey genericParam)
14051359
: parentOrBuilder(builder), identifier(genericParam),
1406-
isUnresolvedNestedType(false),
1407-
IsRecursive(false), Invalid(false),
1408-
DiagnosedRename(false)
1360+
IsRecursive(false)
14091361
{
14101362
}
14111363

@@ -1441,23 +1393,9 @@ class GenericSignatureBuilder::PotentialArchetype {
14411393
/// has been resolved.
14421394
AssociatedTypeDecl *getResolvedAssociatedType() const {
14431395
assert(getParent() && "Not an associated type");
1444-
if (isUnresolvedNestedType)
1445-
return nullptr;
1446-
14471396
return dyn_cast<AssociatedTypeDecl>(identifier.assocTypeOrConcrete);
14481397
}
14491398

1450-
/// Determine whether this PA is still unresolved.
1451-
bool isUnresolved() const { return isUnresolvedNestedType; }
1452-
1453-
/// Resolve the potential archetype to the given associated type.
1454-
void resolveAssociatedType(AssociatedTypeDecl *assocType,
1455-
GenericSignatureBuilder &builder);
1456-
1457-
/// Resolve the potential archetype to the given typealias.
1458-
void resolveConcreteType(TypeDecl *concreteDecl,
1459-
GenericSignatureBuilder &builder);
1460-
14611399
/// Determine whether this is a generic parameter.
14621400
bool isGenericParam() const {
14631401
return parentOrBuilder.is<GenericSignatureBuilder *>();
@@ -1484,18 +1422,12 @@ class GenericSignatureBuilder::PotentialArchetype {
14841422
/// Retrieve the name of a nested potential archetype.
14851423
Identifier getNestedName() const {
14861424
assert(getParent() && "Not a nested type");
1487-
if (isUnresolvedNestedType)
1488-
return identifier.name;
1489-
14901425
return identifier.assocTypeOrConcrete->getName();
14911426
}
14921427

14931428
/// Retrieve the concrete type declaration.
14941429
TypeDecl *getConcreteTypeDecl() const {
14951430
assert(getParent() && "not a nested type");
1496-
if (isUnresolvedNestedType)
1497-
return nullptr;
1498-
14991431
if (isa<AssociatedTypeDecl>(identifier.assocTypeOrConcrete))
15001432
return nullptr;
15011433

@@ -1649,12 +1581,7 @@ class GenericSignatureBuilder::PotentialArchetype {
16491581
///
16501582
/// \param genericParams The set of generic parameters to use in the resulting
16511583
/// dependent type.
1652-
///
1653-
/// \param allowUnresolved If true, allow the result to contain
1654-
/// \c DependentMemberType types with a name but no specific associated
1655-
/// type.
1656-
Type getDependentType(ArrayRef<GenericTypeParamType *> genericParams,
1657-
bool allowUnresolved);
1584+
Type getDependentType(ArrayRef<GenericTypeParamType *> genericParams);
16581585

16591586
/// True if the potential archetype has been bound by a concrete type
16601587
/// constraint.
@@ -1676,32 +1603,6 @@ class GenericSignatureBuilder::PotentialArchetype {
16761603
void setIsRecursive() { IsRecursive = true; }
16771604
bool isRecursive() const { return IsRecursive; }
16781605

1679-
bool isInvalid() const { return Invalid; }
1680-
1681-
void setInvalid() { Invalid = true; }
1682-
1683-
/// Determine whether this archetype was renamed due to typo
1684-
/// correction. If so, \c getName() retrieves the new name.
1685-
bool wasRenamed() const { return !OrigName.empty(); }
1686-
1687-
/// Note that this potential archetype was is going to be renamed (due to typo
1688-
/// correction), saving the old name.
1689-
void saveNameForRenaming() {
1690-
OrigName = getNestedName();
1691-
}
1692-
1693-
/// For a renamed potential archetype, retrieve the original name.
1694-
Identifier getOriginalName() const {
1695-
assert(wasRenamed());
1696-
return OrigName;
1697-
}
1698-
1699-
/// Whether we already diagnosed this rename.
1700-
bool alreadyDiagnosedRename() const { return DiagnosedRename; }
1701-
1702-
/// Note that we already diagnosed this rename.
1703-
void setAlreadyDiagnosedRename() { DiagnosedRename = true; }
1704-
17051606
LLVM_ATTRIBUTE_DEPRECATED(
17061607
void dump() const,
17071608
"only for use within the debugger");
@@ -1725,9 +1626,6 @@ class GenericSignatureBuilder::DelayedRequirement {
17251626

17261627
/// A same-type requirement.
17271628
SameType,
1728-
1729-
/// An unresolved potential archetype.
1730-
Unresolved,
17311629
};
17321630

17331631
Kind kind;

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ void lookupVisibleMemberDecls(VisibleDeclConsumer &Consumer,
288288
Type BaseTy,
289289
const DeclContext *CurrDC,
290290
LazyResolver *typeResolver,
291-
bool includeInstanceMembers);
291+
bool includeInstanceMembers,
292+
GenericSignatureBuilder *GSB = nullptr);
292293

293294
namespace namelookup {
294295
enum class ResolutionKind {

lib/AST/GenericSignature.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ CanType GenericSignature::getCanonicalTypeInContext(Type type,
709709
return getCanonicalTypeInContext(rep->getConcreteType(), builder);
710710
}
711711

712-
return rep->getDependentType(getGenericParams(), /*allowUnresolved*/ false);
712+
return rep->getDependentType(getGenericParams());
713713
});
714714

715715
auto result = type->getCanonicalType();
@@ -894,8 +894,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
894894
auto conformsSource = getBestRequirementSource(conforms->second);
895895
assert(conformsSource != source || !requirementSignatureProto);
896896
Type localRootType = conformsSource->getRootPotentialArchetype()
897-
->getDependentType(inProtoSig->getGenericParams(),
898-
/*allowUnresolved*/true);
897+
->getDependentType(inProtoSig->getGenericParams());
899898
localRootType = inProtoSig->getCanonicalTypeInContext(
900899
localRootType,
901900
*inProtocol->getModuleContext());
@@ -937,8 +936,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
937936
auto source = getBestRequirementSource(conforms->second);
938937
auto subjectPA = source->getRootPotentialArchetype();
939938
subjectPA = subjectPA->getArchetypeAnchor(*subjectPA->getBuilder());
940-
Type rootType = subjectPA->getDependentType(getGenericParams(),
941-
/*allowUnresolved=*/false);
939+
Type rootType = subjectPA->getDependentType(getGenericParams());
942940

943941
// Build the path.
944942
buildPath(getRequirements(), source, protocol, rootType, nullptr);

0 commit comments

Comments
 (0)