Skip to content

Commit 3e864b2

Browse files
committed
AST: @inline(__always) no longer implies @inlinable
Fixes <rdar://problem/44657000>.
1 parent f1dfdf6 commit 3e864b2

File tree

11 files changed

+10
-53
lines changed

11 files changed

+10
-53
lines changed

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/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
@@ -1955,7 +1955,6 @@ class TypeChecker final : public LazyResolver {
19551955
/// Used in diagnostic %selects.
19561956
enum class FragileFunctionKind : unsigned {
19571957
Transparent,
1958-
InlineAlways,
19591958
Inlinable,
19601959
DefaultArgument,
19611960
PropertyInitializer

test/ParseableInterface/inlinable-function.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,6 @@ public struct Foo: Hashable {
199199
inlinableProperty = 4
200200
}
201201

202-
// CHECK: @inline(__always) [[ATTRS]] func inlineAlwaysMethod() {
203-
// CHECK-NEXT: inlinableProperty = 4
204-
// CHECK-NEXT: }
205-
@inline(__always)
206-
mutating public func inlineAlwaysMethod() {
207-
inlinableProperty = 4
208-
}
209-
210202
// CHECK: public func nonInlinableMethod(){{$}}
211203
// CHECK-NOT: print("Not inlinable")
212204
public func nonInlinableMethod() {

test/SILGen/functions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func noinline_callee() {}
426426
@inline(__always)
427427
func always_inline_callee() {}
428428

429-
// CHECK-LABEL: sil [serialized] [always_inline] @$s9functions27public_always_inline_calleeyyF : $@convention(thin) () -> ()
429+
// CHECK-LABEL: sil [always_inline] @$s9functions27public_always_inline_calleeyyF : $@convention(thin) () -> ()
430430
@inline(__always)
431431
public func public_always_inline_callee() {}
432432

test/SILGen/nested-function-fragility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal func bar() {
4343
public func publicFunc() {}
4444

4545
// CHECK-LABEL: sil [serialized] [always_inline] @$s4main3basyyF
46-
@inline(__always)
46+
@inlinable @inline(__always)
4747
public func bas() {
4848
// CHECK-LABEL: sil shared [serialized] [always_inline] @$s4main3basyyF3zimL_yyF
4949
@inline(__always)

test/SILGen/struct_resilience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ public func functionWithMyResilientTypes(_ s: MySize, f: (MySize) -> MySize) ->
195195
return s.w
196196
}
197197

198-
// CHECK-LABEL: sil [serialized] [always_inline] @$s17struct_resilience26publicInlineAlwaysFunctionySiAA6MySizeVF : $@convention(thin) (@in_guaranteed MySize) -> Int
199-
@inline(__always) public func publicInlineAlwaysFunction(_ s: MySize) -> Int {
198+
// CHECK-LABEL: sil [serialized] @$s17struct_resilience23publicInlinableFunctionySiAA6MySizeVF : $@convention(thin) (@in_guaranteed MySize) -> Int
199+
@inlinable public func publicInlinableFunction(_ s: MySize) -> Int {
200200

201201
// Since the body of a public transparent function might be inlined into
202202
// other resilience domains, we have to use accessors

test/Serialization/Inputs/def_always_inline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inline(__always) public func testAlwaysInline(x: Bool) -> Bool {
1+
@inline(__always) @inlinable public func testAlwaysInline(x: Bool) -> Bool {
22
return x
33
}
44

@@ -7,7 +7,7 @@ public struct AlwaysInlineInitStruct {
77
@usableFromInline
88
var x: Bool
99

10-
@inline(__always)
10+
@inline(__always) @inlinable
1111
public init(x x2: Bool) {
1212
self.x = x2
1313
}

test/attr/attr_inlinable.swift

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public func publicFunction() {}
2020
private struct PrivateStruct {}
2121
// expected-note@-1 3{{struct 'PrivateStruct' is not '@usableFromInline' or public}}
2222
struct InternalStruct {}
23-
// expected-note@-1 4{{struct 'InternalStruct' is not '@usableFromInline' or public}}
23+
// expected-note@-1 3{{struct 'InternalStruct' is not '@usableFromInline' or public}}
2424
@usableFromInline struct VersionedStruct {
2525
@usableFromInline init() {}
2626
}
@@ -79,18 +79,6 @@ public struct Struct {
7979
// expected-error@-1 {{struct 'PrivateStruct' is private and cannot be referenced from an '@inlinable' function}}
8080
}
8181

82-
@inline(__always)
83-
public func publicInlineAlwaysMethod(x: Any) {
84-
struct Nested {}
85-
// expected-error@-1 {{type 'Nested' cannot be nested inside an '@inline(__always)' function}}
86-
87-
switch x {
88-
case is InternalStruct:
89-
// expected-error@-1 {{struct 'InternalStruct' is internal and cannot be referenced from an '@inline(__always)' function}}
90-
_ = ()
91-
}
92-
}
93-
9482
private func privateMethod() {}
9583
// expected-note@-1 {{instance method 'privateMethod()' is not '@usableFromInline' or public}}
9684

@@ -109,13 +97,6 @@ public struct Struct {
10997
// expected-error@-1 {{type 'Nested' cannot be nested inside an '@inlinable' function}}
11098
}
11199

112-
@inline(__always)
113-
@usableFromInline
114-
func versionedInlineAlwaysMethod() {
115-
struct Nested {}
116-
// expected-error@-1 {{type 'Nested' cannot be nested inside an '@inline(__always)' function}}
117-
}
118-
119100
@_transparent
120101
func internalTransparentMethod() {
121102
struct Nested {}

0 commit comments

Comments
 (0)