Skip to content

Commit 080d850

Browse files
committed
Sema: Allow @inlinable on back deployed functions.
Per Swift Evolution feedback, back deployed functions should be allowed to be inlinable, even though this means that the version of the function in the library may not always be exectued when it is otherwise available. Resolves rdar://102792806
1 parent b71f9d0 commit 080d850

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4391,21 +4391,16 @@ void AttributeChecker::checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs) {
43914391
if (Attrs.empty())
43924392
return;
43934393

4394-
// Diagnose conflicting attributes. @_alwaysEmitIntoClient, @inlinable, and
4395-
// @_transparent all conflict with back deployment because they each cause the
4396-
// body of a function to be copied into the client under certain conditions
4397-
// and would defeat the goal of back deployment, which is to always use the
4398-
// ABI version of the declaration when it is available.
4394+
// Diagnose conflicting attributes. @_alwaysEmitIntoClient and @_transparent
4395+
// conflict with back deployment because they each cause the body of a
4396+
// function to always be copied into the client and would defeat the goal of
4397+
// back deployment, which is to use the ABI version of the declaration when it
4398+
// is available.
43994399
if (auto *AEICA = D->getAttrs().getAttribute<AlwaysEmitIntoClientAttr>()) {
44004400
diagnoseAndRemoveAttr(AEICA, diag::attr_incompatible_with_back_deploy,
44014401
AEICA, D->getDescriptiveKind());
44024402
}
44034403

4404-
if (auto *IA = D->getAttrs().getAttribute<InlinableAttr>()) {
4405-
diagnoseAndRemoveAttr(IA, diag::attr_incompatible_with_back_deploy, IA,
4406-
D->getDescriptiveKind());
4407-
}
4408-
44094404
if (auto *TA = D->getAttrs().getAttribute<TransparentAttr>()) {
44104405
diagnoseAndRemoveAttr(TA, diag::attr_incompatible_with_back_deploy, TA,
44114406
D->getDescriptiveKind());

test/attr/Inputs/BackDeployHelper.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ extension IntArray {
140140

141141
@available(BackDeploy 1.0, *)
142142
@_backDeploy(before: BackDeploy 2.0)
143+
@inlinable
143144
public subscript(_ i: Int) -> Int {
144145
get { _values[i] }
145146
_modify { yield &_values[i] }
@@ -180,6 +181,7 @@ extension ReferenceIntArray {
180181

181182
@available(BackDeploy 1.0, *)
182183
@_backDeploy(before: BackDeploy 2.0)
184+
@inlinable
183185
public final subscript(_ i: Int) -> Int {
184186
get { _values[i] }
185187
_modify { yield &_values[i] }

test/attr/attr_backDeploy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public func alwaysEmitIntoClientFunc() {}
243243

244244
@available(macOS 11.0, *)
245245
@_backDeploy(before: macOS 12.0)
246-
@inlinable // expected-error {{'@inlinable' cannot be applied to a back deployed global function}}
246+
@inlinable // OK
247247
public func inlinableFunc() {}
248248

249249
@available(macOS 11.0, *)

0 commit comments

Comments
 (0)