@@ -492,12 +492,15 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
492492 SWIFT_INLINE_BITFIELD_EMPTY (TypeDecl, ValueDecl);
493493 SWIFT_INLINE_BITFIELD_EMPTY (AbstractTypeParamDecl, TypeDecl);
494494
495- SWIFT_INLINE_BITFIELD_FULL (GenericTypeParamDecl, AbstractTypeParamDecl, 16 +16 +1 ,
495+ SWIFT_INLINE_BITFIELD_FULL (GenericTypeParamDecl, AbstractTypeParamDecl, 16 +16 +1 + 1 ,
496496 : NumPadBits,
497497
498498 Depth : 16 ,
499499 Index : 16 ,
500- TypeSequence : 1
500+ TypeSequence : 1 ,
501+
502+ // / Whether this generic parameter represents an opaque type.
503+ IsOpaqueType : 1
501504 );
502505
503506 SWIFT_INLINE_BITFIELD_EMPTY (GenericTypeDecl, TypeDecl);
@@ -2786,7 +2789,8 @@ class OpaqueTypeDecl final :
27862789 // / Get the ordinal of the anonymous opaque parameter of this decl with type
27872790 // / repr `repr`, as introduce implicitly by an occurrence of "some" in return
27882791 // / position e.g. `func f() -> some P`. Returns -1 if `repr` is not found.
2789- unsigned getAnonymousOpaqueParamOrdinal (OpaqueReturnTypeRepr *repr) const ;
2792+ Optional<unsigned > getAnonymousOpaqueParamOrdinal (
2793+ OpaqueReturnTypeRepr *repr) const ;
27902794
27912795 GenericSignature getOpaqueInterfaceGenericSignature () const {
27922796 return OpaqueInterfaceGenericSignature;
@@ -2993,9 +2997,14 @@ class AbstractTypeParamDecl : public TypeDecl {
29932997// / \code
29942998// / func min<T : Comparable>(x : T, y : T) -> T { ... }
29952999// / \endcode
2996- class GenericTypeParamDecl : public AbstractTypeParamDecl {
2997- public:
2998- static const unsigned InvalidDepth = 0xFFFF ;
3000+ class GenericTypeParamDecl final :
3001+ public AbstractTypeParamDecl,
3002+ private llvm::TrailingObjects<GenericTypeParamDecl, OpaqueReturnTypeRepr *>{
3003+ friend TrailingObjects;
3004+
3005+ size_t numTrailingObjects (OverloadToken<OpaqueReturnTypeRepr *>) const {
3006+ return isOpaqueType () ? 1 : 0 ;
3007+ }
29993008
30003009 // / Construct a new generic type parameter.
30013010 // /
@@ -3006,7 +3015,29 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
30063015 // / \param name The name of the generic parameter.
30073016 // / \param nameLoc The location of the name.
30083017 GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3009- bool isTypeSequence, unsigned depth, unsigned index);
3018+ bool isTypeSequence, unsigned depth, unsigned index,
3019+ bool isOpaqueType, OpaqueReturnTypeRepr *opaqueTypeRepr);
3020+
3021+ public:
3022+ // / Construct a new generic type parameter.
3023+ // /
3024+ // / \param dc The DeclContext in which the generic type parameter's owner
3025+ // / occurs. This should later be overwritten with the actual declaration
3026+ // / context that owns the type parameter.
3027+ // /
3028+ // / \param name The name of the generic parameter.
3029+ // / \param nameLoc The location of the name.
3030+ GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3031+ bool isTypeSequence, unsigned depth, unsigned index)
3032+ : GenericTypeParamDecl(dc, name, nameLoc, isTypeSequence, depth, index,
3033+ false , nullptr ) { }
3034+
3035+ static const unsigned InvalidDepth = 0xFFFF ;
3036+
3037+ static GenericTypeParamDecl *
3038+ create (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3039+ bool isTypeSequence, unsigned depth, unsigned index,
3040+ bool isOpaqueType, OpaqueReturnTypeRepr *opaqueTypeRepr);
30103041
30113042 // / The depth of this generic type parameter, i.e., the number of outer
30123043 // / levels of generic parameter lists that enclose this type parameter.
@@ -3034,9 +3065,33 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
30343065 // / \code
30353066 // / func foo<@_typeSequence T>(_ : T...) { }
30363067 // / struct Foo<@_typeSequence T> { }
3037- // / \encode
3068+ // / \endcode
30383069 bool isTypeSequence () const { return Bits.GenericTypeParamDecl .TypeSequence ; }
30393070
3071+ // / Determine whether this generic parameter represents an opaque type.
3072+ // /
3073+ // / \code
3074+ // / // "some P" is representated by a generic type parameter.
3075+ // / func f() -> [some P] { ... }
3076+ // / \endcode
3077+ bool isOpaqueType () const {
3078+ return Bits.GenericTypeParamDecl .IsOpaqueType ;
3079+ }
3080+
3081+ // / Retrieve the opaque return type representation described by this
3082+ // / generic parameter, or NULL if any of the following are true:
3083+ // / - the generic parameter does not describe an opaque type
3084+ // / - the opaque type was introduced via the "named opaque parameters"
3085+ // / extension, meaning that it was specified explicitly
3086+ // / - the enclosing declaration was deserialized, in which case it lost
3087+ // / the source location information and has no type representation.
3088+ OpaqueReturnTypeRepr *getOpaqueTypeRepr () const {
3089+ if (!isOpaqueType ())
3090+ return nullptr ;
3091+
3092+ return *getTrailingObjects<OpaqueReturnTypeRepr *>();
3093+ }
3094+
30403095 // / The index of this generic type parameter within its generic parameter
30413096 // / list.
30423097 // /
0 commit comments