Skip to content

Commit c2224f3

Browse files
authored
Merge pull request #8112 from DougGregor/gsb-nested-types-lazier
2 parents fdce984 + c443739 commit c2224f3

File tree

4 files changed

+519
-308
lines changed

4 files changed

+519
-308
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,13 +1025,41 @@ class GenericSignatureBuilder::PotentialArchetype {
10251025
/// The source of the layout constraint requirement.
10261026
const RequirementSource *LayoutSource = nullptr;
10271027

1028+
/// A stored nested type.
1029+
struct StoredNestedType {
1030+
/// The potential archetypes describing this nested type, all of which
1031+
/// are equivalent.
1032+
llvm::TinyPtrVector<PotentialArchetype *> archetypes;
1033+
1034+
typedef llvm::TinyPtrVector<PotentialArchetype *>::iterator iterator;
1035+
iterator begin() { return archetypes.begin(); }
1036+
iterator end() { return archetypes.end(); }
1037+
1038+
typedef llvm::TinyPtrVector<PotentialArchetype *>::const_iterator
1039+
const_iterator;
1040+
const_iterator begin() const { return archetypes.begin(); }
1041+
const_iterator end() const { return archetypes.end(); }
1042+
1043+
PotentialArchetype *front() const { return archetypes.front(); }
1044+
PotentialArchetype *back() const { return archetypes.back(); }
1045+
1046+
unsigned size() const { return archetypes.size(); }
1047+
bool empty() const { return archetypes.empty(); }
1048+
1049+
void push_back(PotentialArchetype *pa) {
1050+
archetypes.push_back(pa);
1051+
}
1052+
};
1053+
10281054
/// \brief The set of nested types of this archetype.
10291055
///
10301056
/// For a given nested type name, there may be multiple potential archetypes
10311057
/// corresponding to different associated types (from different protocols)
10321058
/// that share a name.
1033-
llvm::MapVector<Identifier, llvm::TinyPtrVector<PotentialArchetype *>>
1034-
NestedTypes;
1059+
llvm::MapVector<Identifier, StoredNestedType> NestedTypes;
1060+
1061+
/// Tracks the number of conformances that
1062+
unsigned numConformancesInNestedType = 0;
10351063

10361064
/// Whether this is an unresolved nested type.
10371065
unsigned isUnresolvedNestedType : 1;
@@ -1142,6 +1170,10 @@ class GenericSignatureBuilder::PotentialArchetype {
11421170
void resolveAssociatedType(AssociatedTypeDecl *assocType,
11431171
GenericSignatureBuilder &builder);
11441172

1173+
/// Resolve the potential archetype to the given typealias.
1174+
void resolveTypeAlias(TypeAliasDecl *typealias,
1175+
GenericSignatureBuilder &builder);
1176+
11451177
/// Determine whether this is a generic parameter.
11461178
bool isGenericParam() const {
11471179
return parentOrBuilder.is<GenericSignatureBuilder *>();
@@ -1213,8 +1245,7 @@ class GenericSignatureBuilder::PotentialArchetype {
12131245
}
12141246

12151247
/// Retrieve the set of nested types.
1216-
const llvm::MapVector<Identifier, llvm::TinyPtrVector<PotentialArchetype *>> &
1217-
getNestedTypes() const{
1248+
const llvm::MapVector<Identifier, StoredNestedType> &getNestedTypes() const {
12181249
return NestedTypes;
12191250
}
12201251

@@ -1268,6 +1299,52 @@ class GenericSignatureBuilder::PotentialArchetype {
12681299
PotentialArchetype *getNestedType(AssociatedTypeDecl *assocType,
12691300
GenericSignatureBuilder &builder);
12701301

1302+
/// \brief Retrieve (or create) a nested type with a known typealias.
1303+
PotentialArchetype *getNestedType(TypeAliasDecl *typealias,
1304+
GenericSignatureBuilder &builder);
1305+
1306+
/// \brief Retrieve (or create) a nested type that is the current best
1307+
/// nested archetype anchor (locally) with the given name.
1308+
///
1309+
/// When called on the archetype anchor, this will produce the named
1310+
/// archetype anchor.
1311+
PotentialArchetype *getNestedArchetypeAnchor(
1312+
Identifier name,
1313+
GenericSignatureBuilder &builder);
1314+
1315+
/// Describes the kind of update that is performed.
1316+
enum class NestedTypeUpdate {
1317+
/// Resolve an existing potential archetype, but don't create a new
1318+
/// one if not present.
1319+
ResolveExisting,
1320+
/// If this potential archetype is missing, create it.
1321+
AddIfMissing,
1322+
/// If this potential archetype is missing and would be a better anchor,
1323+
/// create it.
1324+
AddIfBetterAnchor,
1325+
};
1326+
1327+
/// Update the named nested type when we know this type conforms to the given
1328+
/// protocol.
1329+
///
1330+
/// \returns the potential archetype associated with the associated
1331+
/// type or typealias of the given protocol, unless the \c kind implies that
1332+
/// a potential archetype should not be created if it's missing.
1333+
PotentialArchetype *updateNestedTypeForConformance(
1334+
PointerUnion<AssociatedTypeDecl *, TypeAliasDecl *> type,
1335+
NestedTypeUpdate kind);
1336+
1337+
/// Update the named nested type when we know this type conforms to the given
1338+
/// protocol.
1339+
///
1340+
/// \returns the potential archetype associated with either an associated
1341+
/// type or typealias of the given protocol, unless the \c kind implies that
1342+
/// a potential archetype should not be created if it's missing.
1343+
PotentialArchetype *updateNestedTypeForConformance(
1344+
Identifier name,
1345+
ProtocolDecl *protocol,
1346+
NestedTypeUpdate kind);
1347+
12711348
/// \brief Retrieve (or build) the type corresponding to the potential
12721349
/// archetype within the given generic environment.
12731350
Type getTypeInContext(GenericSignatureBuilder &builder,

0 commit comments

Comments
 (0)