Skip to content

Commit 063d159

Browse files
committed
Rename isFragile() as isStrictlyResilient() in var decl.
Add isStrictlyResilient() to nominal type and module decl.
1 parent 36b4d2d commit 063d159

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

include/swift/AST/Decl.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,13 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
41514151
/// is built resiliently.
41524152
bool isResilient() const;
41534153

4154+
/// True if the decl is resilient AND also its defining module does
4155+
/// _not_ allow non-resilient access; the module can allow such access
4156+
/// if package optimization is enabled so its client modules within the
4157+
/// same package can have a direct access to this decl even if it's
4158+
/// resilient.
4159+
bool isStrictlyResilient() const;
4160+
41544161
/// Returns whether this decl is accessed non/resiliently at the _use_ site
41554162
/// in \p accessingModule, depending on \p expansion.
41564163
///
@@ -6015,10 +6022,12 @@ class AbstractStorageDecl : public ValueDecl {
60156022
/// property from the given module?
60166023
bool isResilient(ModuleDecl *M, ResilienceExpansion expansion) const;
60176024

6018-
/// True if the decl is non-resilient, or its defining module allows
6019-
/// non-resilient access so its consuming modules within the same
6020-
/// package can have visibility into this decl.
6021-
bool isFragile() const;
6025+
/// True if the decl is resilient AND also its defining module does
6026+
/// _not_ allow non-resilient access; the module can allow such access
6027+
/// if package optimization is enabled so its client modules within the
6028+
/// same package can have a direct access to this decl even if it's
6029+
/// resilient.
6030+
bool isStrictlyResilient() const;
60226031

60236032
/// True if the storage can be referenced by a keypath directly.
60246033
/// Otherwise, its override must be referenced.

include/swift/AST/Module.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,15 @@ class ModuleDecl
779779
return getResilienceStrategy() != ResilienceStrategy::Default;
780780
}
781781

782+
/// True if this module is resilient AND also does _not_ allow
783+
/// non-resilient access; the module can allow such access if
784+
/// package optimization is enabled so its client modules within
785+
/// the same package can have a direct access to decls in this
786+
/// module even if it's built resiliently.
787+
bool isStrictlyResilient() const {
788+
return isResilient() && !allowNonResilientAccess();
789+
}
790+
782791
/// Look up a (possibly overloaded) value set at top-level scope
783792
/// (but with the specified access path, which may come from an import decl)
784793
/// within the current module.

lib/AST/Decl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,8 +3032,8 @@ bool Decl::isOutermostPrivateOrFilePrivateScope() const {
30323032
!isInPrivateOrLocalContext(this);
30333033
}
30343034

3035-
bool AbstractStorageDecl::isFragile() const {
3036-
return !isResilient() || getModuleContext()->allowNonResilientAccess();
3035+
bool AbstractStorageDecl::isStrictlyResilient() const {
3036+
return isResilient() && !getModuleContext()->allowNonResilientAccess();
30373037
}
30383038

30393039
bool AbstractStorageDecl::isResilient() const {
@@ -5146,6 +5146,10 @@ bool NominalTypeDecl::isResilient() const {
51465146
return getModuleContext()->isResilient();
51475147
}
51485148

5149+
bool NominalTypeDecl::isStrictlyResilient() const {
5150+
return isResilient() && !getModuleContext()->allowNonResilientAccess();
5151+
}
5152+
51495153
DestructorDecl *NominalTypeDecl::getValueTypeDestructor() {
51505154
if (!isa<StructDecl>(this) && !isa<EnumDecl>(this)) {
51515155
return nullptr;

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static LinkageLimit getLinkageLimit(SILDeclRef constant) {
461461
return Limit::OnDemand;
462462

463463
case Kind::GlobalAccessor:
464-
return !cast<VarDecl>(d)->isFragile() ? Limit::NeverPublic : Limit::None;
464+
return cast<VarDecl>(d)->isStrictlyResilient() ? Limit::NeverPublic : Limit::None;
465465

466466
case Kind::DefaultArgGenerator:
467467
// If the default argument is to be serialized, only use non-ABI public
@@ -507,8 +507,7 @@ static LinkageLimit getLinkageLimit(SILDeclRef constant) {
507507
return Limit::AlwaysEmitIntoClient;
508508

509509
// FIXME: This should always be true.
510-
if (d->getModuleContext()->isResilient() &&
511-
!d->getModuleContext()->allowNonResilientAccess())
510+
if (d->getModuleContext()->isStrictlyResilient())
512511
return Limit::NeverPublic;
513512

514513
break;
@@ -1529,11 +1528,10 @@ SubclassScope SILDeclRef::getSubclassScope() const {
15291528
// FIXME: This is too narrow. Any class with resilient metadata should
15301529
// probably have this, at least for method overrides that don't add new
15311530
// vtable entries.
1532-
bool isResilientClass = classType->isResilient() &&
1533-
!classType->getModuleContext()->allowNonResilientAccess();
1531+
bool isStrictResilientClass = classType->isStrictlyResilient();
15341532

15351533
if (auto *CD = dyn_cast<ConstructorDecl>(decl)) {
1536-
if (isResilientClass)
1534+
if (isStrictResilientClass)
15371535
return SubclassScope::NotApplicable;
15381536
// Initializing entry points do not appear in the vtable.
15391537
if (kind == SILDeclRef::Kind::Initializer)
@@ -1564,14 +1562,14 @@ SubclassScope SILDeclRef::getSubclassScope() const {
15641562
// In the resilient case, we're going to be making symbols _less_
15651563
// visible, so make sure we stop now; final methods can always be
15661564
// called directly.
1567-
if (isResilientClass)
1565+
if (isStrictResilientClass)
15681566
return SubclassScope::Internal;
15691567
}
15701568

15711569
assert(decl->getEffectiveAccess() <= classType->getEffectiveAccess() &&
15721570
"class must be as visible as its members");
15731571

1574-
if (isResilientClass) {
1572+
if (isStrictResilientClass) {
15751573
// The symbol should _only_ be reached via the vtable, so we're
15761574
// going to make it hidden.
15771575
return SubclassScope::Resilient;

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
579579

580580
void visitVarDecl(VarDecl *VD) {
581581
// Variables inside non-resilient modules have some additional symbols.
582-
if (VD->isFragile()) {
582+
if (!VD->isStrictlyResilient()) {
583583
// Non-global variables might have an explicit initializer symbol in
584584
// non-resilient modules.
585585
if (VD->getAttrs().hasAttribute<HasInitialValueAttr>() &&

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ RequiresOpaqueAccessorsRequest::evaluate(Evaluator &evaluator,
25372537

25382538
} else if (dc->isModuleScopeContext()) {
25392539
// Fixed-layout global variables don't require opaque accessors.
2540-
if (var->isFragile() && !var->shouldUseNativeDynamicDispatch())
2540+
if (!var->isResilient() && !var->shouldUseNativeDynamicDispatch())
25412541
return false;
25422542

25432543
// Stored properties imported from Clang don't require opaque accessors.

0 commit comments

Comments
 (0)