Skip to content

Commit cab61e8

Browse files
committed
[sending] Do not mangle shared into function signatures if they are paired with sending.
I am doing this b/c we are going to ban borrowing sending so that we can leave open that space for further design. In the short term, we need the ability to create +0 sending parameters without messing with mangling. By special casing this, we get what we want. rdar://129116141 (cherry picked from commit a890c60)
1 parent c0a2fcc commit cab61e8

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,8 @@ static ParameterTypeFlags
31423142
getParameterFlagsForMangling(ParameterTypeFlags flags,
31433143
ParamSpecifier defaultSpecifier,
31443144
bool isInRecursion = true) {
3145+
bool initiallySending = flags.isSending();
3146+
31453147
// If we have been recursed into, then remove sending from our flags.
31463148
if (!isInRecursion) {
31473149
flags = flags.withSending(false);
@@ -3153,12 +3155,10 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
31533155
case ParamSpecifier::Default:
31543156
// If the legacy `__shared` or `__owned` modifier was provided, mangle as-is,
31553157
// because we need to maintain compatibility with their existing behavior.
3156-
case ParamSpecifier::LegacyShared:
31573158
case ParamSpecifier::LegacyOwned:
31583159
// `inout` should already be specified in the flags.
31593160
case ParamSpecifier::InOut:
31603161
return flags;
3161-
31623162
case ParamSpecifier::ImplicitlyCopyableConsuming:
31633163
case ParamSpecifier::Consuming:
31643164
case ParamSpecifier::Borrowing:
@@ -3167,6 +3167,16 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
31673167
flags = flags.withOwnershipSpecifier(ParamSpecifier::Default);
31683168
}
31693169
return flags;
3170+
case ParamSpecifier::LegacyShared:
3171+
// If we were originally sending and by default we are borrowing, suppress
3172+
// this and set ownership specifier to default so we do not mangle in
3173+
// __shared.
3174+
//
3175+
// This is a work around in the short term since shared borrow is not
3176+
// supported.
3177+
if (initiallySending && ParamSpecifier::Borrowing == defaultSpecifier)
3178+
return flags.withOwnershipSpecifier(ParamSpecifier::Default);
3179+
return flags;
31703180
}
31713181
}
31723182

test/Concurrency/sending_mangling.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,25 @@ extension SendingProtocol {
8282
// CHECK: sil hidden [ossa] @(extension in sending_mangling):sending_mangling.SendingProtocol.sendingArgWithFunctionSendingResult() -> (sending __owned sending_mangling.NonSendableKlass) -> () : $@convention(method) <Self where Self : SendingProtocol> (@in_guaranteed Self) -> @sil_sending @owned @callee_guaranteed (@sil_sending @owned NonSendableKlass) -> () {
8383
func sendingArgWithFunctionSendingResult() -> sending (sending NonSendableKlass) -> () { fatalError() }
8484
}
85+
86+
// Make sure we only do not mangle in __shared if we are borrowed by default and
87+
// have sending.
88+
//
89+
// CHECK: sil hidden [ossa] @sending_mangling.sendingArgWithShared(sending_mangling.NonSendableKlass) -> () : $@convention(thin) (@sil_sending @guaranteed NonSendableKlass) -> () {
90+
func sendingArgWithShared(_ x: __shared sending NonSendableKlass) {}
91+
92+
// CHECK: sil hidden [ossa] @sending_mangling.argWithShared(__shared sending_mangling.NonSendableKlass) -> () : $@convention(thin) (@guaranteed NonSendableKlass) -> () {
93+
func argWithShared(_ x: __shared NonSendableKlass) {}
94+
95+
struct ConstructorSharedTest {
96+
// Inits take their value at +1, so we need to mangle in shared even if we do
97+
// not mangle in sending itself.
98+
//
99+
// CHECK: sil hidden [ossa] @sending_mangling.ConstructorSharedTest.init(__shared sending_mangling.NonSendableKlass) -> sending_mangling.ConstructorSharedTest : $@convention(method) (@sil_sending @guaranteed NonSendableKlass, @thin ConstructorSharedTest.Type) -> ConstructorSharedTest {
100+
init(_ x: __shared sending NonSendableKlass) {}
101+
102+
// This is a func which takes its parameter at +0 so we should suppress both.
103+
//
104+
// CHECK: sil hidden [ossa] @sending_mangling.ConstructorSharedTest.functionSupressed(sending_mangling.NonSendableKlass) -> () : $@convention(method) (@sil_sending @guaranteed NonSendableKlass, ConstructorSharedTest) -> () {
105+
func functionSupressed(_ x: __shared sending NonSendableKlass) {}
106+
}

test/api-digester/stability-concurrency-abi.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ Func withCheckedContinuation(function:_:) has mangled name changing from '_Concu
9494
// AsyncStream.init(unfolding:onCancel:) uses @_silgen_name to preserve mangling after adding @preconcurrency.
9595
Constructor AsyncStream.init(unfolding:onCancel:) has mangled name changing from 'Swift.AsyncStream.init(unfolding: () async -> Swift.Optional<A>, onCancel: Swift.Optional<@Sendable () -> ()>) -> Swift.AsyncStream<A>' to 'Swift.AsyncStream.init(unfolding: () async -> Swift.Optional<A>, onCancel: Swift.Optional<() -> ()>) -> Swift.AsyncStream<A>'
9696

97+
// We did not change the mangling, we did change from Default to Shared. Both
98+
// took their arg at +0, so there is no actual ABI difference.
99+
Func AsyncStream.Continuation.yield(with:) has parameter 0 changing from Default to Shared
100+
Func AsyncThrowingStream.Continuation.yield(with:) has parameter 0 changing from Default to Shared
101+
97102
// SerialExecutor gained `enqueue(_: __owned Job)`, protocol requirements got default implementations
98103
Func SerialExecutor.enqueue(_:) has been added as a protocol requirement
99104

0 commit comments

Comments
 (0)