@@ -2699,45 +2699,63 @@ class GenericTypeDecl : public GenericContext, public TypeDecl {
26992699// / The declared type uses a special kind of archetype type to represent
27002700// / abstracted types, e.g. `(some P, some Q)` becomes `((opaque archetype 0),
27012701// / (opaque archetype 1))`.
2702- class OpaqueTypeDecl : public GenericTypeDecl {
2702+ class OpaqueTypeDecl final :
2703+ public GenericTypeDecl,
2704+ private llvm::TrailingObjects<OpaqueTypeDecl, OpaqueReturnTypeRepr *> {
2705+ friend TrailingObjects;
2706+
27032707 // / The original declaration that "names" the opaque type. Although a specific
27042708 // / opaque type cannot be explicitly named, oapque types can propagate
27052709 // / arbitrarily through expressions, so we need to know *which* opaque type is
27062710 // / propagated.
2707- ValueDecl *NamingDecl;
2711+ // /
2712+ // / The bit indicates whether there are any trailing
2713+ // / OpaqueReturnTypeReprs.
2714+ llvm::PointerIntPair<ValueDecl *, 1 >
2715+ NamingDeclAndHasOpaqueReturnTypeRepr;
27082716
27092717 // / The generic signature of the opaque interface to the type. This is the
27102718 // / outer generic signature with added generic parameters representing the
27112719 // / abstracted underlying types.
27122720 GenericSignature OpaqueInterfaceGenericSignature;
27132721
2714- // / The type repr of the underlying type. Might be null if no source location
2715- // / is availble, e.g. if this decl was loaded from a serialized module.
2716- OpaqueReturnTypeRepr *UnderlyingInterfaceRepr;
2717-
2718- // / The generic parameter that represents the underlying type.
2719- GenericTypeParamType *UnderlyingInterfaceType;
2720-
27212722 // / If known, the underlying type and conformances of the opaque type,
27222723 // / expressed as a SubstitutionMap for the opaque interface generic signature.
27232724 // / This maps types in the interface generic signature to the outer generic
27242725 // / signature of the original declaration.
27252726 Optional<SubstitutionMap> UnderlyingTypeSubstitutions;
27262727
27272728 mutable Identifier OpaqueReturnTypeIdentifier;
2728-
2729- public:
2729+
27302730 OpaqueTypeDecl (ValueDecl *NamingDecl, GenericParamList *GenericParams,
27312731 DeclContext *DC,
27322732 GenericSignature OpaqueInterfaceGenericSignature,
2733- OpaqueReturnTypeRepr *UnderlyingInterfaceRepr,
2734- GenericTypeParamType *UnderlyingInterfaceType);
2733+ ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs);
2734+
2735+ unsigned getNumOpaqueReturnTypeReprs () const {
2736+ return NamingDeclAndHasOpaqueReturnTypeRepr.getInt ()
2737+ ? getOpaqueGenericParams ().size ()
2738+ : 0 ;
2739+ }
2740+
2741+ size_t numTrailingObjects (OverloadToken<OpaqueReturnTypeRepr *>) const {
2742+ return getNumOpaqueReturnTypeReprs ();
2743+ }
2744+
2745+ public:
2746+ static OpaqueTypeDecl *get (
2747+ ValueDecl *NamingDecl, GenericParamList *GenericParams,
2748+ DeclContext *DC,
2749+ GenericSignature OpaqueInterfaceGenericSignature,
2750+ ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs);
27352751
2736- ValueDecl *getNamingDecl () const { return NamingDecl; }
2752+ ValueDecl *getNamingDecl () const {
2753+ return NamingDeclAndHasOpaqueReturnTypeRepr.getPointer ();
2754+ }
27372755
27382756 void setNamingDecl (ValueDecl *D) {
2739- assert (!NamingDecl && " already have naming decl" );
2740- NamingDecl = D ;
2757+ assert (!getNamingDecl () && " already have naming decl" );
2758+ NamingDeclAndHasOpaqueReturnTypeRepr. setPointer (D) ;
27412759 }
27422760
27432761 // / Is this opaque type the opaque return type of the given function?
@@ -2754,11 +2772,24 @@ class OpaqueTypeDecl : public GenericTypeDecl {
27542772 GenericSignature getOpaqueInterfaceGenericSignature () const {
27552773 return OpaqueInterfaceGenericSignature;
27562774 }
2757-
2758- GenericTypeParamType *getUnderlyingInterfaceType () const {
2759- return UnderlyingInterfaceType;
2775+
2776+ // / Retrieve the generic parameters that represent the opaque types described by this opaque
2777+ // / type declaration.
2778+ TypeArrayView<GenericTypeParamType> getOpaqueGenericParams () const {
2779+ return OpaqueInterfaceGenericSignature.getInnermostGenericParams ();
27602780 }
2761-
2781+
2782+ // / Retrieve the buffer containing the opaque return type
2783+ // / representations that correspond to the opaque generic parameters.
2784+ ArrayRef<OpaqueReturnTypeRepr *> getOpaqueReturnTypeReprs () const {
2785+ return {
2786+ getTrailingObjects<OpaqueReturnTypeRepr *>(),
2787+ getNumOpaqueReturnTypeReprs ()
2788+ };
2789+ }
2790+
2791+ // / The substitutions that map the generic parameters of the opaque type to
2792+ // / their underlying types, when that information is known.
27622793 Optional<SubstitutionMap> getUnderlyingTypeSubstitutions () const {
27632794 return UnderlyingTypeSubstitutions;
27642795 }
0 commit comments