Skip to content

Commit 0f6a32f

Browse files
committed
[Concurrency] Adopt stable keyword consuming instead of __owned
1 parent 7f60847 commit 0f6a32f

14 files changed

+94
-16
lines changed

lib/AST/Decl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5335,11 +5335,13 @@ NominalTypeDecl::getExecutorOwnedEnqueueFunction() const {
53355335
continue;
53365336

53375337
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
5338-
if (funcDecl->getParameters()->size() != 1)
5338+
auto params = funcDecl->getParameters();
5339+
if (params->size() != 1)
53395340
continue;
53405341

5341-
auto params = funcDecl->getParameters();
5342-
if (params->get(0)->getSpecifier() == ParamSpecifier::LegacyOwned) { // TODO: make this Consuming
5342+
auto param = params->get(0);
5343+
if (param->getSpecifier() == ParamSpecifier::LegacyOwned ||
5344+
param->getSpecifier() == ParamSpecifier::Consuming) {
53435345
return funcDecl;
53445346
}
53455347
}

stdlib/public/Concurrency/Executor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public protocol Executor: AnyObject, Sendable {
2626

2727
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
2828
@available(SwiftStdlib 5.9, *)
29-
func enqueue(_ job: __owned ExecutorJob)
29+
func enqueue(_ job: consuming ExecutorJob)
3030
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
3131
}
3232

@@ -53,7 +53,7 @@ public protocol SerialExecutor: Executor {
5353
// work-scheduling operation.
5454
@_nonoverride
5555
@available(SwiftStdlib 5.9, *)
56-
func enqueue(_ job: __owned ExecutorJob)
56+
func enqueue(_ job: consuming ExecutorJob)
5757
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
5858

5959
/// Convert this executor value to the optimized form of borrowed
@@ -89,7 +89,7 @@ extension Executor {
8989
self.enqueue(ExecutorJob(job))
9090
}
9191

92-
public func enqueue(_ job: __owned ExecutorJob) {
92+
public func enqueue(_ job: consuming ExecutorJob) {
9393
self.enqueue(UnownedJob(job))
9494
}
9595
}

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct UnownedJob: Sendable {
4545
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4646
/// Create an `UnownedJob` whose lifetime must be managed carefully until it is run exactly once.
4747
@available(SwiftStdlib 5.9, *)
48-
public init(_ job: __owned ExecutorJob) {
48+
public init(_ job: consuming ExecutorJob) {
4949
self.context = job.context
5050
}
5151
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

stdlib/public/Distributed/DistributedDefaultExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal final class DistributedRemoteActorReferenceExecutor: SerialExecutor {
2424
internal init() {}
2525

2626
@inlinable
27-
public func enqueue(_ job: __owned ExecutorJob) {
27+
public func enqueue(_ job: consuming ExecutorJob) {
2828
let jobDescription = job.description
2929
fatalError("Attempted to enqueue \(ExecutorJob.self) (\(jobDescription)) on executor of remote distributed actor reference!")
3030
}

test/Concurrency/Runtime/custom_executors_complex_equality_crash.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class NaiveQueueExecutor: SerialExecutor, CustomStringConvertible {
2323
self.queue = queue
2424
}
2525

26-
public func enqueue(_ job: __owned ExecutorJob) {
26+
public func enqueue(_ job: consuming ExecutorJob) {
2727
let unowned = UnownedJob(job)
2828
queue.sync {
2929
unowned.runSynchronously(on: self.asUnownedSerialExecutor())

test/Concurrency/Runtime/custom_executors_moveOnly_job.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// REQUIRES: concurrency_runtime
1111

1212
final class InlineExecutor: SerialExecutor, CustomStringConvertible {
13-
public func enqueue(_ job: __owned ExecutorJob) {
13+
public func enqueue(_ job: consuming ExecutorJob) {
1414
job.runSynchronously(on: self.asUnownedSerialExecutor())
1515
}
1616

test/Concurrency/Runtime/custom_executors_priority.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// REQUIRES: concurrency_runtime
1111

1212
final class InlineExecutor: SerialExecutor {
13-
public func enqueue(_ job: __owned ExecutorJob) {
13+
public func enqueue(_ job: consuming ExecutorJob) {
1414
print("\(self): enqueue (priority: \(TaskPriority(job.priority)!))")
1515
job.runSynchronously(on: self.asUnownedSerialExecutor())
1616
}

test/Concurrency/Runtime/custom_executors_protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class NaiveQueueExecutor: SpecifiedExecutor, CustomStringConvertible {
3535
self.queue = queue
3636
}
3737

38-
public func enqueue(_ job: __owned ExecutorJob) {
38+
public func enqueue(_ job: consuming ExecutorJob) {
3939
print("\(self): enqueue")
4040
let unowned = UnownedJob(job)
4141
queue.sync {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-concurrency-consuming-job-param) -typecheck -parse-as-library %s -verify
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: libdispatch
5+
6+
// rdar://106849189 move-only types should be supported in freestanding mode
7+
// UNSUPPORTED: freestanding
8+
9+
// UNSUPPORTED: back_deployment_runtime
10+
// REQUIRES: concurrency_runtime
11+
12+
import _Concurrency
13+
14+
final class FakeExecutor: SerialExecutor {
15+
// implements the __owned requirement in "old" SDK:
16+
// func enqueue(_ job: __owned Job)
17+
func enqueue(_ job: __owned ExecutorJob) {}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-concurrency-owned-job-param) -typecheck -parse-as-library %s -verify
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: libdispatch
5+
6+
// rdar://106849189 move-only types should be supported in freestanding mode
7+
// UNSUPPORTED: freestanding
8+
9+
// UNSUPPORTED: back_deployment_runtime
10+
// REQUIRES: concurrency_runtime
11+
12+
import _Concurrency
13+
14+
final class FakeExecutor: SerialExecutor {
15+
// implements the __owned requirement in "old" SDK:
16+
// func enqueue(_ job: __owned Job)
17+
func enqueue(_ job: consuming ExecutorJob) {}
18+
}

test/Concurrency/custom_executor_enqueue_impls.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class OldExecutor: SerialExecutor {
2525
/// That's why we do log the deprecation warning, people should use the move-only version.
2626
final class BothExecutor: SerialExecutor {
2727
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'BothExecutor' to 'Executor' by implementing 'func enqueue(Job)' instead}}
28-
func enqueue(_ job: __owned ExecutorJob) {}
28+
func enqueue(_ job: consuming ExecutorJob) {}
2929

3030
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
3131
UnownedSerialExecutor(ordinary: self)
@@ -45,7 +45,7 @@ final class NoneExecutor: SerialExecutor { // expected-error{{type 'NoneExecutor
4545

4646
/// Just implementing the new signature causes no warnings, good.
4747
final class NewExecutor: SerialExecutor {
48-
func enqueue(_ job: __owned ExecutorJob) {} // no warnings
48+
func enqueue(_ job: consuming ExecutorJob) {} // no warnings
4949

5050
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
5151
UnownedSerialExecutor(ordinary: self)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
// This simulates a pre-Swift5.9 concurrency library with `Job` and `ExecutorJob` not being defined at all.
3+
// This is used to verify missing type handling in the SDK when a latest compiler is used.
4+
5+
@_moveOnly
6+
public struct ExecutorJob {}
7+
8+
public protocol SerialExecutor {
9+
// pretend old SDK with `__owned` param rather than ``
10+
func enqueue(_ job: consuming ExecutorJob)
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
// This simulates a pre-Swift5.9 concurrency library with `Job` and `ExecutorJob` not being defined at all.
3+
// This is used to verify missing type handling in the SDK when a latest compiler is used.
4+
5+
@_moveOnly
6+
public struct ExecutorJob {}
7+
8+
public protocol SerialExecutor {
9+
// pretend old SDK with `__owned` param rather than ``
10+
func enqueue(_ job: __owned ExecutorJob)
11+
}

test/lit.cfg

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,33 @@ config.substitutions.append(('%build-clang-importer-objc-overlays',
616616
# FIXME: BEGIN -enable-source-import hackaround
617617
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job-path',
618618
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
619-
620619
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job-nosource',
621620
'-sdk %r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
622621
# FIXME: END -enable-source-import hackaround
623-
624622
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job',
625623
'-enable-source-import -sdk %r -I %r ' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'),
626624
make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk', 'swift-modules-concurrency-without-job'))))
627625

626+
# FIXME: BEGIN -enable-source-import hackaround
627+
config.substitutions.append(('%clang-importer-sdk-concurrency-owned-job-param-path',
628+
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
629+
config.substitutions.append(('%clang-importer-sdk-concurrency-owned-job-param-nosource',
630+
'-sdk %r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
631+
# FIXME: END -enable-source-import hackaround
632+
config.substitutions.append(('%clang-importer-sdk-concurrency-owned-job-param',
633+
'-enable-source-import -sdk %r -I %r ' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'),
634+
make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk', 'swift-modules-concurrency-owned-job-param'))))
635+
636+
# FIXME: BEGIN -enable-source-import hackaround
637+
config.substitutions.append(('%clang-importer-sdk-concurrency-consuming-job-param-path',
638+
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
639+
config.substitutions.append(('%clang-importer-sdk-concurrency-owned-job-param-nosource',
640+
'-sdk %r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
641+
# FIXME: END -enable-source-import hackaround
642+
config.substitutions.append(('%clang-importer-sdk-concurrency-consuming-job-param',
643+
'-enable-source-import -sdk %r -I %r ' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'),
644+
make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk', 'swift-modules-concurrency-consuming-job-param'))))
645+
628646

629647
# FIXME: BEGIN -enable-source-import hackaround
630648
config.substitutions.append(('%clang-importer-sdk-path',

0 commit comments

Comments
 (0)