Skip to content

[Concurrency] Un-deprecate enqueue(UnownedJob) for easier adoption #69532

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 1 commit into from
Nov 1, 2023
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
4 changes: 0 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -6935,10 +6935,6 @@ WARNING(hashvalue_implementation,Deprecation,
"conform type %0 to 'Hashable' by implementing 'hash(into:)' instead",
(Type))

WARNING(executor_enqueue_deprecated_unowned_implementation,Deprecation,
"'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; "
"conform type %0 to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead",
(Type))
WARNING(executor_enqueue_deprecated_owned_job_implementation,Deprecation,
"'Executor.enqueue(Job)' is deprecated as a protocol requirement; "
"conform type %0 to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead",
Expand Down
12 changes: 4 additions & 8 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,14 +1459,10 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
}
}

// Old UnownedJob based impl is present, warn about it suggesting the new protocol requirement.
if (canRemoveOldDecls && unownedEnqueueWitnessDecl) {
if (!isStdlibDefaultImplDecl(unownedEnqueueWitnessDecl)) {
diags.diagnose(unownedEnqueueWitnessDecl->getLoc(),
diag::executor_enqueue_deprecated_unowned_implementation,
nominalTy);
}
}
// We specifically do allow the old UnownedJob implementation to be present.
// In order to ease migration and compatibility for libraries which remain compatible with old Swift versions,
// and would be getting this warning in situations they cannot address it.

// Old Job based impl is present, warn about it suggesting the new protocol requirement.
if (legacyMoveOnlyEnqueueWitnessDecl) {
if (!isStdlibDefaultImplDecl(legacyMoveOnlyEnqueueWitnessDecl)) {
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/Concurrency/Executor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public protocol Executor: AnyObject, Sendable {
// Do not deprecate the UnownedJob enqueue in that configuration just yet - as we cannot introduce the replacements.
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 5.1, *)
@available(*, deprecated, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
func enqueue(_ job: UnownedJob)

Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/custom_executor_enqueue_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class BothExecutorOldStdlib: SerialExecutor {
/// that it can be dropped.
@available(SwiftStdlib 5.9, *)
final class BothExecutorNewStdlib: SerialExecutor {
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'BothExecutorNewStdlib' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
func enqueue(_ job: UnownedJob) {} // no warning, we're not deprecating the UnownedJob enqueue method yet

func enqueue(_ job: __owned ExecutorJob) {}

Expand All @@ -51,7 +51,7 @@ final class BothExecutorNewStdlib: SerialExecutor {

@available(SwiftStdlib 5.9, *)
final class TripleExecutor: SerialExecutor {
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'TripleExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
func enqueue(_ job: UnownedJob) {} // no warning, we're not deprecating the UnownedJob enqueue method yet

// expected-warning@+2{{'Job' is deprecated: renamed to 'ExecutorJob'}}
// expected-note@+1{{use 'ExecutorJob' instead}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


extension Executor {
func enqueue(_ job: UnownedJob) { // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'NoneExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
func enqueue(_ job: UnownedJob) { // no warning, we don't deprecate this just yet. It was deprecated in 5.9.0 but we undid this.
fatalError()
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/custom_executor_enqueue_impls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// We keep support for them, but also log a deprecation warning that they should move to the new signature.
final class OldExecutor: SerialExecutor {
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'OldExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
func enqueue(_ job: UnownedJob) {} // no warning, we're not deprecating the UnownedJob enqueue method yet

func asUnownedSerialExecutor() -> UnownedSerialExecutor {
UnownedSerialExecutor(ordinary: self)
Expand All @@ -26,7 +26,7 @@ final class OldExecutor: SerialExecutor {
///
/// That's why we do log the deprecation warning, people should use the move-only version.
final class BothExecutor: SerialExecutor {
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'BothExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
func enqueue(_ job: UnownedJob) {} // no warning, we're not deprecating the UnownedJob enqueue method yet

func enqueue(_ job: __owned ExecutorJob) {}

Expand All @@ -37,7 +37,7 @@ final class BothExecutor: SerialExecutor {

/// For now we must keep all 3 implementation kinds and warn about deprecated ones
final class TripleExecutor: SerialExecutor {
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'TripleExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
func enqueue(_ job: UnownedJob) {} // no warning, we're not deprecating the UnownedJob enqueue method yet

// expected-warning@+2{{'Job' is deprecated: renamed to 'ExecutorJob'}}
// expected-note@+1{{use 'ExecutorJob' instead}}
Expand Down