@@ -5243,6 +5243,70 @@ class ProtocolCompositionType final : public TypeBase,
5243
5243
BEGIN_CAN_TYPE_WRAPPER(ProtocolCompositionType, Type)
5244
5244
END_CAN_TYPE_WRAPPER(ProtocolCompositionType, Type)
5245
5245
5246
+ /// ParametrizedProtocolType - A type that constrains the primary associated
5247
+ /// type of a protocol to an argument type.
5248
+ ///
5249
+ /// Written like a bound generic type, eg Sequence<Int>.
5250
+ ///
5251
+ /// For now, these are only supported in generic requirement-like contexts:
5252
+ /// - Inheritance clauses of protocols, generic parameters, associated types
5253
+ /// - Conformance requirements in where clauses
5254
+ /// - Extensions
5255
+ ///
5256
+ /// Assuming that the primary associated type of Sequence is Element, the
5257
+ /// desugaring is that T : Sequence<Int> is equivalent to
5258
+ ///
5259
+ /// \code
5260
+ /// T : Sequence where T.Element == Int.
5261
+ /// \endcode
5262
+ class ParametrizedProtocolType final : public TypeBase,
5263
+ public llvm::FoldingSetNode {
5264
+ friend struct ExistentialLayout;
5265
+
5266
+ ProtocolType *Base;
5267
+ AssociatedTypeDecl *AssocType;
5268
+ Type Arg;
5269
+
5270
+ public:
5271
+ /// Retrieve an instance of a protocol composition type with the
5272
+ /// given set of members.
5273
+ static Type get(const ASTContext &C, ProtocolType *base,
5274
+ Type arg);
5275
+
5276
+ ProtocolType *getBaseType() const {
5277
+ return Base;
5278
+ }
5279
+
5280
+ AssociatedTypeDecl *getAssocType() const {
5281
+ return AssocType;
5282
+ }
5283
+
5284
+ Type getArgumentType() const {
5285
+ return Arg;
5286
+ }
5287
+
5288
+ void Profile(llvm::FoldingSetNodeID &ID) {
5289
+ Profile(ID, Base, Arg);
5290
+ }
5291
+ static void Profile(llvm::FoldingSetNodeID &ID,
5292
+ ProtocolType *base,
5293
+ Type arg);
5294
+
5295
+ // Implement isa/cast/dyncast/etc.
5296
+ static bool classof(const TypeBase *T) {
5297
+ return T->getKind() == TypeKind::ParametrizedProtocol;
5298
+ }
5299
+
5300
+ private:
5301
+ ParametrizedProtocolType(const ASTContext *ctx,
5302
+ ProtocolType *base, Type arg,
5303
+ RecursiveTypeProperties properties);
5304
+ };
5305
+ BEGIN_CAN_TYPE_WRAPPER(ParametrizedProtocolType, Type)
5306
+ PROXY_CAN_TYPE_SIMPLE_GETTER(getBaseType)
5307
+ PROXY_CAN_TYPE_SIMPLE_GETTER(getArgumentType)
5308
+ END_CAN_TYPE_WRAPPER(ParametrizedProtocolType, Type)
5309
+
5246
5310
/// An existential type, spelled with \c any .
5247
5311
///
5248
5312
/// In Swift 5 mode, a plain protocol name in type
0 commit comments