@@ -2975,8 +2975,13 @@ bool AbstractStorageDecl::isFormallyResilient() const {
2975
2975
bool AbstractStorageDecl::isResilient () const {
2976
2976
if (!isFormallyResilient ())
2977
2977
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 ());
2980
2985
}
2981
2986
2982
2987
bool AbstractStorageDecl::isResilient (ModuleDecl *M,
@@ -4207,13 +4212,6 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
4207
4212
return access == AccessLevel::Open;
4208
4213
}
4209
4214
4210
- bool ValueDecl::hasPackageAccess () const {
4211
- AccessLevel access =
4212
- getAdjustedFormalAccess (this , /* useDC*/ nullptr ,
4213
- /* treatUsableFromInlineAsPublic*/ false );
4214
- return access == AccessLevel::Package;
4215
- }
4216
-
4217
4215
// / Given the formal access level for using \p VD, compute the scope where
4218
4216
// / \p VD may be accessed, taking \@usableFromInline, \@testable imports,
4219
4217
// / \@_spi imports, and enclosing access levels into account.
@@ -5054,8 +5052,13 @@ bool NominalTypeDecl::isFormallyResilient() const {
5054
5052
bool NominalTypeDecl::isResilient () const {
5055
5053
if (!isFormallyResilient ())
5056
5054
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 ());
5059
5062
}
5060
5063
5061
5064
DestructorDecl *NominalTypeDecl::getValueTypeDestructor () {
@@ -6375,7 +6378,11 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
6375
6378
// Non-public, non-versioned enums are always exhaustive.
6376
6379
AccessScope accessScope = getFormalAccessScope (/* useDC*/ nullptr ,
6377
6380
/* 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 ()))
6379
6386
return true ;
6380
6387
6381
6388
// All other checks are use-site specific; with no further information, the
0 commit comments