@@ -4930,6 +4930,25 @@ SourceLoc Decl::getAttributeInsertionLoc(bool forModifier) const {
4930
4930
return resultLoc;
4931
4931
}
4932
4932
4933
+ bool ValueDecl::hasAttributeWithInlinableSemantics () const {
4934
+ if (getAttrs ().hasAttribute <InlinableAttr>())
4935
+ return true ;
4936
+
4937
+ // @inline(always) implies @inlinable on "public" (open, public, package)
4938
+ // declarations.
4939
+ AccessScope access =
4940
+ getFormalAccessScope (nullptr , /* treatUsableFromInlineAsPublic*/ false );
4941
+ if (!access.isPublicOrPackage ())
4942
+ return false ;
4943
+
4944
+ if (auto *inlineAttr = getAttrs ().getAttribute <InlineAttr>()) {
4945
+ if (inlineAttr && inlineAttr->getKind () == InlineKind::Always)
4946
+ return true ;
4947
+ }
4948
+
4949
+ return false ;
4950
+ }
4951
+
4933
4952
// / Returns true if \p VD needs to be treated as publicly-accessible
4934
4953
// / at the SIL, LLVM, and machine levels due to being @usableFromInline.
4935
4954
bool ValueDecl::isUsableFromInline () const {
@@ -4942,22 +4961,22 @@ bool ValueDecl::isUsableFromInline() const {
4942
4961
4943
4962
if (getAttrs ().hasAttribute <UsableFromInlineAttr>() ||
4944
4963
getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr>() ||
4945
- getAttrs (). hasAttribute <InlinableAttr> ())
4964
+ hasAttributeWithInlinableSemantics ())
4946
4965
return true ;
4947
4966
4948
4967
if (auto *accessor = dyn_cast<AccessorDecl>(this )) {
4949
4968
auto *storage = accessor->getStorage ();
4950
4969
if (storage->getAttrs ().hasAttribute <UsableFromInlineAttr>() ||
4951
4970
storage->getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr>() ||
4952
- storage->getAttrs (). hasAttribute <InlinableAttr> ())
4971
+ storage->hasAttributeWithInlinableSemantics ())
4953
4972
return true ;
4954
4973
}
4955
4974
4956
4975
if (auto *opaqueType = dyn_cast<OpaqueTypeDecl>(this )) {
4957
4976
if (auto *namingDecl = opaqueType->getNamingDecl ()) {
4958
4977
if (namingDecl->getAttrs ().hasAttribute <UsableFromInlineAttr>() ||
4959
4978
namingDecl->getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr>() ||
4960
- namingDecl->getAttrs (). hasAttribute <InlinableAttr> ())
4979
+ namingDecl->hasAttributeWithInlinableSemantics ())
4961
4980
return true ;
4962
4981
}
4963
4982
}
@@ -5576,7 +5595,7 @@ void ValueDecl::copyFormalAccessFrom(const ValueDecl *source,
5576
5595
// Inherit the @usableFromInline attribute.
5577
5596
if (source->getAttrs ().hasAttribute <UsableFromInlineAttr>() &&
5578
5597
!getAttrs ().hasAttribute <UsableFromInlineAttr>() &&
5579
- !getAttrs (). hasAttribute <InlinableAttr> () &&
5598
+ !hasAttributeWithInlinableSemantics () &&
5580
5599
DeclAttribute::canAttributeAppearOnDecl (DeclAttrKind::UsableFromInline,
5581
5600
this )) {
5582
5601
auto &ctx = getASTContext ();
@@ -10712,7 +10731,7 @@ bool AbstractFunctionDecl::isValidKeyPathComponent() const {
10712
10731
10713
10732
bool AbstractFunctionDecl::isResilient () const {
10714
10733
// Check for attributes that makes functions non-resilient.
10715
- if (getAttrs (). hasAttribute <InlinableAttr> () &&
10734
+ if (hasAttributeWithInlinableSemantics () &&
10716
10735
getAttrs ().hasAttribute <UsableFromInlineAttr>())
10717
10736
return false ;
10718
10737
0 commit comments