@@ -492,12 +492,15 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
492
492
SWIFT_INLINE_BITFIELD_EMPTY (TypeDecl, ValueDecl);
493
493
SWIFT_INLINE_BITFIELD_EMPTY (AbstractTypeParamDecl, TypeDecl);
494
494
495
- SWIFT_INLINE_BITFIELD_FULL (GenericTypeParamDecl, AbstractTypeParamDecl, 16 +16 +1 ,
495
+ SWIFT_INLINE_BITFIELD_FULL (GenericTypeParamDecl, AbstractTypeParamDecl, 16 +16 +1 + 1 ,
496
496
: NumPadBits,
497
497
498
498
Depth : 16 ,
499
499
Index : 16 ,
500
- TypeSequence : 1
500
+ TypeSequence : 1 ,
501
+
502
+ // / Whether this generic parameter represents an opaque type.
503
+ IsOpaqueType : 1
501
504
);
502
505
503
506
SWIFT_INLINE_BITFIELD_EMPTY (GenericTypeDecl, TypeDecl);
@@ -2993,9 +2996,14 @@ class AbstractTypeParamDecl : public TypeDecl {
2993
2996
// / \code
2994
2997
// / func min<T : Comparable>(x : T, y : T) -> T { ... }
2995
2998
// / \endcode
2996
- class GenericTypeParamDecl : public AbstractTypeParamDecl {
2997
- public:
2998
- static const unsigned InvalidDepth = 0xFFFF ;
2999
+ class GenericTypeParamDecl final :
3000
+ public AbstractTypeParamDecl,
3001
+ private llvm::TrailingObjects<GenericTypeParamDecl, OpaqueReturnTypeRepr *>{
3002
+ friend TrailingObjects;
3003
+
3004
+ size_t numTrailingObjects (OverloadToken<OpaqueReturnTypeRepr *>) const {
3005
+ return isOpaqueType () ? 1 : 0 ;
3006
+ }
2999
3007
3000
3008
// / Construct a new generic type parameter.
3001
3009
// /
@@ -3006,7 +3014,29 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
3006
3014
// / \param name The name of the generic parameter.
3007
3015
// / \param nameLoc The location of the name.
3008
3016
GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3009
- bool isTypeSequence, unsigned depth, unsigned index);
3017
+ bool isTypeSequence, unsigned depth, unsigned index,
3018
+ bool isOpaqueType, OpaqueReturnTypeRepr *opaqueTypeRepr);
3019
+
3020
+ public:
3021
+ // / Construct a new generic type parameter.
3022
+ // /
3023
+ // / \param dc The DeclContext in which the generic type parameter's owner
3024
+ // / occurs. This should later be overwritten with the actual declaration
3025
+ // / context that owns the type parameter.
3026
+ // /
3027
+ // / \param name The name of the generic parameter.
3028
+ // / \param nameLoc The location of the name.
3029
+ GenericTypeParamDecl (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3030
+ bool isTypeSequence, unsigned depth, unsigned index)
3031
+ : GenericTypeParamDecl(dc, name, nameLoc, isTypeSequence, depth, index,
3032
+ false , nullptr ) { }
3033
+
3034
+ static const unsigned InvalidDepth = 0xFFFF ;
3035
+
3036
+ static GenericTypeParamDecl *
3037
+ create (DeclContext *dc, Identifier name, SourceLoc nameLoc,
3038
+ bool isTypeSequence, unsigned depth, unsigned index,
3039
+ bool isOpaqueType, OpaqueReturnTypeRepr *opaqueTypeRepr);
3010
3040
3011
3041
// / The depth of this generic type parameter, i.e., the number of outer
3012
3042
// / levels of generic parameter lists that enclose this type parameter.
@@ -3034,9 +3064,33 @@ class GenericTypeParamDecl : public AbstractTypeParamDecl {
3034
3064
// / \code
3035
3065
// / func foo<@_typeSequence T>(_ : T...) { }
3036
3066
// / struct Foo<@_typeSequence T> { }
3037
- // / \encode
3067
+ // / \endcode
3038
3068
bool isTypeSequence () const { return Bits.GenericTypeParamDecl .TypeSequence ; }
3039
3069
3070
+ // / Determine whether this generic parameter represents an opaque type.
3071
+ // /
3072
+ // / \code
3073
+ // / // "some P" is representated by a generic type parameter.
3074
+ // / func f() -> [some P] { ... }
3075
+ // / \endcode
3076
+ bool isOpaqueType () const {
3077
+ return Bits.GenericTypeParamDecl .IsOpaqueType ;
3078
+ }
3079
+
3080
+ // / Retrieve the opaque return type representation described by this
3081
+ // / generic parameter, or NULL if any of the following are true:
3082
+ // / - the generic parameter does not describe an opaque type
3083
+ // / - the opaque type was introduced via the "named opaque parameters"
3084
+ // / extension, meaning that it was specified explicitly
3085
+ // / - the enclosing declaration was deserialized, in which case it lost
3086
+ // / the source location information and has no type representation.
3087
+ OpaqueReturnTypeRepr *getOpaqueTypeRepr () const {
3088
+ if (!isOpaqueType ())
3089
+ return nullptr ;
3090
+
3091
+ return *getTrailingObjects<OpaqueReturnTypeRepr *>();
3092
+ }
3093
+
3040
3094
// / The index of this generic type parameter within its generic parameter
3041
3095
// / list.
3042
3096
// /
0 commit comments