Skip to content

Commit 32e1b67

Browse files
committed
Add Task+init gyb to embedded; Remove TaskGroup+Embedded.swift workaround
1 parent 6c87489 commit 32e1b67

File tree

5 files changed

+34
-477
lines changed

5 files changed

+34
-477
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ add_library(swift_Concurrency
9191
Task+TaskExecutor.swift
9292
TaskCancellation.swift
9393
TaskGroup.swift
94-
TaskGroup+Embedded.swift
9594
TaskLocal.swift
9695
TaskSleep.swift
9796
TaskSleepDuration.swift
97+
"${CMAKE_CURRENT_BINARY_DIR}/Task+init.swift"
9898
"${CMAKE_CURRENT_BINARY_DIR}/TaskGroup+addTask.swift"
9999
"${CMAKE_CURRENT_BINARY_DIR}/Task+startSynchronously.swift")
100100

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
129129
Task+TaskExecutor.swift
130130
TaskCancellation.swift
131131
TaskGroup.swift
132-
TaskGroup+Embedded.swift
133132
DiscardingTaskGroup.swift
134133
TaskLocal.swift
135134
TaskSleep.swift
@@ -204,6 +203,12 @@ set(LLVM_OPTIONAL_SOURCES
204203
DispatchGlobalExecutor.cpp
205204
)
206205

206+
set(SWIFT_CONCURRENCY_GYB_SOURCES
207+
Task+init.swift.gyb
208+
TaskGroup+addTask.swift.gyb
209+
Task+startSynchronously.swift.gyb
210+
)
211+
207212
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
208213
${SWIFT_RUNTIME_CONCURRENCY_C_SOURCES}
209214
${SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES}
@@ -212,9 +217,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
212217
${SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES}
213218

214219
GYB_SOURCES
215-
Task+init.swift.gyb
216-
TaskGroup+addTask.swift.gyb
217-
Task+startSynchronously.swift.gyb
220+
${SWIFT_CONCURRENCY_GYB_SOURCES}
218221

219222
SWIFT_MODULE_DEPENDS_ANDROID Android
220223
SWIFT_MODULE_DEPENDS_LINUX Glibc
@@ -310,6 +313,9 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
310313
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES}
311314
${SWIFT_RUNTIME_CONCURRENCY_EMBEDDED_SWIFT_SOURCES}
312315

316+
GYB_SOURCES
317+
${SWIFT_CONCURRENCY_GYB_SOURCES}
318+
313319
SWIFT_COMPILE_FLAGS
314320
${extra_swift_compile_flags} -enable-experimental-feature Embedded
315321
-parse-stdlib -DSWIFT_CONCURRENCY_EMBEDDED

stdlib/public/Concurrency/SourceCompatibilityShims.swift

Lines changed: 17 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
import Swift
17-
import _Concurrency
1817

1918
@available(SwiftStdlib 5.1, *)
2019
extension Task where Success == Never, Failure == Never {
@@ -88,192 +87,23 @@ extension Task where Success == Never, Failure == Never {
8887
}
8988
}
9089

91-
//@available(SwiftStdlib 5.1, *)
92-
//extension Task where Failure == Error {
93-
// #if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
94-
// @discardableResult
95-
// @_alwaysEmitIntoClient
96-
// @available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
97-
// public static func runDetached(
98-
// priority: TaskPriority? = nil,
99-
// operation: __owned @Sendable @escaping () async throws -> Success
100-
// ) -> Task<Success, Failure> {
101-
// fatalError("Unavailable in task-to-thread concurrency model")
102-
// }
103-
// #else
104-
// @discardableResult
105-
// @_alwaysEmitIntoClient
106-
// @available(*, deprecated, message: "`Task.runDetached` was replaced by `Task.detached` and will be removed shortly.")
107-
// public static func runDetached(
108-
// priority: TaskPriority? = nil,
109-
// operation: __owned @Sendable @escaping () async throws -> Success
110-
// ) -> Task<Success, Failure> {
111-
// detached(priority: priority, operation: operation)
112-
// }
113-
// #endif
114-
//}
115-
//
116-
//#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
117-
//@discardableResult
118-
//@available(SwiftStdlib 5.1, *)
119-
//@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
120-
//@_alwaysEmitIntoClient
121-
//public func detach<T>(
122-
// priority: TaskPriority? = nil,
123-
// operation: __owned @Sendable @escaping () async -> T
124-
//) -> Task<T, Never> {
125-
// fatalError("Unavailable in task-to-thread concurrency model")
126-
//}
127-
//#else
128-
//@discardableResult
129-
//@available(SwiftStdlib 5.1, *)
130-
//@available(*, deprecated, message: "`detach` was replaced by `Task.detached` and will be removed shortly.")
131-
//@_alwaysEmitIntoClient
132-
//public func detach<T>(
133-
// priority: TaskPriority? = nil,
134-
// operation: __owned @Sendable @escaping () async -> T
135-
//) -> Task<T, Never> {
136-
// Task.detached(priority: priority, operation: operation)
137-
//}
138-
//#endif
139-
//
140-
//#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
141-
//@discardableResult
142-
//@available(SwiftStdlib 5.1, *)
143-
//@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
144-
//@_alwaysEmitIntoClient
145-
//public func detach<T>(
146-
// priority: TaskPriority? = nil,
147-
// operation: __owned @Sendable @escaping () async throws -> T
148-
//) -> Task<T, Error> {
149-
// fatalError("Unavailable in task-to-thread concurrency model")
150-
//}
151-
//#else
152-
//@discardableResult
153-
//@available(SwiftStdlib 5.1, *)
154-
//@available(*, deprecated, message: "`detach` was replaced by `Task.detached` and will be removed shortly.")
155-
//@_alwaysEmitIntoClient
156-
//public func detach<T>(
157-
// priority: TaskPriority? = nil,
158-
// operation: __owned @Sendable @escaping () async throws -> T
159-
//) -> Task<T, Error> {
160-
// Task.detached(priority: priority, operation: operation)
161-
//}
162-
//#endif
163-
//
164-
//#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
165-
//@discardableResult
166-
//@available(SwiftStdlib 5.1, *)
167-
//@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
168-
//@_alwaysEmitIntoClient
169-
//public func asyncDetached<T>(
170-
// priority: TaskPriority? = nil,
171-
// @_implicitSelfCapture operation: __owned @Sendable @escaping () async -> T
172-
//) -> Task<T, Never> {
173-
// fatalError("Unavailable in task-to-thread concurrency model")
174-
//}
175-
//#else
176-
//@discardableResult
177-
//@available(SwiftStdlib 5.1, *)
178-
//@available(*, deprecated, message: "`asyncDetached` was replaced by `Task.detached` and will be removed shortly.")
179-
//@_alwaysEmitIntoClient
180-
//public func asyncDetached<T>(
181-
// priority: TaskPriority? = nil,
182-
// @_implicitSelfCapture operation: __owned @Sendable @escaping () async -> T
183-
//) -> Task<T, Never> {
184-
// return Task.detached(priority: priority, operation: operation)
185-
//}
186-
//#endif
187-
//
188-
//#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
189-
//@discardableResult
190-
//@available(SwiftStdlib 5.1, *)
191-
//@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
192-
//@_alwaysEmitIntoClient
193-
//public func asyncDetached<T>(
194-
// priority: TaskPriority? = nil,
195-
// @_implicitSelfCapture operation: __owned @Sendable @escaping () async throws -> T
196-
//) -> Task<T, Error> {
197-
// fatalError("Unavailable in task-to-thread concurrency model")
198-
//}
199-
//#else
200-
//@discardableResult
201-
//@available(SwiftStdlib 5.1, *)
202-
//@available(*, deprecated, message: "`asyncDetached` was replaced by `Task.detached` and will be removed shortly.")
203-
//@_alwaysEmitIntoClient
204-
//public func asyncDetached<T>(
205-
// priority: TaskPriority? = nil,
206-
// @_implicitSelfCapture operation: __owned @Sendable @escaping () async throws -> T
207-
//) -> Task<T, Error> {
208-
// return Task.detached(priority: priority, operation: operation)
209-
//}
210-
//#endif
211-
//
212-
//#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
213-
//@available(SwiftStdlib 5.1, *)
214-
//@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
215-
//@discardableResult
216-
//@_alwaysEmitIntoClient
217-
//public func async<T>(
218-
// priority: TaskPriority? = nil,
219-
// @_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async -> T
220-
//) -> Task<T, Never> {
221-
// fatalError("Unavailable in task-to-thread concurrency model")
222-
//}
223-
//#else
224-
//@available(SwiftStdlib 5.1, *)
225-
//@available(*, deprecated, message: "`async` was replaced by `Task.init` and will be removed shortly.")
226-
//@discardableResult
227-
//@_alwaysEmitIntoClient
228-
//public func async<T>(
229-
// priority: TaskPriority? = nil,
230-
// @_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async -> T
231-
//) -> Task<T, Never> {
232-
// .init(priority: priority, operation: operation)
233-
//}
234-
//#endif
235-
//
236-
//#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
237-
//@available(SwiftStdlib 5.1, *)
238-
//@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
239-
//@discardableResult
240-
//@_alwaysEmitIntoClient
241-
//public func async<T>(
242-
// priority: TaskPriority? = nil,
243-
// @_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async throws -> T
244-
//) -> Task<T, Error> {
245-
// fatalError("Unavailable in task-to-thread concurrency model")
246-
//}
247-
//#else
248-
//@available(SwiftStdlib 5.1, *)
249-
//@available(*, deprecated, message: "`async` was replaced by `Task.init` and will be removed shortly.")
250-
//@discardableResult
251-
//@_alwaysEmitIntoClient
252-
//public func async<T>(
253-
// priority: TaskPriority? = nil,
254-
// @_inheritActorContext @_implicitSelfCapture operation: __owned @Sendable @escaping () async throws -> T
255-
//) -> Task<T, Error> {
256-
// .init(priority: priority, operation: operation)
257-
//}
258-
//#endif
259-
//
260-
//@available(SwiftStdlib 5.1, *)
261-
//extension Task where Success == Never, Failure == Never {
262-
// @available(*, deprecated, message: "`Task.Group` was replaced by `ThrowingTaskGroup` and `TaskGroup` and will be removed shortly.")
263-
// public typealias Group<TaskResult: Sendable> = ThrowingTaskGroup<TaskResult, Error>
264-
//
265-
// @available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.")
266-
// @_alwaysEmitIntoClient
267-
// public static func withGroup<TaskResult: Sendable, BodyResult>(
268-
// resultType: TaskResult.Type,
269-
// returning returnType: BodyResult.Type = BodyResult.self,
270-
// body: (inout Task.Group<TaskResult>) async throws -> BodyResult
271-
// ) async rethrows -> BodyResult {
272-
// try await withThrowingTaskGroup(of: resultType) { group in
273-
// try await body(&group)
274-
// }
275-
// }
276-
//}
90+
@available(SwiftStdlib 5.1, *)
91+
extension Task where Success == Never, Failure == Never {
92+
@available(*, deprecated, message: "`Task.Group` was replaced by `ThrowingTaskGroup` and `TaskGroup` and will be removed shortly.")
93+
public typealias Group<TaskResult: Sendable> = ThrowingTaskGroup<TaskResult, Error>
94+
95+
@available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.")
96+
@_alwaysEmitIntoClient
97+
public static func withGroup<TaskResult: Sendable, BodyResult>(
98+
resultType: TaskResult.Type,
99+
returning returnType: BodyResult.Type = BodyResult.self,
100+
body: (inout Task.Group<TaskResult>) async throws -> BodyResult
101+
) async rethrows -> BodyResult {
102+
try await withThrowingTaskGroup(of: resultType) { group in
103+
try await body(&group)
104+
}
105+
}
106+
}
277107

278108
@available(SwiftStdlib 5.1, *)
279109
extension Task {

stdlib/public/Concurrency/Task+init.swift.gyb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ import Swift
141141

142142
% IS_TOP_LEVEL_FUNC = (not ('init' in METHOD_VARIANT)) and (not ('static' in METHOD_VARIANT))
143143
% IS_INIT = 'init' in METHOD_VARIANT
144-
% IS_DETACHED = 'detached' in METHOD_VARIANT
144+
% IS_DETACHED = 'detach' in METHOD_VARIANT.lower()
145145
% IS_THROWING = 'throws' in METHOD_VARIANT
146146
%
147147
% HAS_TASK_PRIORITY = any('priority:' in param for param in PARAMS)
@@ -221,7 +221,11 @@ extension Task where Failure == ${FAILURE_TYPE} {
221221

222222
let (task, _) = Builtin.createAsyncTask(flags, operation)
223223

224+
% if IS_INIT:
224225
self._task = task
226+
% else:
227+
return Task(task)
228+
% end
225229
}
226230
% end # not HAS_TASK_EXECUTOR
227231

@@ -283,7 +287,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
283287
% end # IS_DEPRECATED
284288
${"\n ".join(adjust_availability(ALL_AVAILABILITY))}
285289
@discardableResult
286-
public ${METHOD_VARIANT}(
290+
public ${METHOD_VARIANT}( // Task ${METHOD_VARIANT}
287291
${",\n ".join(adjust_params_for_kind(PARAMS))}
288292
) ${ARROW_RETURN_TYPE}{
289293

0 commit comments

Comments
 (0)