Skip to content

Commit f5150e7

Browse files
committed
Remove AbstractStorageDecl::isFormallyResilient.
Update DeclContext::bypassResilienceInPackage.
1 parent 4588cc2 commit f5150e7

File tree

5 files changed

+19
-41
lines changed

5 files changed

+19
-41
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5842,13 +5842,6 @@ class AbstractStorageDecl : public ValueDecl {
58425842
ModuleDecl *module,
58435843
ResilienceExpansion expansion) const;
58445844

5845-
/// Should this declaration behave as if it must be accessed
5846-
/// resiliently, even when we're building a non-resilient module?
5847-
///
5848-
/// This is used for diagnostics, because we do not want a behavior
5849-
/// change between builds with resilience enabled and disabled.
5850-
bool isFormallyResilient() const;
5851-
58525845
/// Do we need to use resilient access patterns outside of this
58535846
/// property's resilience domain?
58545847
bool isResilient() const;

include/swift/AST/DeclContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
535535
/// (possibly also public types later) if opted-in, client and defining module
536536
/// are in the same package, and the defining module is a binary module.
537537
LLVM_READONLY
538-
bool allowBypassResilienceInPackage(bool isForPackageDecl) const;
538+
bool bypassResilienceInPackage(bool isForPackageDecl) const;
539539

540540
/// Returns the module context that contains this context.
541541
LLVM_READONLY

lib/AST/Decl.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,15 +2952,13 @@ 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

2960-
// If we're an instance property of a nominal type, query the type.
2961-
auto *dc = getDeclContext();
29622960
if (!isStatic())
2963-
if (auto *nominalDecl = dc->getSelfNominalTypeDecl())
2961+
if (auto *nominalDecl = getDeclContext()->getSelfNominalTypeDecl())
29642962
return nominalDecl->isResilient();
29652963

29662964
// Non-public global and static variables always have a
@@ -2969,19 +2967,14 @@ bool AbstractStorageDecl::isFormallyResilient() const {
29692967
/*treatUsableFromInlineAsPublic=*/true).isPublicOrPackage())
29702968
return false;
29712969

2972-
return true;
2973-
}
2974-
2975-
bool AbstractStorageDecl::isResilient() const {
2976-
if (!isFormallyResilient())
2977-
return false;
29782970
if (!getModuleContext()->isResilient())
29792971
return false;
2972+
29802973
// Allows bypassing resilience checks for package decls
29812974
// at use site within a package if opted in, whether the
29822975
// loaded module was built resiliently or not.
2983-
return !getDeclContext()->allowBypassResilienceInPackage(getFormalAccessScope(/*useDC=*/nullptr,
2984-
/*treatUsableFromInlineAsPublic=*/true).isPackage());
2976+
return !getDeclContext()->bypassResilienceInPackage(getFormalAccessScope(/*useDC=*/nullptr,
2977+
/*treatUsableFromInlineAsPublic=*/true).isPackage());
29852978
}
29862979

29872980
bool AbstractStorageDecl::isResilient(ModuleDecl *M,
@@ -5057,8 +5050,8 @@ bool NominalTypeDecl::isResilient() const {
50575050
// Allows bypassing resilience checks for package decls
50585051
// at use site within a package if opted in, whether the
50595052
// loaded module was built resiliently or not.
5060-
return !getDeclContext()->allowBypassResilienceInPackage(getFormalAccessScope(/*useDC=*/nullptr,
5061-
/*treatUsableFromInlineAsPublic=*/true).isPackage());
5053+
return !getDeclContext()->bypassResilienceInPackage(getFormalAccessScope(/*useDC=*/nullptr,
5054+
/*treatUsableFromInlineAsPublic=*/true).isPackage());
50625055
}
50635056

50645057
DestructorDecl *NominalTypeDecl::getValueTypeDestructor() {
@@ -6382,7 +6375,7 @@ bool EnumDecl::isFormallyExhaustive(const DeclContext *useDC) const {
63826375
// package enum is optimized with bypassing resilience checks.
63836376
if (!accessScope.isPublicOrPackage())
63846377
return true;
6385-
if (useDC && useDC->allowBypassResilienceInPackage(accessScope.isPackage()))
6378+
if (useDC && useDC->bypassResilienceInPackage(accessScope.isPackage()))
63866379
return true;
63876380

63886381
// All other checks are use-site specific; with no further information, the

lib/AST/DeclContext.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,12 @@ PackageUnit *DeclContext::getPackageContext(bool lookupIfNotCurrent) const {
300300
return nullptr;
301301
}
302302

303-
bool DeclContext::allowBypassResilienceInPackage(bool isForPackageDecl) const {
304-
// Bypassing resilience checks only applies to package types.
305-
if (!isForPackageDecl)
306-
return false;
307-
308-
auto shouldAllow = true;
309-
// Check if the enclosing type is non-resilient.
310-
if (auto enclosingNominal = dyn_cast<NominalTypeDecl>(this)) {
311-
shouldAllow = !enclosingNominal->isResilient();
312-
} else if (auto enclosingExt = dyn_cast<ExtensionDecl>(this)) {
313-
if (auto extNominal = enclosingExt->getExtendedNominal())
314-
shouldAllow = !extNominal->isResilient();
315-
}
316-
317-
// Check if opted-in for bypassing resilience checks, client and defining
318-
// module are in the same package, and defining module is a binary module.
319-
return shouldAllow &&
303+
bool DeclContext::bypassResilienceInPackage(bool isForPackageDecl) const {
304+
// Bypassing resilience checks only applies to package types (and possibly
305+
// public types in a package in the future). Allowed only if opted-in for
306+
// bypassing checks, client and defining module are in the same package,
307+
// and defining module is a binary module.
308+
return isForPackageDecl &&
320309
getASTContext().LangOpts.EnableBypassResilienceInPackage &&
321310
getParentModule()->inPackage(getASTContext().LangOpts.PackageName) &&
322311
!getParentModule()->isBuiltFromInterface();

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,10 @@ static bool canStorageUseTrivialDescriptor(SILGenModule &SGM,
18891889
if (SGM.canStorageUseStoredKeyPathComponent(decl, expansion)) {
18901890
// External modules can't directly access storage, unless this is a
18911891
// property in a fixed-layout type.
1892-
return !decl->isFormallyResilient();
1892+
// Assert here as key path component cannot refer to a static var.
1893+
assert(!decl->isStatic());
1894+
// By this point, decl is a fixed layout or its enclosing type is non-resilient.
1895+
return true;
18931896
}
18941897

18951898
// If the type is computed and doesn't have a setter that's hidden from

0 commit comments

Comments
 (0)