Skip to content

Commit efbbc2c

Browse files
committed
[Concurrency] introduce gyb file to generate addTask implementations
1 parent 45b639a commit efbbc2c

26 files changed

+768
-1421
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
add_subdirectory(InternalShims)
22

3+
gyb_expand(TaskGroup+addTask.swift.gyb TaskGroup+addTask.swift)
4+
35
add_library(swift_Concurrency
46
Actor.cpp
57
AsyncLet.cpp
@@ -77,10 +79,11 @@ add_library(swift_Concurrency
7779
Task+TaskExecutor.swift
7880
TaskCancellation.swift
7981
TaskGroup.swift
80-
TaskGroup+TaskExecutor.swift
8182
TaskLocal.swift
8283
TaskSleep.swift
83-
TaskSleepDuration.swift)
84+
TaskSleepDuration.swift
85+
"${CMAKE_CURRENT_BINARY_DIR}/TaskGroup+addTask.swift")
86+
8487
include(${SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR}.cmake)
8588
target_compile_definitions(swift_Concurrency PRIVATE
8689
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_TARGET_LIBRARY_NAME=swift_Concurrency>

lib/AST/Builtins.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,6 @@ _generics(ParamS... params) {
219219
return {{params...}};
220220
}
221221

222-
///// A conditional synthesizer which generates a generic parameter list.
223-
///// If the 'condition' is false, no generic parameters are created.
224-
//template <class... ParamS>
225-
//struct ConditionalGenericParamListSynthesizer {
226-
// bool condition;
227-
// VariadicSynthesizerStorage<ParamS...> Params;
228-
//};
229-
//template <class... ParamS>
230-
//constexpr ConditionalGenericParamListSynthesizer<ParamS...>
231-
//_ifGenerics(bool condition, ParamS... params) {
232-
// return {condition, {params...}};
233-
//}
234-
235222
struct CountGenericParameters {
236223
unsigned &Count;
237224

@@ -305,21 +292,6 @@ static GenericParamList *synthesizeGenericParamList(SynthesisContext &SC,
305292
return paramList;
306293
}
307294

308-
//template <class... ParamsS>
309-
//static GenericParamList *synthesizeGenericParamList(
310-
// SynthesisContext &SC,
311-
// const ConditionalGenericParamListSynthesizer<ParamsS...> &params) {
312-
// if (params.condition) {
313-
// unsigned count = 0;
314-
// params.Params.visit(CountGenericParameters{count});
315-
// auto paramList = getGenericParams(SC.Context, count);
316-
// SC.GenericParams = paramList;
317-
// return paramList;
318-
// } else {
319-
// return GenericParamList::create(SC.Context, SourceLoc(), {}, SourceLoc());
320-
// }
321-
//}
322-
323295
namespace {
324296
struct CollectGenericParams {
325297
SynthesisContext &SC;
@@ -369,24 +341,6 @@ synthesizeGenericSignature(SynthesisContext &SC,
369341
/*allowInverses=*/false);
370342
}
371343

372-
//template <class... ParamsS>
373-
//static GenericSignature
374-
//synthesizeGenericSignature(SynthesisContext &SC,
375-
// const ConditionalGenericParamListSynthesizer<ParamsS...> &list) {
376-
// CollectGenericParams collector(SC);
377-
// if (list.condition) {
378-
// list.Params.visit(collector);
379-
//
380-
// return buildGenericSignature(SC.Context,
381-
// GenericSignature(),
382-
// std::move(collector.GenericParamTypes),
383-
// std::move(collector.AddedRequirements),
384-
// /*allowInverses=*/false);
385-
// } else {
386-
// return GenericSignature();
387-
// }
388-
//}
389-
390344
/// Build a builtin function declaration.
391345
///
392346
/// This is a "legacy" interface; you should probably use one of

lib/IRGen/GenConcurrency.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,6 @@ irgen::emitTaskCreate(IRGenFunction &IGF, llvm::Value *flags,
857857
}
858858

859859
// Add an option record for the initial task name, if present.
860-
//
861-
// (lldb) e taskName.value.Values[0]
862-
// (llvm::Value *) $11 = 0x000060000220d1a0
863-
// (lldb) e taskName.value.Values[0]->dump()
864-
// %16 = extractvalue { i64, i64 } %15, 0
865-
// (lldb) e taskName.value.Values[1]->dump()
866-
// %17 = extractvalue { i64, i64 } %15, 1
867860
taskOptions = maybeAddTaskNameOptionRecord(IGF, taskOptions, taskName);
868861

869862
// In embedded Swift, create and pass result type info.

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
144144
Task+TaskExecutor.swift
145145
TaskCancellation.swift
146146
TaskGroup.swift
147-
TaskGroup+TaskExecutor.swift
147+
TaskGroup+Embedded.swift
148148
DiscardingTaskGroup.swift
149149
TaskLocal.swift
150150
TaskSleep.swift
@@ -181,6 +181,9 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
181181
${SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES}
182182
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES}
183183

184+
GYB_SOURCES
185+
TaskGroup+addTask.swift.gyb
186+
184187
SWIFT_MODULE_DEPENDS_ANDROID Android
185188
SWIFT_MODULE_DEPENDS_LINUX Glibc
186189
SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl
@@ -274,6 +277,9 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
274277
${SWIFT_RUNTIME_CONCURRENCY_C_SOURCES}
275278
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES}
276279

280+
# FIXME: Need to include the TaskGroup+addTask.swift.gyb here,
281+
# but there's trouble with that: Unknown architecture: x86_64-apple-macos
282+
277283
SWIFT_COMPILE_FLAGS
278284
${extra_swift_compile_flags} -enable-experimental-feature Embedded
279285
-parse-stdlib -DSWIFT_CONCURRENCY_EMBEDDED

stdlib/public/Concurrency/DiscardingTaskGroup.swift

Lines changed: 0 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -186,152 +186,6 @@ public struct DiscardingTaskGroup {
186186
let _: Void? = try await _taskGroupWaitAll(group: _group, bodyError: nil)
187187
}
188188

189-
/// Adds a child task to the group.
190-
///
191-
/// - Parameters:
192-
/// - priority: The priority of the operation task.
193-
/// Omit this parameter or pass `.unspecified`
194-
/// to set the child task's priority to the priority of the group.
195-
/// - operation: The operation to execute as part of the task group.
196-
@_alwaysEmitIntoClient
197-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
198-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
199-
#endif
200-
public mutating func addTask(
201-
priority: TaskPriority? = nil,
202-
operation: sending @escaping @isolated(any) () async -> Void
203-
) {
204-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
205-
let flags = taskCreateFlags(
206-
priority: priority, isChildTask: true, copyTaskLocals: false,
207-
inheritContext: false, enqueueJob: false,
208-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
209-
)
210-
#else
211-
let flags = taskCreateFlags(
212-
priority: priority, isChildTask: true, copyTaskLocals: false,
213-
inheritContext: false, enqueueJob: true,
214-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
215-
)
216-
#endif
217-
218-
// Create the task in this group.
219-
let builtinSerialExecutor =
220-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
221-
222-
_ = Builtin.createDiscardingTask(flags: flags,
223-
initialSerialExecutor: builtinSerialExecutor,
224-
taskGroup: _group,
225-
operation: operation)
226-
}
227-
228-
/// Adds a child task to the group, unless the group has been canceled.
229-
///
230-
/// - Parameters:
231-
/// - priority: The priority of the operation task.
232-
/// Omit this parameter or pass `.unspecified`
233-
/// to set the child task's priority to the priority of the group.
234-
/// - operation: The operation to execute as part of the task group.
235-
/// - Returns: `true` if the child task was added to the group;
236-
/// otherwise `false`.
237-
@_alwaysEmitIntoClient
238-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
239-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
240-
#endif
241-
public mutating func addTaskUnlessCancelled(
242-
priority: TaskPriority? = nil,
243-
operation: sending @escaping @isolated(any) () async -> Void
244-
) -> Bool {
245-
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)
246-
247-
guard canAdd else {
248-
// the group is cancelled and is not accepting any new work
249-
return false
250-
}
251-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
252-
let flags = taskCreateFlags(
253-
priority: priority, isChildTask: true, copyTaskLocals: false,
254-
inheritContext: false, enqueueJob: false,
255-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
256-
)
257-
#else
258-
let flags = taskCreateFlags(
259-
priority: priority, isChildTask: true, copyTaskLocals: false,
260-
inheritContext: false, enqueueJob: true,
261-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
262-
)
263-
#endif
264-
265-
// Create the task in this group.
266-
let builtinSerialExecutor =
267-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
268-
269-
_ = Builtin.createDiscardingTask(flags: flags,
270-
initialSerialExecutor: builtinSerialExecutor,
271-
taskGroup: _group,
272-
operation: operation)
273-
274-
return true
275-
}
276-
277-
@_alwaysEmitIntoClient
278-
public mutating func addTask(
279-
operation: sending @escaping @isolated(any) () async -> Void
280-
) {
281-
let flags = taskCreateFlags(
282-
priority: nil, isChildTask: true, copyTaskLocals: false,
283-
inheritContext: false, enqueueJob: true,
284-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
285-
)
286-
287-
// Create the task in this group.
288-
let builtinSerialExecutor =
289-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
290-
291-
_ = Builtin.createDiscardingTask(flags: flags,
292-
initialSerialExecutor: builtinSerialExecutor,
293-
taskGroup: _group,
294-
operation: operation)
295-
}
296-
297-
/// Adds a child task to the group, unless the group has been canceled.
298-
///
299-
/// - Parameters:
300-
/// - operation: The operation to execute as part of the task group.
301-
/// - Returns: `true` if the child task was added to the group;
302-
/// otherwise `false`.
303-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
304-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
305-
#endif
306-
@_alwaysEmitIntoClient
307-
public mutating func addTaskUnlessCancelled(
308-
operation: sending @escaping @isolated(any) () async -> Void
309-
) -> Bool {
310-
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)
311-
312-
guard canAdd else {
313-
// the group is cancelled and is not accepting any new work
314-
return false
315-
}
316-
317-
let flags = taskCreateFlags(
318-
priority: nil, isChildTask: true, copyTaskLocals: false,
319-
inheritContext: false, enqueueJob: true,
320-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
321-
)
322-
323-
// Create the task in this group.
324-
let builtinSerialExecutor =
325-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
326-
327-
_ = Builtin.createDiscardingTask(flags: flags,
328-
initialSerialExecutor: builtinSerialExecutor,
329-
taskGroup: _group,
330-
operation: operation)
331-
332-
return true
333-
}
334-
335189
/// A Boolean value that indicates whether the group has any remaining tasks.
336190
///
337191
/// At the start of the body of a `withDiscardingTaskGroup(of:returning:body:)` call,
@@ -624,63 +478,6 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
624478
let _: Void? = try await _taskGroupWaitAll(group: _group, bodyError: bodyError)
625479
}
626480

627-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
628-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
629-
#endif
630-
@_alwaysEmitIntoClient
631-
public mutating func addTask(
632-
priority: TaskPriority? = nil,
633-
operation: sending @escaping @isolated(any) () async throws -> Void
634-
) {
635-
let flags = taskCreateFlags(
636-
priority: priority, isChildTask: true, copyTaskLocals: false,
637-
inheritContext: false, enqueueJob: true,
638-
addPendingGroupTaskUnconditionally: true, isDiscardingTask: true
639-
)
640-
641-
// Create the task in this group.
642-
let builtinSerialExecutor =
643-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
644-
645-
_ = Builtin.createDiscardingTask(flags: flags,
646-
initialSerialExecutor: builtinSerialExecutor,
647-
taskGroup: _group,
648-
operation: operation)
649-
}
650-
651-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
652-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
653-
#endif
654-
@_alwaysEmitIntoClient
655-
public mutating func addTaskUnlessCancelled(
656-
priority: TaskPriority? = nil,
657-
operation: sending @escaping @isolated(any) () async throws -> Void
658-
) -> Bool {
659-
let canAdd = _taskGroupAddPendingTask(group: _group, unconditionally: false)
660-
661-
guard canAdd else {
662-
// the group is cancelled and is not accepting any new work
663-
return false
664-
}
665-
666-
let flags = taskCreateFlags(
667-
priority: priority, isChildTask: true, copyTaskLocals: false,
668-
inheritContext: false, enqueueJob: true,
669-
addPendingGroupTaskUnconditionally: false, isDiscardingTask: true
670-
)
671-
672-
// Create the task in this group.
673-
let builtinSerialExecutor =
674-
Builtin.extractFunctionIsolation(operation)?.unownedExecutor.executor
675-
676-
_ = Builtin.createDiscardingTask(flags: flags,
677-
initialSerialExecutor: builtinSerialExecutor,
678-
taskGroup: _group,
679-
operation: operation)
680-
681-
return true
682-
}
683-
684481
/// A Boolean value that indicates whether the group has any remaining tasks.
685482
///
686483
/// At the start of the body of a `withThrowingDiscardingTaskGroup(returning:body:)` call,

0 commit comments

Comments
 (0)