@@ -2952,31 +2952,30 @@ bool Decl::isOutermostPrivateOrFilePrivateScope() const {
29522952 !isInPrivateOrLocalContext (this );
29532953}
29542954
2955- bool AbstractStorageDecl::isFormallyResilient () const {
2955+ bool AbstractStorageDecl::isResilient () const {
29562956 // Check for an explicit @_fixed_layout attribute.
29572957 if (getAttrs ().hasAttribute <FixedLayoutAttr>())
29582958 return false ;
29592959
29602960 // If we're an instance property of a nominal type, query the type.
2961- auto *dc = getDeclContext ();
29622961 if (!isStatic ())
2963- if (auto *nominalDecl = dc ->getSelfNominalTypeDecl ())
2962+ if (auto *nominalDecl = getDeclContext () ->getSelfNominalTypeDecl ())
29642963 return nominalDecl->isResilient ();
29652964
29662965 // Non-public global and static variables always have a
29672966 // fixed layout.
2968- if (!getFormalAccessScope (/* useDC=*/ nullptr ,
2969- /* treatUsableFromInlineAsPublic=*/ true ).isPublicOrPackage ())
2967+ auto accessScope = getFormalAccessScope (/* useDC=*/ nullptr ,
2968+ /* treatUsableFromInlineAsPublic=*/ true );
2969+ if (!accessScope.isPublicOrPackage ())
29702970 return false ;
29712971
2972- return true ;
2973- }
2974-
2975- bool AbstractStorageDecl::isResilient () const {
2976- if (!isFormallyResilient ())
2972+ if (!getModuleContext ()->isResilient ())
29772973 return false ;
29782974
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 ());
29802979}
29812980
29822981bool AbstractStorageDecl::isResilient (ModuleDecl *M,
@@ -4207,13 +4206,6 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
42074206 return access == AccessLevel::Open;
42084207}
42094208
4210- bool ValueDecl::hasPackageAccess () const {
4211- AccessLevel access =
4212- getAdjustedFormalAccess (this , /* useDC*/ nullptr ,
4213- /* treatUsableFromInlineAsPublic*/ false );
4214- return access == AccessLevel::Package;
4215- }
4216-
42174209// / Given the formal access level for using \p VD, compute the scope where
42184210// / \p VD may be accessed, taking \@usableFromInline, \@testable imports,
42194211// / \@_spi imports, and enclosing access levels into account.
@@ -5054,8 +5046,14 @@ bool NominalTypeDecl::isFormallyResilient() const {
50545046bool NominalTypeDecl::isResilient () const {
50555047 if (!isFormallyResilient ())
50565048 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 ());
50595057}
50605058
50615059DestructorDecl *NominalTypeDecl::getValueTypeDestructor () {
@@ -6375,7 +6373,11 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
63756373 // Non-public, non-versioned enums are always exhaustive.
63766374 AccessScope accessScope = getFormalAccessScope (/* useDC*/ nullptr ,
63776375 /* 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 ()))
63796381 return true ;
63806382
63816383 // All other checks are use-site specific; with no further information, the
0 commit comments