Skip to content

Commit 7bec9ac

Browse files
committed
[sending] Replace sending with consuming when suppressing sending from arguments in swiftinterface files.
Previously we would just not print sending. This causes problems since sending implies a +1 parameter and by removing it we convert the parameter to a +0 parameter, breaking ABI. In this commit, I make it so that when we suppress sending from argument parameters, we just replace it with consuming so that we preserve ABI even for callers who do not support sending. rdar://131066640 (cherry picked from commit fdd435a)
1 parent c8aee3c commit 7bec9ac

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3803,8 +3803,19 @@ static void printParameterFlags(ASTPrinter &printer,
38033803
break;
38043804
}
38053805

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

38093820
if (flags.isIsolated()) {
38103821
if (!(param && param->getInterfaceType()->isOptional() &&

test/Concurrency/sending_conditional_suppression.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ public class NonSendableKlass {}
99
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
1010
// CHECK-NEXT: public func transferArgTest(_ x: sending test.NonSendableKlass)
1111
// CHECK-NEXT: #else
12-
// CHECK-NEXT: public func transferArgTest(_ x: test.NonSendableKlass)
12+
// When we suppress, we preserve +1 by marking the parameter as consuming. Otherwise, we
13+
// be breaking ABI.
14+
// CHECK-NEXT: public func transferArgTest(_ x: consuming test.NonSendableKlass)
1315
// CHECK-NEXT: #endif
1416
public func transferArgTest(_ x: sending NonSendableKlass) {}
1517

@@ -23,14 +25,14 @@ public func transferResultTest() -> sending NonSendableKlass { fatalError() }
2325
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
2426
// CHECK-NEXT: public func transferArgAndResultTest(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, _ z: test.NonSendableKlass) -> sending test.NonSendableKlass
2527
// CHECK-NEXT: #else
26-
// CHECK-NEXT: public func transferArgAndResultTest(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, _ z: test.NonSendableKlass) -> test.NonSendableKlass
28+
// CHECK-NEXT: public func transferArgAndResultTest(_ x: test.NonSendableKlass, _ y: consuming test.NonSendableKlass, _ z: test.NonSendableKlass) -> test.NonSendableKlass
2729
// CHECK-NEXT: #endif
2830
public func transferArgAndResultTest(_ x: NonSendableKlass, _ y: sending NonSendableKlass, _ z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
2931

3032
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
3133
// CHECK-NEXT: public func argEmbeddedInType(_ fn: (sending test.NonSendableKlass) -> ())
3234
// CHECK-NEXT: #else
33-
// CHECK-NEXT: public func argEmbeddedInType(_ fn: (test.NonSendableKlass) -> ())
35+
// CHECK-NEXT: public func argEmbeddedInType(_ fn: (consuming test.NonSendableKlass) -> ())
3436
// CHECK-NEXT: #endif
3537
public func argEmbeddedInType(_ fn: (sending NonSendableKlass) -> ()) {}
3638

@@ -44,15 +46,15 @@ public func resultEmbeddedInType(_ fn: () -> sending NonSendableKlass) {}
4446
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
4547
// CHECK-NEXT: public func argAndResultEmbeddedInType(_ fn: (test.NonSendableKlass, sending test.NonSendableKlass, test.NonSendableKlass) -> sending test.NonSendableKlass)
4648
// CHECK-NEXT: #else
47-
// CHECK-NEXT: public func argAndResultEmbeddedInType(_ fn: (test.NonSendableKlass, test.NonSendableKlass, test.NonSendableKlass) -> test.NonSendableKlass)
49+
// CHECK-NEXT: public func argAndResultEmbeddedInType(_ fn: (test.NonSendableKlass, consuming test.NonSendableKlass, test.NonSendableKlass) -> test.NonSendableKlass)
4850
// CHECK-NEXT: #endif
4951
public func argAndResultEmbeddedInType(_ fn: (NonSendableKlass, sending NonSendableKlass, NonSendableKlass) -> sending NonSendableKlass) {}
5052

5153
public class TestInKlass {
5254
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
5355
// CHECK-NEXT: public func testKlassArg(_ x: sending test.NonSendableKlass)
5456
// CHECK-NEXT: #else
55-
// CHECK-NEXT: public func testKlassArg(_ x: test.NonSendableKlass)
57+
// CHECK-NEXT: public func testKlassArg(_ x: consuming test.NonSendableKlass)
5658
// CHECK-NEXT: #endif
5759
public func testKlassArg(_ x: sending NonSendableKlass) { fatalError() }
5860

@@ -66,7 +68,7 @@ public class TestInKlass {
6668
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
6769
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, z: test.NonSendableKlass) -> sending test.NonSendableKlass
6870
// CHECK-NEXT: #else
69-
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
71+
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: consuming test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
7072
// CHECK-NEXT: #endif
7173
public func testKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
7274
}
@@ -75,7 +77,7 @@ public struct TestInStruct {
7577
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
7678
// CHECK-NEXT: public func testKlassArg(_ x: sending test.NonSendableKlass)
7779
// CHECK-NEXT: #else
78-
// CHECK-NEXT: public func testKlassArg(_ x: test.NonSendableKlass)
80+
// CHECK-NEXT: public func testKlassArg(_ x: consuming test.NonSendableKlass)
7981
// CHECK-NEXT: #endif
8082
public func testKlassArg(_ x: sending NonSendableKlass) { fatalError() }
8183

@@ -89,7 +91,7 @@ public struct TestInStruct {
8991
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
9092
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, z: test.NonSendableKlass) -> sending test.NonSendableKlass
9193
// CHECK-NEXT: #else
92-
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
94+
// CHECK-NEXT: public func testKlassArgAndResult(_ x: test.NonSendableKlass, _ y: consuming test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
9395
// CHECK-NEXT: #endif
9496
public func testKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
9597

@@ -112,7 +114,7 @@ public struct TestInStruct {
112114
// CHECK-NEXT: internal func testUsableFromInlineKlassArg(_ x: sending test.NonSendableKlass)
113115
// CHECK-NEXT: #else
114116
// CHECK-NEXT: @usableFromInline
115-
// CHECK-NEXT: internal func testUsableFromInlineKlassArg(_ x: test.NonSendableKlass)
117+
// CHECK-NEXT: internal func testUsableFromInlineKlassArg(_ x: consuming test.NonSendableKlass)
116118
// CHECK-NEXT: #endif
117119
@usableFromInline func testUsableFromInlineKlassArg(_ x: sending NonSendableKlass) { fatalError() }
118120

@@ -131,7 +133,7 @@ public struct TestInStruct {
131133
// CHECK-NEXT: internal func testUsableFromInlineKlassArgAndResult(_ x: test.NonSendableKlass, _ y: sending test.NonSendableKlass, z: test.NonSendableKlass) -> sending test.NonSendableKlass
132134
// CHECK-NEXT: #else
133135
// CHECK-NEXT: @usableFromInline
134-
// CHECK-NEXT: internal func testUsableFromInlineKlassArgAndResult(_ x: test.NonSendableKlass, _ y: test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
136+
// CHECK-NEXT: internal func testUsableFromInlineKlassArgAndResult(_ x: test.NonSendableKlass, _ y: consuming test.NonSendableKlass, z: test.NonSendableKlass) -> test.NonSendableKlass
135137
// CHECK-NEXT: #endif
136138
@usableFromInline
137139
func testUsableFromInlineKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
@@ -159,7 +161,7 @@ public struct TestInStruct {
159161
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
160162
// CHECK-NEXT: public var publicVarFieldFunctionArg: (sending test.NonSendableKlass) -> ()
161163
// CHECK-NEXT: #else
162-
// CHECK-NEXT: public var publicVarFieldFunctionArg: (test.NonSendableKlass) -> ()
164+
// CHECK-NEXT: public var publicVarFieldFunctionArg: (consuming test.NonSendableKlass) -> ()
163165
// CHECK-NEXT: #endif
164166
public var publicVarFieldFunctionArg: (sending NonSendableKlass) -> ()
165167

@@ -168,15 +170,15 @@ public struct TestInStruct {
168170
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (sending test.NonSendableKlass) -> ()
169171
// CHECK-NEXT: #else
170172
// CHECK-NEXT: @usableFromInline
171-
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (test.NonSendableKlass) -> ()
173+
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (consuming test.NonSendableKlass) -> ()
172174
// CHECK-NEXT: #endif
173175
@usableFromInline
174176
var internalVarFieldFunctionArg: (sending NonSendableKlass) -> ()
175177

176178
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
177179
// CHECK-NEXT: public let publicLetFieldFunctionArg: (sending test.NonSendableKlass) -> ()
178180
// CHECK-NEXT: #else
179-
// CHECK-NEXT: public let publicLetFieldFunctionArg: (test.NonSendableKlass) -> ()
181+
// CHECK-NEXT: public let publicLetFieldFunctionArg: (consuming test.NonSendableKlass) -> ()
180182
// CHECK-NEXT: #endif
181183
public let publicLetFieldFunctionArg: (sending NonSendableKlass) -> ()
182184

@@ -185,7 +187,7 @@ public struct TestInStruct {
185187
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (sending test.NonSendableKlass) -> ()
186188
// CHECK-NEXT: #else
187189
// CHECK-NEXT: @usableFromInline
188-
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (test.NonSendableKlass) -> ()
190+
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (consuming test.NonSendableKlass) -> ()
189191
// CHECK-NEXT: #endif
190192
@usableFromInline
191193
let internalLetFieldFunctionArg: (sending NonSendableKlass) -> ()
@@ -226,7 +228,7 @@ public struct TestInStruct {
226228
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 26
227229
// CHECK-NEXT: public var publicGlobal: (sending test.NonSendableKlass) -> ()
228230
// CHECK-NEXT: #else
229-
// CHECK-NEXT: public var publicGlobal: (test.NonSendableKlass) -> ()
231+
// CHECK-NEXT: public var publicGlobal: (consuming test.NonSendableKlass) -> ()
230232
// CHECK-NEXT: #endif
231233
public var publicGlobal: (sending NonSendableKlass) -> () = { x in fatalError() }
232234

@@ -235,7 +237,7 @@ public var publicGlobal: (sending NonSendableKlass) -> () = { x in fatalError()
235237
// CHECK-NEXT: internal var usableFromInlineGlobal: (sending test.NonSendableKlass) -> ()
236238
// CHECK-NEXT: #else
237239
// CHECK-NEXT: @usableFromInline
238-
// CHECK-NEXT: internal var usableFromInlineGlobal: (test.NonSendableKlass) -> ()
240+
// CHECK-NEXT: internal var usableFromInlineGlobal: (consuming test.NonSendableKlass) -> ()
239241
// CHECK-NEXT: #endif
240242
@usableFromInline
241243
internal var usableFromInlineGlobal: (sending NonSendableKlass) -> () = { x in fatalError() }

0 commit comments

Comments
 (0)