@@ -10820,13 +10820,16 @@ bool AbstractFunctionDecl::isResilient(ModuleDecl *M,
1082010820OpaqueTypeDecl::OpaqueTypeDecl (ValueDecl *NamingDecl,
1082110821 GenericParamList *GenericParams, DeclContext *DC,
1082210822 GenericSignature OpaqueInterfaceGenericSignature,
10823- ArrayRef<TypeRepr *>
10824- OpaqueReturnTypeReprs )
10823+ ArrayRef<TypeRepr *> OpaqueReturnTypeReprs,
10824+ bool hasLazyUnderlyingSubstitutions )
1082510825 : GenericTypeDecl(DeclKind::OpaqueType, DC, Identifier(), SourceLoc(), {},
1082610826 GenericParams),
1082710827 NamingDeclAndHasOpaqueReturnTypeRepr (
1082810828 NamingDecl, !OpaqueReturnTypeReprs.empty()),
1082910829 OpaqueInterfaceGenericSignature(OpaqueInterfaceGenericSignature) {
10830+ Bits.OpaqueTypeDecl .HasLazyUnderlyingSubstitutions
10831+ = hasLazyUnderlyingSubstitutions;
10832+
1083010833 // Always implicit.
1083110834 setImplicit ();
1083210835
@@ -10839,7 +10842,7 @@ OpaqueTypeDecl::OpaqueTypeDecl(ValueDecl *NamingDecl,
1083910842 OpaqueReturnTypeReprs.end (), getTrailingObjects ());
1084010843}
1084110844
10842- OpaqueTypeDecl *OpaqueTypeDecl::get (
10845+ OpaqueTypeDecl *OpaqueTypeDecl::create (
1084310846 ValueDecl *NamingDecl, GenericParamList *GenericParams,
1084410847 DeclContext *DC,
1084510848 GenericSignature OpaqueInterfaceGenericSignature,
@@ -10850,7 +10853,33 @@ OpaqueTypeDecl *OpaqueTypeDecl::get(
1085010853 auto mem = ctx.Allocate (size, alignof (OpaqueTypeDecl));
1085110854 return new (mem) OpaqueTypeDecl (
1085210855 NamingDecl, GenericParams, DC, OpaqueInterfaceGenericSignature,
10853- OpaqueReturnTypeReprs);
10856+ OpaqueReturnTypeReprs, /* hasLazyUnderlyingSubstitutions=*/ false );
10857+ }
10858+
10859+ OpaqueTypeDecl *OpaqueTypeDecl::createDeserialized (
10860+ GenericParamList *GenericParams, DeclContext *DC,
10861+ GenericSignature OpaqueInterfaceGenericSignature,
10862+ LazyMemberLoader *lazyLoader, uint64_t underlyingSubsData) {
10863+ bool hasLazyUnderlyingSubstitutions = (underlyingSubsData != 0 );
10864+
10865+ ASTContext &ctx = DC->getASTContext ();
10866+ auto size = totalSizeToAlloc<TypeRepr *>(0 );
10867+ auto mem = ctx.Allocate (size, alignof (OpaqueTypeDecl));
10868+
10869+ // NamingDecl is set later by deserialization
10870+ auto *decl = new (mem) OpaqueTypeDecl (
10871+ /* namingDecl=*/ nullptr , GenericParams, DC,
10872+ OpaqueInterfaceGenericSignature, { },
10873+ hasLazyUnderlyingSubstitutions);
10874+
10875+ if (hasLazyUnderlyingSubstitutions) {
10876+ auto &ctx = DC->getASTContext ();
10877+ auto *data = static_cast <LazyOpaqueTypeData *>(
10878+ ctx.getOrCreateLazyContextData (decl, lazyLoader));
10879+ data->underlyingSubsData = underlyingSubsData;
10880+ }
10881+
10882+ return decl;
1085410883}
1085510884
1085610885bool OpaqueTypeDecl::isOpaqueReturnTypeOf (const Decl *ownerDecl) const {
@@ -10906,16 +10935,41 @@ bool OpaqueTypeDecl::exportUnderlyingType() const {
1090610935 llvm_unreachable (" The naming decl is expected to be either an AFD or ASD" );
1090710936}
1090810937
10938+ void OpaqueTypeDecl::loadLazyUnderlyingSubstitutions () {
10939+ if (!Bits.OpaqueTypeDecl .HasLazyUnderlyingSubstitutions )
10940+ return ;
10941+
10942+ Bits.OpaqueTypeDecl .HasLazyUnderlyingSubstitutions = 0 ;
10943+
10944+ auto &ctx = getASTContext ();
10945+ auto *data = static_cast <LazyOpaqueTypeData *>(
10946+ ctx.getLazyContextData (this ));
10947+ ASSERT (data != nullptr );
10948+
10949+ data->loader ->finishOpaqueTypeDecl (
10950+ this , data->underlyingSubsData );
10951+ }
10952+
1090910953std::optional<SubstitutionMap>
1091010954OpaqueTypeDecl::getUniqueUnderlyingTypeSubstitutions (
1091110955 bool typeCheckFunctionBodies) const {
10956+ const_cast <OpaqueTypeDecl *>(this )->loadLazyUnderlyingSubstitutions ();
10957+
1091210958 if (!typeCheckFunctionBodies)
1091310959 return UniqueUnderlyingType;
1091410960
1091510961 return evaluateOrDefault (getASTContext ().evaluator ,
1091610962 UniqueUnderlyingTypeSubstitutionsRequest{this }, {});
1091710963}
1091810964
10965+ ArrayRef<OpaqueTypeDecl::ConditionallyAvailableSubstitutions *>
10966+ OpaqueTypeDecl::getConditionallyAvailableSubstitutions () const {
10967+ const_cast <OpaqueTypeDecl *>(this )->loadLazyUnderlyingSubstitutions ();
10968+
10969+ assert (ConditionallyAvailableTypes);
10970+ return ConditionallyAvailableTypes.value ();
10971+ }
10972+
1091910973std::optional<unsigned >
1092010974OpaqueTypeDecl::getAnonymousOpaqueParamOrdinal (TypeRepr *repr) const {
1092110975 assert (NamingDeclAndHasOpaqueReturnTypeRepr.getInt () &&
@@ -10945,7 +10999,8 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
1094510999
1094611000void OpaqueTypeDecl::setConditionallyAvailableSubstitutions (
1094711001 ArrayRef<ConditionallyAvailableSubstitutions *> substitutions) {
10948- assert (!ConditionallyAvailableTypes &&
11002+ ASSERT (!Bits.OpaqueTypeDecl .HasLazyUnderlyingSubstitutions );
11003+ ASSERT (!ConditionallyAvailableTypes &&
1094911004 " resetting conditionally available substitutions?!" );
1095011005 ConditionallyAvailableTypes = getASTContext ().AllocateCopy (substitutions);
1095111006}
0 commit comments