Skip to content

Commit 4b68c3f

Browse files
authored
Merge pull request #76766 from kubamracek/embedded-dont-avoid-any-actor
[Concurrency] Drop the cloned code for Embedded around 'any Actor'
2 parents cab765e + 9b56ea0 commit 4b68c3f

File tree

3 files changed

+1
-265
lines changed

3 files changed

+1
-265
lines changed

stdlib/public/Concurrency/DiscardingTaskGroup.swift

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ public struct DiscardingTaskGroup {
184184
let _: Void? = try await _taskGroupWaitAll(group: _group, bodyError: nil)
185185
}
186186

187-
// Clone the task-creation routines in Embedded Swift so that we don't
188-
// introduce an implicit use of `any Actor`.
189-
#if !$Embedded
190-
191187
/// Adds a child task to the group.
192188
///
193189
/// - Parameters:
@@ -334,133 +330,6 @@ public struct DiscardingTaskGroup {
334330
return true
335331
}
336332

337-
// The Embedded clones of the task-creation routines.
338-
#else
339-
340-
/// Adds a child task to the group.
341-
///
342-
/// - Parameters:
343-
/// - priority: The priority of the operation task.
344-
/// Omit this parameter or pass `.unspecified`
345-
/// to set the child task's priority to the priority of the group.
346-
/// - operation: The operation to execute as part of the task group.
347-
@_alwaysEmitIntoClient
348-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
349-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
350-
#endif
351-
public mutating func addTask(
352-
priority: TaskPriority? = nil,
353-
operation: sending @escaping () async -> Void
354-
) {
355-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
356-
let flags = taskCreateFlags(
357-
priority: priority, isChildTask: true, copyTaskLocals: false,
358-
inheritContext: false, enqueueJob: false,
359-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
360-
)
361-
#else
362-
let flags = taskCreateFlags(
363-
priority: priority, isChildTask: true, copyTaskLocals: false,
364-
inheritContext: false, enqueueJob: true,
365-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
366-
)
367-
#endif
368-
369-
// Create the task in this group.
370-
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
371-
}
372-
373-
/// Adds a child task to the group, unless the group has been canceled.
374-
///
375-
/// - Parameters:
376-
/// - priority: The priority of the operation task.
377-
/// Omit this parameter or pass `.unspecified`
378-
/// to set the child task's priority to the priority of the group.
379-
/// - operation: The operation to execute as part of the task group.
380-
/// - Returns: `true` if the child task was added to the group;
381-
/// otherwise `false`.
382-
@_alwaysEmitIntoClient
383-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
384-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
385-
#endif
386-
public mutating func addTaskUnlessCancelled(
387-
priority: TaskPriority? = nil,
388-
operation: sending @escaping () async -> Void
389-
) -> Bool {
390-
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)
391-
392-
guard canAdd else {
393-
// the group is cancelled and is not accepting any new work
394-
return false
395-
}
396-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
397-
let flags = taskCreateFlags(
398-
priority: priority, isChildTask: true, copyTaskLocals: false,
399-
inheritContext: false, enqueueJob: false,
400-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
401-
)
402-
#else
403-
let flags = taskCreateFlags(
404-
priority: priority, isChildTask: true, copyTaskLocals: false,
405-
inheritContext: false, enqueueJob: true,
406-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
407-
)
408-
#endif
409-
410-
// Create the task in this group.
411-
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
412-
413-
return true
414-
}
415-
416-
@_alwaysEmitIntoClient
417-
public mutating func addTask(
418-
operation: sending @escaping () async -> Void
419-
) {
420-
let flags = taskCreateFlags(
421-
priority: nil, isChildTask: true, copyTaskLocals: false,
422-
inheritContext: false, enqueueJob: true,
423-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
424-
)
425-
426-
// Create the task in this group.
427-
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
428-
}
429-
430-
/// Adds a child task to the group, unless the group has been canceled.
431-
///
432-
/// - Parameters:
433-
/// - operation: The operation to execute as part of the task group.
434-
/// - Returns: `true` if the child task was added to the group;
435-
/// otherwise `false`.
436-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
437-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
438-
#endif
439-
@_alwaysEmitIntoClient
440-
public mutating func addTaskUnlessCancelled(
441-
operation: sending @escaping () async -> Void
442-
) -> Bool {
443-
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)
444-
445-
guard canAdd else {
446-
// the group is cancelled and is not accepting any new work
447-
return false
448-
}
449-
450-
let flags = taskCreateFlags(
451-
priority: nil, isChildTask: true, copyTaskLocals: false,
452-
inheritContext: false, enqueueJob: true,
453-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
454-
)
455-
456-
// Create the task in this group.
457-
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
458-
459-
return true
460-
}
461-
462-
#endif // $Embedded
463-
464333
/// A Boolean value that indicates whether the group has any remaining tasks.
465334
///
466335
/// At the start of the body of a `withDiscardingTaskGroup(of:returning:body:)` call,

stdlib/public/Concurrency/Task.swift

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -635,25 +635,6 @@ extension Task where Failure == Never {
635635
) {
636636
fatalError("Unavailable in task-to-thread concurrency model.")
637637
}
638-
#elseif $Embedded
639-
@discardableResult
640-
@_alwaysEmitIntoClient
641-
public init(
642-
priority: TaskPriority? = nil,
643-
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async -> Success
644-
) {
645-
// Set up the job flags for a new task.
646-
let flags = taskCreateFlags(
647-
priority: priority, isChildTask: false, copyTaskLocals: true,
648-
inheritContext: true, enqueueJob: true,
649-
addPendingGroupTaskUnconditionally: false,
650-
isDiscardingTask: false)
651-
652-
// Create the asynchronous task.
653-
let (task, _) = Builtin.createAsyncTask(flags, operation)
654-
655-
self._task = task
656-
}
657638
#else
658639
/// Runs the given nonthrowing operation asynchronously
659640
/// as part of a new top-level task on behalf of the current actor.
@@ -717,25 +698,6 @@ extension Task where Failure == Error {
717698
) {
718699
fatalError("Unavailable in task-to-thread concurrency model")
719700
}
720-
#elseif $Embedded
721-
@discardableResult
722-
@_alwaysEmitIntoClient
723-
public init(
724-
priority: TaskPriority? = nil,
725-
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping () async throws -> Success
726-
) {
727-
// Set up the task flags for a new task.
728-
let flags = taskCreateFlags(
729-
priority: priority, isChildTask: false, copyTaskLocals: true,
730-
inheritContext: true, enqueueJob: true,
731-
addPendingGroupTaskUnconditionally: false,
732-
isDiscardingTask: false)
733-
734-
// Create the asynchronous task future.
735-
let (task, _) = Builtin.createAsyncTask(flags, operation)
736-
737-
self._task = task
738-
}
739701
#else
740702
/// Runs the given throwing operation asynchronously
741703
/// as part of a new top-level task on behalf of the current actor.
@@ -801,25 +763,6 @@ extension Task where Failure == Never {
801763
) -> Task<Success, Failure> {
802764
fatalError("Unavailable in task-to-thread concurrency model")
803765
}
804-
#elseif $Embedded
805-
@discardableResult
806-
@_alwaysEmitIntoClient
807-
public static func detached(
808-
priority: TaskPriority? = nil,
809-
operation: sending @escaping () async -> Success
810-
) -> Task<Success, Failure> {
811-
// Set up the job flags for a new task.
812-
let flags = taskCreateFlags(
813-
priority: priority, isChildTask: false, copyTaskLocals: false,
814-
inheritContext: false, enqueueJob: true,
815-
addPendingGroupTaskUnconditionally: false,
816-
isDiscardingTask: false)
817-
818-
// Create the asynchronous task future.
819-
let (task, _) = Builtin.createAsyncTask(flags, operation)
820-
821-
return Task(task)
822-
}
823766
#else
824767
/// Runs the given nonthrowing operation asynchronously
825768
/// as part of a new top-level task.
@@ -880,25 +823,6 @@ extension Task where Failure == Error {
880823
) -> Task<Success, Failure> {
881824
fatalError("Unavailable in task-to-thread concurrency model")
882825
}
883-
#elseif $Embedded
884-
@discardableResult
885-
@_alwaysEmitIntoClient
886-
public static func detached(
887-
priority: TaskPriority? = nil,
888-
operation: sending @escaping () async throws -> Success
889-
) -> Task<Success, Failure> {
890-
// Set up the job flags for a new task.
891-
let flags = taskCreateFlags(
892-
priority: priority, isChildTask: false, copyTaskLocals: false,
893-
inheritContext: false, enqueueJob: true,
894-
addPendingGroupTaskUnconditionally: false,
895-
isDiscardingTask: false)
896-
897-
// Create the asynchronous task future.
898-
let (task, _) = Builtin.createAsyncTask(flags, operation)
899-
900-
return Task(task)
901-
}
902826
#else
903827
/// Runs the given throwing operation asynchronously
904828
/// as part of a new top-level task.

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
327327
self._group = group
328328
}
329329

330-
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY && !$Embedded
330+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
331331
/// Adds a child task to the group.
332332
///
333333
/// - Parameters:
@@ -409,63 +409,6 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
409409
return true
410410
}
411411

412-
#elseif $Embedded
413-
414-
@_alwaysEmitIntoClient
415-
public mutating func addTask(
416-
priority: TaskPriority? = nil,
417-
operation: sending @escaping () async -> ChildTaskResult
418-
) {
419-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
420-
let flags = taskCreateFlags(
421-
priority: priority, isChildTask: true, copyTaskLocals: false,
422-
inheritContext: false, enqueueJob: false,
423-
addPendingGroupTaskUnconditionally: true,
424-
isDiscardingTask: false
425-
)
426-
#else
427-
let flags = taskCreateFlags(
428-
priority: priority, isChildTask: true, copyTaskLocals: false,
429-
inheritContext: false, enqueueJob: true,
430-
addPendingGroupTaskUnconditionally: true,
431-
isDiscardingTask: false)
432-
#endif
433-
434-
// Create the task in this group.
435-
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
436-
}
437-
438-
@_alwaysEmitIntoClient
439-
public mutating func addTaskUnlessCancelled(
440-
priority: TaskPriority? = nil,
441-
operation: sending @escaping () async -> ChildTaskResult
442-
) -> Bool {
443-
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)
444-
445-
guard canAdd else {
446-
// the group is cancelled and is not accepting any new work
447-
return false
448-
}
449-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
450-
let flags = taskCreateFlags(
451-
priority: priority, isChildTask: true, copyTaskLocals: false,
452-
inheritContext: false, enqueueJob: false,
453-
addPendingGroupTaskUnconditionally: false,
454-
isDiscardingTask: false)
455-
#else
456-
let flags = taskCreateFlags(
457-
priority: priority, isChildTask: true, copyTaskLocals: false,
458-
inheritContext: false, enqueueJob: true,
459-
addPendingGroupTaskUnconditionally: false,
460-
isDiscardingTask: false)
461-
#endif
462-
463-
// Create the task in this group.
464-
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
465-
466-
return true
467-
}
468-
469412
#else // if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
470413
@available(SwiftStdlib 5.7, *)
471414
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")

0 commit comments

Comments
 (0)