Skip to content

[6.0][sending] Replace sending with __owned when suppressing sending from arguments in swiftinterface files. #75153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3803,8 +3803,19 @@ static void printParameterFlags(ASTPrinter &printer,
break;
}

if (!options.SuppressSendingArgsAndResults && flags.isSending())
printer.printAttrName("sending ");
if (flags.isSending()) {
if (!options.SuppressSendingArgsAndResults) {
printer.printAttrName("sending ");
} else if (flags.getOwnershipSpecifier() ==
ParamSpecifier::ImplicitlyCopyableConsuming) {
// Ok. We are suppressing sending. If our ownership specifier was
// originally implicitly copyable consuming our argument was being passed
// at +1. By not printing sending, we would be changing the API
// potentially to take the parameter at +0 instead of +1. To work around
// this, print out consuming so that we preserve the +1 parameter.
printer.printKeyword("__owned", options, " ");
}
}

if (flags.isIsolated()) {
if (!(param && param->getInterfaceType()->isOptional() &&
Expand Down
34 changes: 18 additions & 16 deletions test/Concurrency/sending_conditional_suppression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class NonSendableKlass {}
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func transferArgTest(_ x: sending test.NonSendableKlass)
// CHECK-NEXT: #else
// CHECK-NEXT: public func transferArgTest(_ x: test.NonSendableKlass)
// When we suppress, we preserve +1 by marking the parameter as __owned. Otherwise, we
// be breaking ABI.
// CHECK-NEXT: public func transferArgTest(_ x: __owned test.NonSendableKlass)
// CHECK-NEXT: #endif
public func transferArgTest(_ x: sending NonSendableKlass) {}

Expand All @@ -23,14 +25,14 @@ public func transferResultTest() -> sending NonSendableKlass { fatalError() }
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func transferArgAndResultTest(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, _ z: test.NonSendableKlass) -> sending test.NonSendableKlass
// CHECK-NEXT: #else
// CHECK-NEXT: public func transferArgAndResultTest(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, _ z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: public func transferArgAndResultTest(_ x: test.NonSendableKlass, _ y: __owned test.NonSendableKlass, _ z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: #endif
public func transferArgAndResultTest(_ x: NonSendableKlass, _ y: sending NonSendableKlass, _ z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }

// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func argEmbeddedInType(_ fn: (sending test.NonSendableKlass) -> ())
// CHECK-NEXT: #else
// CHECK-NEXT: public func argEmbeddedInType(_ fn: (test.NonSendableKlass) -> ())
// CHECK-NEXT: public func argEmbeddedInType(_ fn: (__owned test.NonSendableKlass) -> ())
// CHECK-NEXT: #endif
public func argEmbeddedInType(_ fn: (sending NonSendableKlass) -> ()) {}

Expand All @@ -44,15 +46,15 @@ public func resultEmbeddedInType(_ fn: () -> sending NonSendableKlass) {}
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func argAndResultEmbeddedInType(_ fn: (test.NonSendableKlass, sending test.NonSendableKlass, test.NonSendableKlass) -> sending test.NonSendableKlass)
// CHECK-NEXT: #else
// CHECK-NEXT: public func argAndResultEmbeddedInType(_ fn: (test.NonSendableKlass, test.NonSendableKlass, test.NonSendableKlass) -> test.NonSendableKlass)
// CHECK-NEXT: public func argAndResultEmbeddedInType(_ fn: (test.NonSendableKlass, __owned test.NonSendableKlass, test.NonSendableKlass) -> test.NonSendableKlass)
// CHECK-NEXT: #endif
public func argAndResultEmbeddedInType(_ fn: (NonSendableKlass, sending NonSendableKlass, NonSendableKlass) -> sending NonSendableKlass) {}

public class TestInKlass {
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func testKlassArg(_ x: sending test.NonSendableKlass)
// CHECK-NEXT: #else
// CHECK-NEXT: public func testKlassArg(_ x: test.NonSendableKlass)
// CHECK-NEXT: public func testKlassArg(_ x: __owned test.NonSendableKlass)
// CHECK-NEXT: #endif
public func testKlassArg(_ x: sending NonSendableKlass) { fatalError() }

Expand All @@ -66,7 +68,7 @@ public class TestInKlass {
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, z: test.NonSendableKlass) -> sending test.NonSendableKlass
// CHECK-NEXT: #else
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: __owned test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: #endif
public func testKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
}
Expand All @@ -75,7 +77,7 @@ public struct TestInStruct {
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func testKlassArg(_ x: sending test.NonSendableKlass)
// CHECK-NEXT: #else
// CHECK-NEXT: public func testKlassArg(_ x: test.NonSendableKlass)
// CHECK-NEXT: public func testKlassArg(_ x: __owned test.NonSendableKlass)
// CHECK-NEXT: #endif
public func testKlassArg(_ x: sending NonSendableKlass) { fatalError() }

Expand All @@ -89,7 +91,7 @@ public struct TestInStruct {
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, z: test.NonSendableKlass) -> sending test.NonSendableKlass
// CHECK-NEXT: #else
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: __owned test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: #endif
public func testKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }

Expand All @@ -112,7 +114,7 @@ public struct TestInStruct {
// CHECK-NEXT: internal func testUsableFromInlineKlassArg(_ x: sending test.NonSendableKlass)
// CHECK-NEXT: #else
// CHECK-NEXT: @usableFromInline
// CHECK-NEXT: internal func testUsableFromInlineKlassArg(_ x: test.NonSendableKlass)
// CHECK-NEXT: internal func testUsableFromInlineKlassArg(_ x: __owned test.NonSendableKlass)
// CHECK-NEXT: #endif
@usableFromInline func testUsableFromInlineKlassArg(_ x: sending NonSendableKlass) { fatalError() }

Expand All @@ -131,7 +133,7 @@ public struct TestInStruct {
// CHECK-NEXT: internal func testUsableFromInlineKlassArgAndResult(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, z: test.NonSendableKlass) -> sending test.NonSendableKlass
// CHECK-NEXT: #else
// CHECK-NEXT: @usableFromInline
// CHECK-NEXT: internal func testUsableFromInlineKlassArgAndResult(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: internal func testUsableFromInlineKlassArgAndResult(_ x: test.NonSendableKlass, _ y: __owned test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
// CHECK-NEXT: #endif
@usableFromInline
func testUsableFromInlineKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
Expand Down Expand Up @@ -159,7 +161,7 @@ public struct TestInStruct {
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public var publicVarFieldFunctionArg: (sending test.NonSendableKlass) -> ()
// CHECK-NEXT: #else
// CHECK-NEXT: public var publicVarFieldFunctionArg: (test.NonSendableKlass) -> ()
// CHECK-NEXT: public var publicVarFieldFunctionArg: (__owned test.NonSendableKlass) -> ()
// CHECK-NEXT: #endif
public var publicVarFieldFunctionArg: (sending NonSendableKlass) -> ()

Expand All @@ -168,15 +170,15 @@ public struct TestInStruct {
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (sending test.NonSendableKlass) -> ()
// CHECK-NEXT: #else
// CHECK-NEXT: @usableFromInline
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (test.NonSendableKlass) -> ()
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (__owned test.NonSendableKlass) -> ()
// CHECK-NEXT: #endif
@usableFromInline
var internalVarFieldFunctionArg: (sending NonSendableKlass) -> ()

// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
// CHECK-NEXT: public let publicLetFieldFunctionArg: (sending test.NonSendableKlass) -> ()
// CHECK-NEXT: #else
// CHECK-NEXT: public let publicLetFieldFunctionArg: (test.NonSendableKlass) -> ()
// CHECK-NEXT: public let publicLetFieldFunctionArg: (__owned test.NonSendableKlass) -> ()
// CHECK-NEXT: #endif
public let publicLetFieldFunctionArg: (sending NonSendableKlass) -> ()

Expand All @@ -185,7 +187,7 @@ public struct TestInStruct {
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (sending test.NonSendableKlass) -> ()
// CHECK-NEXT: #else
// CHECK-NEXT: @usableFromInline
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (test.NonSendableKlass) -> ()
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (__owned test.NonSendableKlass) -> ()
// CHECK-NEXT: #endif
@usableFromInline
let internalLetFieldFunctionArg: (sending NonSendableKlass) -> ()
Expand Down Expand Up @@ -226,7 +228,7 @@ public struct TestInStruct {
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 26
// CHECK-NEXT: public var publicGlobal: (sending test.NonSendableKlass) -> ()
// CHECK-NEXT: #else
// CHECK-NEXT: public var publicGlobal: (test.NonSendableKlass) -> ()
// CHECK-NEXT: public var publicGlobal: (__owned test.NonSendableKlass) -> ()
// CHECK-NEXT: #endif
public var publicGlobal: (sending NonSendableKlass) -> () = { x in fatalError() }

Expand All @@ -235,7 +237,7 @@ public var publicGlobal: (sending NonSendableKlass) -> () = { x in fatalError()
// CHECK-NEXT: internal var usableFromInlineGlobal: (sending test.NonSendableKlass) -> ()
// CHECK-NEXT: #else
// CHECK-NEXT: @usableFromInline
// CHECK-NEXT: internal var usableFromInlineGlobal: (test.NonSendableKlass) -> ()
// CHECK-NEXT: internal var usableFromInlineGlobal: (__owned test.NonSendableKlass) -> ()
// CHECK-NEXT: #endif
@usableFromInline
internal var usableFromInlineGlobal: (sending NonSendableKlass) -> () = { x in fatalError() }