Skip to content

Commit eb147d9

Browse files
authored
Merge pull request swiftlang#20531 from slavapestov/inline-always-is-not-inlinable
@inline(__always) should not imply @inlinable
2 parents 8c969b8 + 6e44005 commit eb147d9

29 files changed

+103
-191
lines changed

benchmark/utils/TestsUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public func Random() -> Int64 {
221221
return lfsrRandomGenerator.randInt()
222222
}
223223

224-
@inline(__always)
224+
@inlinable @inline(__always)
225225
public func CheckResults(
226226
_ resultsMatch: Bool,
227227
file: StaticString = #file,

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ SIMPLE_DECL_ATTR(unsafe_no_objc_tagged_pointer, UnsafeNoObjCTaggedPointer,
179179
UserInaccessible,
180180
19)
181181
DECL_ATTR(inline, Inline,
182-
OnFunc | OnAccessor | OnConstructor,
182+
OnVar | OnSubscript | OnAbstractFunction,
183183
20)
184184
DECL_ATTR(_semantics, Semantics,
185185
OnAbstractFunction | OnSubscript |

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,7 +4097,6 @@ ERROR(usable_from_inline_attr_in_protocol,none,
40974097

40984098
#define FRAGILE_FUNC_KIND \
40994099
"%select{a '@_transparent' function|" \
4100-
"an '@inline(__always)' function|" \
41014100
"an '@inlinable' function|" \
41024101
"a default argument value|" \
41034102
"a property initializer in a '@_fixed_layout' type}"
@@ -4126,7 +4125,7 @@ NOTE(resilience_decl_declared_here,
41264125

41274126
ERROR(class_designated_init_inlinable_resilient,none,
41284127
"initializer for class %0 is "
4129-
"'%select{@_transparent|@inline(__always)|@inlinable|%error}1' and must "
4128+
"'%select{@_transparent|@inlinable|%error}1' and must "
41304129
"delegate to another initializer", (Type, unsigned))
41314130

41324131
ERROR(attribute_invalid_on_stored_property,

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,13 @@ ResilienceExpansion DeclContext::getResilienceExpansion() const {
323323
if (!funcAccess.isPublic())
324324
break;
325325

326-
// Bodies of public transparent and always-inline functions are
327-
// serialized, so use conservative access patterns.
326+
// If the function is public, @_transparent implies @inlinable.
328327
if (AFD->isTransparent())
329328
return ResilienceExpansion::Minimal;
330329

331330
if (AFD->getAttrs().hasAttribute<InlinableAttr>())
332331
return ResilienceExpansion::Minimal;
333332

334-
if (auto attr = AFD->getAttrs().getAttribute<InlineAttr>())
335-
if (attr->getKind() == InlineKind::Always)
336-
return ResilienceExpansion::Minimal;
337-
338333
// If a property or subscript is @inlinable, the accessors are
339334
// @inlinable also.
340335
if (auto accessor = dyn_cast<AccessorDecl>(AFD))

lib/SIL/SILDeclRef.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,26 +528,47 @@ IsSerialized_t SILDeclRef::isSerialized() const {
528528
return IsNotSerialized;
529529
}
530530

531-
/// \brief True if the function has noinline attribute.
531+
/// \brief True if the function has an @inline(never) attribute.
532532
bool SILDeclRef::isNoinline() const {
533533
if (!hasDecl())
534534
return false;
535-
if (auto InlineA = getDecl()->getAttrs().getAttribute<InlineAttr>())
536-
if (InlineA->getKind() == InlineKind::Never)
535+
536+
auto *decl = getDecl();
537+
if (auto *attr = decl->getAttrs().getAttribute<InlineAttr>())
538+
if (attr->getKind() == InlineKind::Never)
537539
return true;
538-
if (auto *semanticsA = getDecl()->getAttrs().getAttribute<SemanticsAttr>())
539-
if (semanticsA->Value.equals("keypath.entry"))
540+
541+
if (auto *accessorDecl = dyn_cast<AccessorDecl>(decl)) {
542+
auto *storage = accessorDecl->getStorage();
543+
if (auto *attr = storage->getAttrs().getAttribute<InlineAttr>())
544+
if (attr->getKind() == InlineKind::Never)
545+
return true;
546+
}
547+
548+
if (auto *attr = decl->getAttrs().getAttribute<SemanticsAttr>())
549+
if (attr->Value.equals("keypath.entry"))
540550
return true;
551+
541552
return false;
542553
}
543554

544-
/// \brief True if the function has noinline attribute.
555+
/// \brief True if the function has the @inline(__always) attribute.
545556
bool SILDeclRef::isAlwaysInline() const {
546557
if (!hasDecl())
547558
return false;
548-
if (auto InlineA = getDecl()->getAttrs().getAttribute<InlineAttr>())
549-
if (InlineA->getKind() == InlineKind::Always)
559+
560+
auto *decl = getDecl();
561+
if (auto attr = decl->getAttrs().getAttribute<InlineAttr>())
562+
if (attr->getKind() == InlineKind::Always)
550563
return true;
564+
565+
if (auto *accessorDecl = dyn_cast<AccessorDecl>(decl)) {
566+
auto *storage = accessorDecl->getStorage();
567+
if (auto *attr = storage->getAttrs().getAttribute<InlineAttr>())
568+
if (attr->getKind() == InlineKind::Always)
569+
return true;
570+
}
571+
551572
return false;
552573
}
553574

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ TypeChecker::getFragileFunctionKind(const DeclContext *DC) {
5858
return std::make_pair(FragileFunctionKind::Inlinable,
5959
/*treatUsableFromInlineAsPublic=*/true);
6060

61-
if (auto attr = AFD->getAttrs().getAttribute<InlineAttr>())
62-
if (attr->getKind() == InlineKind::Always)
63-
return std::make_pair(FragileFunctionKind::InlineAlways,
64-
/*treatUsableFromInlineAsPublic=*/true);
65-
6661
// If a property or subscript is @inlinable, the accessors are
6762
// @inlinable also.
6863
if (auto accessor = dyn_cast<AccessorDecl>(AFD))

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,6 @@ class TypeChecker final : public LazyResolver {
19561956
/// Used in diagnostic %selects.
19571957
enum class FragileFunctionKind : unsigned {
19581958
Transparent,
1959-
InlineAlways,
19601959
Inlinable,
19611960
DefaultArgument,
19621961
PropertyInitializer

stdlib/public/SDK/GLKit/GLKMath.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// types.
2222

2323
// Do dirty pointer manipulations to index an opaque struct like an array.
24-
@inline(__always)
24+
@inlinable @inline(__always)
2525
public func _indexHomogeneousValue<TTT, T>(_ aggregate: UnsafePointer<TTT>,
2626
_ index: Int) -> T {
2727
return UnsafeRawPointer(aggregate).load(
@@ -31,7 +31,7 @@ public func _indexHomogeneousValue<TTT, T>(_ aggregate: UnsafePointer<TTT>,
3131
%{
3232
def defineSubscript(Type, limit):
3333
return """
34-
public subscript(i: Int) -> Float {{
34+
@inlinable public subscript(i: Int) -> Float {{
3535
@inline(__always)
3636
get {{
3737
precondition(i >= 0, "Negative {0} index out of range")

stdlib/public/core/Array.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ extension Array {
384384
}
385385

386386
@_semantics("array.get_element")
387-
@inline(__always)
387+
@inlinable @inline(__always)
388388
public // @testable
389389
func _getElement(
390390
_ index: Int,
@@ -440,7 +440,7 @@ extension Array: _ArrayProtocol {
440440
@inlinable
441441
public // @testable
442442
var _owner: AnyObject? {
443-
@inline(__always)
443+
@inlinable @inline(__always)
444444
get {
445445
return _buffer.owner
446446
}
@@ -1447,7 +1447,7 @@ extension Array {
14471447
/// method's execution.
14481448
/// - Returns: The return value, if any, of the `body` closure parameter.
14491449
@_semantics("array.withUnsafeMutableBufferPointer")
1450-
@inline(__always) // Performance: This method should get inlined into the
1450+
@inlinable @inline(__always) // Performance: This method should get inlined into the
14511451
// caller such that we can combine the partial apply with the apply in this
14521452
// function saving on allocating a closure context. This becomes unnecessary
14531453
// once we allocate noescape closures on the stack.

stdlib/public/core/ArrayShared.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct _DependenceToken {
2525
/// This function is referenced by the compiler to allocate array literals.
2626
///
2727
/// - Precondition: `storage` is `_ContiguousArrayStorage`.
28-
@inline(__always)
28+
@inlinable @inline(__always)
2929
public // COMPILER_INTRINSIC
3030
func _allocateUninitializedArray<Element>(_ builtinCount: Builtin.Word)
3131
-> (Array<Element>, Builtin.RawPointer) {

0 commit comments

Comments
 (0)