@@ -2975,8 +2975,13 @@ bool AbstractStorageDecl::isFormallyResilient() const {
29752975bool AbstractStorageDecl::isResilient () const {
29762976 if (!isFormallyResilient ())
29772977 return false ;
2978-
2979- return getModuleContext ()->isResilient ();
2978+ if (!getModuleContext ()->isResilient ())
2979+ return false ;
2980+ // Allows bypassing resilience checks for package decls
2981+ // at use site within a package if opted in, whether the
2982+ // loaded module was built resiliently or not.
2983+ return !getDeclContext ()->allowBypassResilienceInPackage (getFormalAccessScope (/* useDC=*/ nullptr ,
2984+ /* treatUsableFromInlineAsPublic=*/ true ).isPackage ());
29802985}
29812986
29822987bool AbstractStorageDecl::isResilient (ModuleDecl *M,
@@ -4207,13 +4212,6 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
42074212 return access == AccessLevel::Open;
42084213}
42094214
4210- bool ValueDecl::hasPackageAccess () const {
4211- AccessLevel access =
4212- getAdjustedFormalAccess (this , /* useDC*/ nullptr ,
4213- /* treatUsableFromInlineAsPublic*/ false );
4214- return access == AccessLevel::Package;
4215- }
4216-
42174215// / Given the formal access level for using \p VD, compute the scope where
42184216// / \p VD may be accessed, taking \@usableFromInline, \@testable imports,
42194217// / \@_spi imports, and enclosing access levels into account.
@@ -5054,8 +5052,13 @@ bool NominalTypeDecl::isFormallyResilient() const {
50545052bool NominalTypeDecl::isResilient () const {
50555053 if (!isFormallyResilient ())
50565054 return false ;
5057-
5058- return getModuleContext ()->isResilient ();
5055+ if (!getModuleContext ()->isResilient ())
5056+ return false ;
5057+ // Allows bypassing resilience checks for package decls
5058+ // at use site within a package if opted in, whether the
5059+ // loaded module was built resiliently or not.
5060+ return !getDeclContext ()->allowBypassResilienceInPackage (getFormalAccessScope (/* useDC=*/ nullptr ,
5061+ /* treatUsableFromInlineAsPublic=*/ true ).isPackage ());
50595062}
50605063
50615064DestructorDecl *NominalTypeDecl::getValueTypeDestructor () {
@@ -6375,7 +6378,11 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
63756378 // Non-public, non-versioned enums are always exhaustive.
63766379 AccessScope accessScope = getFormalAccessScope (/* useDC*/ nullptr ,
63776380 /* respectVersioned*/ true );
6378- if (!accessScope.isPublic ())
6381+ // Both public and package enums should behave the same unless
6382+ // package enum is optimized with bypassing resilience checks.
6383+ if (!accessScope.isPublicOrPackage ())
6384+ return true ;
6385+ if (useDC && useDC->allowBypassResilienceInPackage (accessScope.isPackage ()))
63796386 return true ;
63806387
63816388 // All other checks are use-site specific; with no further information, the
0 commit comments