Skip to content

Commit 920f338

Browse files
committed
[Concurrency] Adopt stable keyword consuming instead of __owned
1 parent 71e71be commit 920f338

File tree

13 files changed

+93
-15
lines changed

13 files changed

+93
-15
lines changed

lib/AST/Decl.cpp

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

53255325
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
5326-
if (funcDecl->getParameters()->size() != 1)
5326+
auto params = funcDecl->getParameters();
5327+
if (params->size() != 1)
53275328
continue;
53285329

5329-
auto params = funcDecl->getParameters();
5330-
if (params->get(0)->getSpecifier() == ParamSpecifier::LegacyOwned) { // TODO: make this Consuming
5330+
auto param = params->get(0);
5331+
if (param->getSpecifier() == ParamSpecifier::LegacyOwned ||
5332+
param->getSpecifier() == ParamSpecifier::Consuming) {
53315333
return funcDecl;
53325334
}
53335335
}

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/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 \(Job.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
@@ -611,15 +611,33 @@ config.substitutions.append(('%build-clang-importer-objc-overlays',
611611
# FIXME: BEGIN -enable-source-import hackaround
612612
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job-path',
613613
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
614-
615614
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job-nosource',
616615
'-sdk %r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
617616
# FIXME: END -enable-source-import hackaround
618-
619617
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job',
620618
'-enable-source-import -sdk %r -I %r ' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'),
621619
make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk', 'swift-modules-concurrency-without-job'))))
622620

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

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

0 commit comments

Comments
 (0)