From 080d850153b4e37b7ba125ec571645198a3869cd Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Tue, 29 Nov 2022 17:59:00 -0800 Subject: [PATCH] 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 --- lib/Sema/TypeCheckAttr.cpp | 15 +++++---------- test/attr/Inputs/BackDeployHelper.swift | 2 ++ test/attr/attr_backDeploy.swift | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 1a3c84d900a9e..5cc70a66527db 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -4391,21 +4391,16 @@ void AttributeChecker::checkBackDeployAttrs(ArrayRef Attrs) { if (Attrs.empty()) return; - // Diagnose conflicting attributes. @_alwaysEmitIntoClient, @inlinable, and - // @_transparent all conflict with back deployment because they each cause the - // body of a function to be copied into the client under certain conditions - // and would defeat the goal of back deployment, which is to always use the - // ABI version of the declaration when it is available. + // Diagnose conflicting attributes. @_alwaysEmitIntoClient and @_transparent + // conflict with back deployment because they each cause the body of a + // function to always be copied into the client and would defeat the goal of + // back deployment, which is to use the ABI version of the declaration when it + // is available. if (auto *AEICA = D->getAttrs().getAttribute()) { diagnoseAndRemoveAttr(AEICA, diag::attr_incompatible_with_back_deploy, AEICA, D->getDescriptiveKind()); } - if (auto *IA = D->getAttrs().getAttribute()) { - diagnoseAndRemoveAttr(IA, diag::attr_incompatible_with_back_deploy, IA, - D->getDescriptiveKind()); - } - if (auto *TA = D->getAttrs().getAttribute()) { diagnoseAndRemoveAttr(TA, diag::attr_incompatible_with_back_deploy, TA, D->getDescriptiveKind()); diff --git a/test/attr/Inputs/BackDeployHelper.swift b/test/attr/Inputs/BackDeployHelper.swift index c0b65d5a5ab74..257ace9c2e22b 100644 --- a/test/attr/Inputs/BackDeployHelper.swift +++ b/test/attr/Inputs/BackDeployHelper.swift @@ -140,6 +140,7 @@ extension IntArray { @available(BackDeploy 1.0, *) @_backDeploy(before: BackDeploy 2.0) + @inlinable public subscript(_ i: Int) -> Int { get { _values[i] } _modify { yield &_values[i] } @@ -180,6 +181,7 @@ extension ReferenceIntArray { @available(BackDeploy 1.0, *) @_backDeploy(before: BackDeploy 2.0) + @inlinable public final subscript(_ i: Int) -> Int { get { _values[i] } _modify { yield &_values[i] } diff --git a/test/attr/attr_backDeploy.swift b/test/attr/attr_backDeploy.swift index 653ddb0662cec..4b5949eb66d08 100644 --- a/test/attr/attr_backDeploy.swift +++ b/test/attr/attr_backDeploy.swift @@ -243,7 +243,7 @@ public func alwaysEmitIntoClientFunc() {} @available(macOS 11.0, *) @_backDeploy(before: macOS 12.0) -@inlinable // expected-error {{'@inlinable' cannot be applied to a back deployed global function}} +@inlinable // OK public func inlinableFunc() {} @available(macOS 11.0, *)