@@ -1025,13 +1025,41 @@ class GenericSignatureBuilder::PotentialArchetype {
1025
1025
// / The source of the layout constraint requirement.
1026
1026
const RequirementSource *LayoutSource = nullptr ;
1027
1027
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
+
1028
1054
// / \brief The set of nested types of this archetype.
1029
1055
// /
1030
1056
// / For a given nested type name, there may be multiple potential archetypes
1031
1057
// / corresponding to different associated types (from different protocols)
1032
1058
// / 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 ;
1035
1063
1036
1064
// / Whether this is an unresolved nested type.
1037
1065
unsigned isUnresolvedNestedType : 1 ;
@@ -1142,6 +1170,10 @@ class GenericSignatureBuilder::PotentialArchetype {
1142
1170
void resolveAssociatedType (AssociatedTypeDecl *assocType,
1143
1171
GenericSignatureBuilder &builder);
1144
1172
1173
+ // / Resolve the potential archetype to the given typealias.
1174
+ void resolveTypeAlias (TypeAliasDecl *typealias,
1175
+ GenericSignatureBuilder &builder);
1176
+
1145
1177
// / Determine whether this is a generic parameter.
1146
1178
bool isGenericParam () const {
1147
1179
return parentOrBuilder.is <GenericSignatureBuilder *>();
@@ -1213,8 +1245,7 @@ class GenericSignatureBuilder::PotentialArchetype {
1213
1245
}
1214
1246
1215
1247
// / 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 {
1218
1249
return NestedTypes;
1219
1250
}
1220
1251
@@ -1268,6 +1299,52 @@ class GenericSignatureBuilder::PotentialArchetype {
1268
1299
PotentialArchetype *getNestedType (AssociatedTypeDecl *assocType,
1269
1300
GenericSignatureBuilder &builder);
1270
1301
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
+
1271
1348
// / \brief Retrieve (or build) the type corresponding to the potential
1272
1349
// / archetype within the given generic environment.
1273
1350
Type getTypeInContext (GenericSignatureBuilder &builder,
0 commit comments