Skip to content

Commit 55189ba

Browse files
authored
Merge pull request swiftlang#78345 from swiftlang/revert-78327-back-deployed-without-body
Revert "Sema: Diagnose `@backDeployed` functions with missing bodies in swiftinterfaces"
2 parents 192bb33 + aab36f6 commit 55189ba

File tree

6 files changed

+29
-83
lines changed

6 files changed

+29
-83
lines changed

include/swift/AST/DiagnosticsSema.def

+6-10
Original file line numberDiff line numberDiff line change
@@ -7570,17 +7570,13 @@ ERROR(cannot_convert_default_value_type_to_argument_type, none,
75707570
// MARK: Back deployment
75717571
//------------------------------------------------------------------------------
75727572

7573-
ERROR(attr_incompatible_with_back_deployed,none,
7574-
"'%0' cannot be applied to a back deployed %kind1",
7575-
(DeclAttribute, const Decl *))
7576-
7577-
WARNING(back_deployed_opaque_result_not_supported,none,
7578-
"'%0' cannot be applied to %kind1 because it has a 'some' return type",
7579-
(DeclAttribute, const ValueDecl *))
7573+
ERROR(attr_incompatible_with_back_deploy,none,
7574+
"'%0' cannot be applied to a back deployed %1",
7575+
(DeclAttribute, DescriptiveDeclKind))
75807576

7581-
ERROR(back_deployed_requires_body,none,
7582-
"'%0' requires that %kind1 have a body",
7583-
(DeclAttribute, const ValueDecl *))
7577+
WARNING(backdeployed_opaque_result_not_supported,none,
7578+
"'%0' is unsupported on a %1 with a 'some' return type",
7579+
(DeclAttribute, DescriptiveDeclKind))
75847580

75857581
//------------------------------------------------------------------------------
75867582
// MARK: Implicit opening of existential types

lib/Sema/TypeCheckAttr.cpp

+20-27
Original file line numberDiff line numberDiff line change
@@ -4873,13 +4873,13 @@ void AttributeChecker::checkBackDeployedAttrs(
48734873
// back deployment, which is to use the ABI version of the declaration when it
48744874
// is available.
48754875
if (auto *AEICA = D->getAttrs().getAttribute<AlwaysEmitIntoClientAttr>()) {
4876-
diagnoseAndRemoveAttr(AEICA, diag::attr_incompatible_with_back_deployed,
4877-
AEICA, D);
4876+
diagnoseAndRemoveAttr(AEICA, diag::attr_incompatible_with_back_deploy,
4877+
AEICA, D->getDescriptiveKind());
48784878
}
48794879

48804880
if (auto *TA = D->getAttrs().getAttribute<TransparentAttr>()) {
4881-
diagnoseAndRemoveAttr(TA, diag::attr_incompatible_with_back_deployed, TA,
4882-
D);
4881+
diagnoseAndRemoveAttr(TA, diag::attr_incompatible_with_back_deploy, TA,
4882+
D->getDescriptiveKind());
48834883
}
48844884

48854885
// Only functions, methods, computed properties, and subscripts are
@@ -4931,9 +4931,19 @@ void AttributeChecker::checkBackDeployedAttrs(
49314931
continue;
49324932
}
49334933

4934+
if (auto *VarD = dyn_cast<VarDecl>(D)) {
4935+
// There must be a function body to back deploy so for vars we require
4936+
// that they be computed in order to allow back deployment.
4937+
if (VarD->hasStorageOrWrapsStorage()) {
4938+
diagnoseAndRemoveAttr(Attr, diag::attr_not_on_stored_properties, Attr);
4939+
continue;
4940+
}
4941+
}
4942+
49344943
if (VD->getOpaqueResultTypeDecl()) {
4935-
diagnoseAndRemoveAttr(
4936-
Attr, diag::back_deployed_opaque_result_not_supported, Attr, VD)
4944+
diagnoseAndRemoveAttr(Attr,
4945+
diag::backdeployed_opaque_result_not_supported,
4946+
Attr, D->getDescriptiveKind())
49374947
.warnInSwiftInterface(D->getDeclContext());
49384948
continue;
49394949
}
@@ -4950,29 +4960,12 @@ void AttributeChecker::checkBackDeployedAttrs(
49504960
continue;
49514961
}
49524962

4953-
// The remaining diagnostics can only be diagnosed for attributes that
4954-
// apply to the active platform.
4955-
if (Attr != ActiveAttr)
4963+
if (Ctx.LangOpts.DisableAvailabilityChecking)
49564964
continue;
49574965

4958-
if (auto *VarD = dyn_cast<VarDecl>(D)) {
4959-
// There must be a function body to back deploy so for vars we require
4960-
// that they be computed in order to allow back deployment.
4961-
if (VarD->hasStorageOrWrapsStorage()) {
4962-
diagnoseAndRemoveAttr(Attr, diag::attr_not_on_stored_properties, Attr);
4963-
continue;
4964-
}
4965-
}
4966-
4967-
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
4968-
if (!AFD->hasBody()) {
4969-
diagnoseAndRemoveAttr(Attr, diag::back_deployed_requires_body, Attr,
4970-
VD);
4971-
continue;
4972-
}
4973-
}
4974-
4975-
if (Ctx.LangOpts.DisableAvailabilityChecking)
4966+
// Availability conflicts can only be diagnosed for attributes that apply
4967+
// to the active platform.
4968+
if (Attr != ActiveAttr)
49764969
continue;
49774970

49784971
auto availability =

test/ModuleInterface/BackDeployedAttrBad.swiftinterface

-24
This file was deleted.

test/ModuleInterface/BackDeployedAttrGood.swiftinterface

-16
This file was deleted.

test/Serialization/ignore-opaque-underlying-type-back-deploy.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct EV : V {
5757
@available(SwiftStdlib 5.1, *)
5858
public extension V {
5959
// CHECK: Loading underlying information for opaque type of 'backdeployedOpaqueFunc()'
60-
@backDeployed(before: SwiftStdlib 5.1) // expected-warning 4 {{'@backDeployed' cannot be applied to instance method 'backdeployedOpaqueFunc()' because it has a 'some' return type}}
60+
@backDeployed(before: SwiftStdlib 5.1) // expected-warning 4 {{'@backDeployed' is unsupported on a instance method with a 'some' return type}}
6161
func backdeployedOpaqueFunc() -> some V { EV() }
6262
}
6363

test/attr/attr_backDeployed.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ public enum CannotBackDeployEnum {
251251
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' must not be used on stored properties}}
252252
public var cannotBackDeployTopLevelVar = 79
253253

254-
@backDeployed(before: iOS 15.0) // OK, this can only be diagnosed when compiling for iOS
255-
public var cannotBackDeployTopLevelVarOniOS = 79
256-
257254
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
258255
extension TopLevelStruct {}
259256

@@ -269,13 +266,13 @@ public struct ConformsToTopLevelProtocol: TopLevelProtocol {
269266
}
270267

271268
@available(SwiftStdlib 5.1, *)
272-
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' cannot be applied to var 'cannotBackDeployVarWithOpaqueResultType' because it has a 'some' return type}}
269+
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' is unsupported on a var with a 'some' return type}}
273270
public var cannotBackDeployVarWithOpaqueResultType: some TopLevelProtocol {
274271
return ConformsToTopLevelProtocol()
275272
}
276273

277274
@available(SwiftStdlib 5.1, *)
278-
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' cannot be applied to global function 'cannotBackDeployFuncWithOpaqueResultType()' because it has a 'some' return type}}
275+
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' is unsupported on a global function with a 'some' return type}}
279276
public func cannotBackDeployFuncWithOpaqueResultType() -> some TopLevelProtocol {
280277
return ConformsToTopLevelProtocol()
281278
}

0 commit comments

Comments
 (0)