@@ -3060,7 +3060,7 @@ bool AbstractStorageDecl::isResilient(ModuleDecl *M,
30603060 case ResilienceExpansion::Maximal:
30613061 if (M == getModuleContext ())
30623062 return false ;
3063- // Non-resilient if bypass optimization in package is enabled
3063+ // Access non-resiliently if package optimization is enabled
30643064 if (bypassResilienceInPackage (M))
30653065 return false ;
30663066 return isResilient ();
@@ -4271,13 +4271,23 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
42714271}
42724272
42734273bool ValueDecl::bypassResilienceInPackage (ModuleDecl *accessingModule) const {
4274- // Client needs to opt in to bypass resilience checks at the use site.
4275- // Client and the loaded module both need to be in the same package.
4276- // The loaded module needs to be built from source and opt in to allow
4277- // non-resilient access.
4278- return getASTContext ().LangOpts .EnableBypassResilienceInPackage &&
4279- getModuleContext ()->inSamePackage (accessingModule) &&
4280- getModuleContext ()->allowNonResilientAccess ();
4274+ auto declModule = getModuleContext ();
4275+ if (declModule->inSamePackage (accessingModule) &&
4276+ declModule->allowNonResilientAccess ()) {
4277+ // If the defining module is built with package-cmo,
4278+ // allow direct access from the use site that belongs
4279+ // to accessingModule (client module).
4280+ if (declModule->isResilient () &&
4281+ declModule->serializePackageEnabled ())
4282+ return true ;
4283+
4284+ // If not, check if the client can still opt in to
4285+ // have a direct access to this decl from the use
4286+ // site with a flag.
4287+ // FIXME: serialize this flag to Module and get it via accessingModule.
4288+ return getASTContext ().LangOpts .EnableBypassResilienceInPackage ;
4289+ }
4290+ return false ;
42814291}
42824292
42834293// / Given the formal access level for using \p VD, compute the scope where
@@ -5134,7 +5144,7 @@ bool NominalTypeDecl::isResilient(ModuleDecl *M,
51345144 // non-resiliently in a maximal context.
51355145 if (M == getModuleContext ())
51365146 return false ;
5137- // Non-resilient if bypass optimization in package is enabled
5147+ // Access non-resiliently if package optimization is enabled
51385148 if (bypassResilienceInPackage (M))
51395149 return false ;
51405150
0 commit comments