@@ -2952,31 +2952,30 @@ bool Decl::isOutermostPrivateOrFilePrivateScope() const {
2952
2952
!isInPrivateOrLocalContext (this );
2953
2953
}
2954
2954
2955
- bool AbstractStorageDecl::isFormallyResilient () const {
2955
+ bool AbstractStorageDecl::isResilient () const {
2956
2956
// Check for an explicit @_fixed_layout attribute.
2957
2957
if (getAttrs ().hasAttribute <FixedLayoutAttr>())
2958
2958
return false ;
2959
2959
2960
2960
// If we're an instance property of a nominal type, query the type.
2961
- auto *dc = getDeclContext ();
2962
2961
if (!isStatic ())
2963
- if (auto *nominalDecl = dc ->getSelfNominalTypeDecl ())
2962
+ if (auto *nominalDecl = getDeclContext () ->getSelfNominalTypeDecl ())
2964
2963
return nominalDecl->isResilient ();
2965
2964
2966
2965
// Non-public global and static variables always have a
2967
2966
// fixed layout.
2968
- if (!getFormalAccessScope (/* useDC=*/ nullptr ,
2969
- /* treatUsableFromInlineAsPublic=*/ true ).isPublicOrPackage ())
2967
+ auto accessScope = getFormalAccessScope (/* useDC=*/ nullptr ,
2968
+ /* treatUsableFromInlineAsPublic=*/ true );
2969
+ if (!accessScope.isPublicOrPackage ())
2970
2970
return false ;
2971
2971
2972
- return true ;
2973
- }
2974
-
2975
- bool AbstractStorageDecl::isResilient () const {
2976
- if (!isFormallyResilient ())
2972
+ if (!getModuleContext ()->isResilient ())
2977
2973
return false ;
2978
2974
2979
- return getModuleContext ()->isResilient ();
2975
+ // Allows bypassing resilience checks for package decls
2976
+ // at use site within a package if opted in, whether the
2977
+ // loaded module was built resiliently or not.
2978
+ return !getDeclContext ()->bypassResilienceInPackage (accessScope.isPackage ());
2980
2979
}
2981
2980
2982
2981
bool AbstractStorageDecl::isResilient (ModuleDecl *M,
@@ -4207,13 +4206,6 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
4207
4206
return access == AccessLevel::Open;
4208
4207
}
4209
4208
4210
- bool ValueDecl::hasPackageAccess () const {
4211
- AccessLevel access =
4212
- getAdjustedFormalAccess (this , /* useDC*/ nullptr ,
4213
- /* treatUsableFromInlineAsPublic*/ false );
4214
- return access == AccessLevel::Package;
4215
- }
4216
-
4217
4209
// / Given the formal access level for using \p VD, compute the scope where
4218
4210
// / \p VD may be accessed, taking \@usableFromInline, \@testable imports,
4219
4211
// / \@_spi imports, and enclosing access levels into account.
@@ -5054,8 +5046,14 @@ bool NominalTypeDecl::isFormallyResilient() const {
5054
5046
bool NominalTypeDecl::isResilient () const {
5055
5047
if (!isFormallyResilient ())
5056
5048
return false ;
5057
-
5058
- return getModuleContext ()->isResilient ();
5049
+ if (!getModuleContext ()->isResilient ())
5050
+ return false ;
5051
+ // Allows bypassing resilience checks for package decls
5052
+ // at use site within a package if opted in, whether the
5053
+ // loaded module was built resiliently or not.
5054
+ auto accessScope = getFormalAccessScope (/* useDC=*/ nullptr ,
5055
+ /* treatUsableFromInlineAsPublic=*/ true );
5056
+ return !getDeclContext ()->bypassResilienceInPackage (accessScope.isPackage ());
5059
5057
}
5060
5058
5061
5059
DestructorDecl *NominalTypeDecl::getValueTypeDestructor () {
@@ -6375,7 +6373,11 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
6375
6373
// Non-public, non-versioned enums are always exhaustive.
6376
6374
AccessScope accessScope = getFormalAccessScope (/* useDC*/ nullptr ,
6377
6375
/* respectVersioned*/ true );
6378
- if (!accessScope.isPublic ())
6376
+ // Both public and package enums should behave the same unless
6377
+ // package enum is optimized with bypassing resilience checks.
6378
+ if (!accessScope.isPublicOrPackage ())
6379
+ return true ;
6380
+ if (useDC && useDC->bypassResilienceInPackage (accessScope.isPackage ()))
6379
6381
return true ;
6380
6382
6381
6383
// All other checks are use-site specific; with no further information, the
0 commit comments