Skip to content

Commit

Permalink
Merge pull request #78345 from swiftlang/revert-78327-back-deployed-w…
Browse files Browse the repository at this point in the history
…ithout-body

Revert "Sema: Diagnose `@backDeployed` functions with missing bodies in swiftinterfaces"
  • Loading branch information
shahmishal authored Dec 22, 2024
2 parents 192bb33 + aab36f6 commit 55189ba
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 83 deletions.
16 changes: 6 additions & 10 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7570,17 +7570,13 @@ ERROR(cannot_convert_default_value_type_to_argument_type, none,
// MARK: Back deployment
//------------------------------------------------------------------------------

ERROR(attr_incompatible_with_back_deployed,none,
"'%0' cannot be applied to a back deployed %kind1",
(DeclAttribute, const Decl *))

WARNING(back_deployed_opaque_result_not_supported,none,
"'%0' cannot be applied to %kind1 because it has a 'some' return type",
(DeclAttribute, const ValueDecl *))
ERROR(attr_incompatible_with_back_deploy,none,
"'%0' cannot be applied to a back deployed %1",
(DeclAttribute, DescriptiveDeclKind))

ERROR(back_deployed_requires_body,none,
"'%0' requires that %kind1 have a body",
(DeclAttribute, const ValueDecl *))
WARNING(backdeployed_opaque_result_not_supported,none,
"'%0' is unsupported on a %1 with a 'some' return type",
(DeclAttribute, DescriptiveDeclKind))

//------------------------------------------------------------------------------
// MARK: Implicit opening of existential types
Expand Down
47 changes: 20 additions & 27 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4873,13 +4873,13 @@ void AttributeChecker::checkBackDeployedAttrs(
// back deployment, which is to use the ABI version of the declaration when it
// is available.
if (auto *AEICA = D->getAttrs().getAttribute<AlwaysEmitIntoClientAttr>()) {
diagnoseAndRemoveAttr(AEICA, diag::attr_incompatible_with_back_deployed,
AEICA, D);
diagnoseAndRemoveAttr(AEICA, diag::attr_incompatible_with_back_deploy,
AEICA, D->getDescriptiveKind());
}

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

// Only functions, methods, computed properties, and subscripts are
Expand Down Expand Up @@ -4931,9 +4931,19 @@ void AttributeChecker::checkBackDeployedAttrs(
continue;
}

if (auto *VarD = dyn_cast<VarDecl>(D)) {
// There must be a function body to back deploy so for vars we require
// that they be computed in order to allow back deployment.
if (VarD->hasStorageOrWrapsStorage()) {
diagnoseAndRemoveAttr(Attr, diag::attr_not_on_stored_properties, Attr);
continue;
}
}

if (VD->getOpaqueResultTypeDecl()) {
diagnoseAndRemoveAttr(
Attr, diag::back_deployed_opaque_result_not_supported, Attr, VD)
diagnoseAndRemoveAttr(Attr,
diag::backdeployed_opaque_result_not_supported,
Attr, D->getDescriptiveKind())
.warnInSwiftInterface(D->getDeclContext());
continue;
}
Expand All @@ -4950,29 +4960,12 @@ void AttributeChecker::checkBackDeployedAttrs(
continue;
}

// The remaining diagnostics can only be diagnosed for attributes that
// apply to the active platform.
if (Attr != ActiveAttr)
if (Ctx.LangOpts.DisableAvailabilityChecking)
continue;

if (auto *VarD = dyn_cast<VarDecl>(D)) {
// There must be a function body to back deploy so for vars we require
// that they be computed in order to allow back deployment.
if (VarD->hasStorageOrWrapsStorage()) {
diagnoseAndRemoveAttr(Attr, diag::attr_not_on_stored_properties, Attr);
continue;
}
}

if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
if (!AFD->hasBody()) {
diagnoseAndRemoveAttr(Attr, diag::back_deployed_requires_body, Attr,
VD);
continue;
}
}

if (Ctx.LangOpts.DisableAvailabilityChecking)
// Availability conflicts can only be diagnosed for attributes that apply
// to the active platform.
if (Attr != ActiveAttr)
continue;

auto availability =
Expand Down
24 changes: 0 additions & 24 deletions test/ModuleInterface/BackDeployedAttrBad.swiftinterface

This file was deleted.

16 changes: 0 additions & 16 deletions test/ModuleInterface/BackDeployedAttrGood.swiftinterface

This file was deleted.

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

Expand Down
7 changes: 2 additions & 5 deletions test/attr/attr_backDeployed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ public enum CannotBackDeployEnum {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' must not be used on stored properties}}
public var cannotBackDeployTopLevelVar = 79

@backDeployed(before: iOS 15.0) // OK, this can only be diagnosed when compiling for iOS
public var cannotBackDeployTopLevelVarOniOS = 79

@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
extension TopLevelStruct {}

Expand All @@ -269,13 +266,13 @@ public struct ConformsToTopLevelProtocol: TopLevelProtocol {
}

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

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

0 comments on commit 55189ba

Please sign in to comment.