Skip to content

[Concurrency] Drop the cloned code for Embedded around 'any Actor' #76766

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
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
131 changes: 0 additions & 131 deletions stdlib/public/Concurrency/DiscardingTaskGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ public struct DiscardingTaskGroup {
let _: Void? = try await _taskGroupWaitAll(group: _group, bodyError: nil)
}

// Clone the task-creation routines in Embedded Swift so that we don't
// introduce an implicit use of `any Actor`.
#if !$Embedded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the #if !$Embedded branch is the one to remove? It contains the @isolated(any) additions (introduced by commit a86b76a).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks! Fixed.


/// Adds a child task to the group.
///
/// - Parameters:
Expand Down Expand Up @@ -334,133 +330,6 @@ public struct DiscardingTaskGroup {
return true
}

// The Embedded clones of the task-creation routines.
#else

/// Adds a child task to the group.
///
/// - Parameters:
/// - priority: The priority of the operation task.
/// Omit this parameter or pass `.unspecified`
/// to set the child task's priority to the priority of the group.
/// - operation: The operation to execute as part of the task group.
@_alwaysEmitIntoClient
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
#endif
public mutating func addTask(
priority: TaskPriority? = nil,
operation: sending @escaping () async -> Void
) {
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: false,
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
)
#else
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
)
#endif

// Create the task in this group.
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
}

/// Adds a child task to the group, unless the group has been canceled.
///
/// - Parameters:
/// - priority: The priority of the operation task.
/// Omit this parameter or pass `.unspecified`
/// to set the child task's priority to the priority of the group.
/// - operation: The operation to execute as part of the task group.
/// - Returns: `true` if the child task was added to the group;
/// otherwise `false`.
@_alwaysEmitIntoClient
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
#endif
public mutating func addTaskUnlessCancelled(
priority: TaskPriority? = nil,
operation: sending @escaping () async -> Void
) -> Bool {
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)

guard canAdd else {
// the group is cancelled and is not accepting any new work
return false
}
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: false,
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
)
#else
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
)
#endif

// Create the task in this group.
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)

return true
}

@_alwaysEmitIntoClient
public mutating func addTask(
operation: sending @escaping () async -> Void
) {
let flags = taskCreateFlags(
priority: nil, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
)

// Create the task in this group.
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
}

/// Adds a child task to the group, unless the group has been canceled.
///
/// - Parameters:
/// - operation: The operation to execute as part of the task group.
/// - Returns: `true` if the child task was added to the group;
/// otherwise `false`.
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
#endif
@_alwaysEmitIntoClient
public mutating func addTaskUnlessCancelled(
operation: sending @escaping () async -> Void
) -> Bool {
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)

guard canAdd else {
// the group is cancelled and is not accepting any new work
return false
}

let flags = taskCreateFlags(
priority: nil, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
)

// Create the task in this group.
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)

return true
}

#endif // $Embedded

/// A Boolean value that indicates whether the group has any remaining tasks.
///
/// At the start of the body of a `withDiscardingTaskGroup(of:returning:body:)` call,
Expand Down
76 changes: 0 additions & 76 deletions stdlib/public/Concurrency/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -635,25 +635,6 @@ extension Task where Failure == Never {
) {
fatalError("Unavailable in task-to-thread concurrency model.")
}
#elseif $Embedded
@discardableResult
@_alwaysEmitIntoClient
public init(
priority: TaskPriority? = nil,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async -> Success
) {
// Set up the job flags for a new task.
let flags = taskCreateFlags(
priority: priority, isChildTask: false, copyTaskLocals: true,
inheritContext: true, enqueueJob: true,
addPendingGroupTaskUnconditionally: false,
isDiscardingTask: false)

// Create the asynchronous task.
let (task, _) = Builtin.createAsyncTask(flags, operation)

self._task = task
}
#else
/// Runs the given nonthrowing operation asynchronously
/// as part of a new top-level task on behalf of the current actor.
Expand Down Expand Up @@ -717,25 +698,6 @@ extension Task where Failure == Error {
) {
fatalError("Unavailable in task-to-thread concurrency model")
}
#elseif $Embedded
@discardableResult
@_alwaysEmitIntoClient
public init(
priority: TaskPriority? = nil,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async throws -> Success
) {
// Set up the task flags for a new task.
let flags = taskCreateFlags(
priority: priority, isChildTask: false, copyTaskLocals: true,
inheritContext: true, enqueueJob: true,
addPendingGroupTaskUnconditionally: false,
isDiscardingTask: false)

// Create the asynchronous task future.
let (task, _) = Builtin.createAsyncTask(flags, operation)

self._task = task
}
#else
/// Runs the given throwing operation asynchronously
/// as part of a new top-level task on behalf of the current actor.
Expand Down Expand Up @@ -801,25 +763,6 @@ extension Task where Failure == Never {
) -> Task<Success, Failure> {
fatalError("Unavailable in task-to-thread concurrency model")
}
#elseif $Embedded
@discardableResult
@_alwaysEmitIntoClient
public static func detached(
priority: TaskPriority? = nil,
operation: sending @escaping () async -> Success
) -> Task<Success, Failure> {
// Set up the job flags for a new task.
let flags = taskCreateFlags(
priority: priority, isChildTask: false, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: false,
isDiscardingTask: false)

// Create the asynchronous task future.
let (task, _) = Builtin.createAsyncTask(flags, operation)

return Task(task)
}
#else
/// Runs the given nonthrowing operation asynchronously
/// as part of a new top-level task.
Expand Down Expand Up @@ -880,25 +823,6 @@ extension Task where Failure == Error {
) -> Task<Success, Failure> {
fatalError("Unavailable in task-to-thread concurrency model")
}
#elseif $Embedded
@discardableResult
@_alwaysEmitIntoClient
public static func detached(
priority: TaskPriority? = nil,
operation: sending @escaping () async throws -> Success
) -> Task<Success, Failure> {
// Set up the job flags for a new task.
let flags = taskCreateFlags(
priority: priority, isChildTask: false, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: false,
isDiscardingTask: false)

// Create the asynchronous task future.
let (task, _) = Builtin.createAsyncTask(flags, operation)

return Task(task)
}
#else
/// Runs the given throwing operation asynchronously
/// as part of a new top-level task.
Expand Down
59 changes: 1 addition & 58 deletions stdlib/public/Concurrency/TaskGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
self._group = group
}

#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY && !$Embedded
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
/// Adds a child task to the group.
///
/// - Parameters:
Expand Down Expand Up @@ -409,63 +409,6 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
return true
}

#elseif $Embedded

@_alwaysEmitIntoClient
public mutating func addTask(
priority: TaskPriority? = nil,
operation: sending @escaping () async -> ChildTaskResult
) {
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: false,
addPendingGroupTaskUnconditionally: true,
isDiscardingTask: false
)
#else
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: true,
isDiscardingTask: false)
#endif

// Create the task in this group.
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
}

@_alwaysEmitIntoClient
public mutating func addTaskUnlessCancelled(
priority: TaskPriority? = nil,
operation: sending @escaping () async -> ChildTaskResult
) -> Bool {
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)

guard canAdd else {
// the group is cancelled and is not accepting any new work
return false
}
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: false,
addPendingGroupTaskUnconditionally: false,
isDiscardingTask: false)
#else
let flags = taskCreateFlags(
priority: priority, isChildTask: true, copyTaskLocals: false,
inheritContext: false, enqueueJob: true,
addPendingGroupTaskUnconditionally: false,
isDiscardingTask: false)
#endif

// Create the task in this group.
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)

return true
}

#else // if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 5.7, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
Expand Down