Skip to content

Commit 100f70a

Browse files
committed
cleanups
1 parent 27ac871 commit 100f70a

File tree

4 files changed

+19
-41
lines changed

4 files changed

+19
-41
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,17 +2387,18 @@ enum class TaskOptionRecordKind : uint8_t {
23872387
class TaskGroupFlags : public FlagSet<uint32_t> {
23882388
public:
23892389
enum {
2390-
// 8 bits are un-used, in case we want to introduce a Kind here
2391-
2390+
// 8 bits are reserved for future use
2391+
/// Request the TaskGroup to immediately release completed tasks,
2392+
/// and not store their results. This also effectively disables `next()`.
23922393
TaskGroup_DiscardResults = 8,
23932394
};
23942395

23952396
explicit TaskGroupFlags(uint32_t bits) : FlagSet(bits) {}
23962397
constexpr TaskGroupFlags() {}
23972398

23982399
FLAGSET_DEFINE_FLAG_ACCESSORS(TaskGroup_DiscardResults,
2399-
task_isDiscardResults,
2400-
task_setIsDiscardResults)
2400+
isDiscardResults,
2401+
setIsDiscardResults)
24012402
};
24022403

24032404
/// Kinds of task group option records that can be passed to creating a task group.

lib/IRGen/GenConcurrency.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ llvm::Value *irgen::emitCreateTaskGroup(IRGenFunction &IGF,
285285

286286
llvm::CallInst *call;
287287
if (groupFlags) {
288+
fprintf(stderr, "[%s:%d](%s) group flags; invoke -> getTaskGroupInitializeWithFlagsFunctionPointer\n", __FILE_NAME__, __LINE__, __FUNCTION__);
288289
call = IGF.Builder.CreateCall(IGF.IGM.getTaskGroupInitializeWithFlagsFunctionPointer(),
289290
{groupFlags, group, resultTypeMetadata});
290291
} else {
292+
fprintf(stderr, "[%s:%d](%s) no group flags; invoke -> getTaskGroupInitializeFunctionPointer\n", __FILE_NAME__, __LINE__, __FUNCTION__);
291293
call = IGF.Builder.CreateCall(IGF.IGM.getTaskGroupInitializeFunctionPointer(),
292294
{group, resultTypeMetadata});
293295
}

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,16 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
513513

514514
// Initializes into the preallocated _group an actual TaskGroupImpl.
515515
SWIFT_CC(swift)
516-
static void swift_taskGroup_initializeWithFlagsImpl(size_t flags, TaskGroup *group, const Metadata *T) {
516+
static void swift_taskGroup_initializeWithFlagsImpl(size_t rawGroupFlags, TaskGroup *group, const Metadata *T) {
517517
SWIFT_TASK_DEBUG_LOG("creating task group = %p", group);
518518

519-
fprintf(stderr, "[%s:%d](%s) INITIALIZE FLAGS: %d\n", __FILE_NAME__, __LINE__, __FUNCTION__, flags);
519+
TaskGroupFlags groupFlags(rawGroupFlags);
520520

521-
TaskGroupImpl *impl = ::new (group) TaskGroupImpl(T, /*discardResults=*/true);
521+
fprintf(stderr, "[%s:%d](%s) INITIALIZE FLAGS: raw:%d, discardResults:%d\n", __FILE_NAME__, __LINE__, __FUNCTION__, rawGroupFlags,
522+
groupFlags.isDiscardResults());
523+
524+
TaskGroupImpl *impl = ::new(group)
525+
TaskGroupImpl(T, groupFlags.isDiscardResults());
522526
auto record = impl->getTaskRecord();
523527
assert(impl == record && "the group IS the task record");
524528

@@ -674,7 +678,7 @@ static void fillGroupNextVoidResult(TaskFutureWaitAsyncContext *context,
674678

675679
// TaskGroup is locked upon entry and exit
676680
void TaskGroupImpl::enqueueCompletedTask(AsyncTask *completedTask, bool hadErrorResult) {
677-
if (this->discardResults) {
681+
if (discardResults) {
678682
SWIFT_TASK_DEBUG_LOG("group has no waiting tasks, eager release mode; release result task = %p",
679683
completedTask);
680684
// DO NOT RETAIN THE TASK.
@@ -963,7 +967,7 @@ reevaluate_if_taskgroup_has_results:;
963967

964968
// Success! We are allowed to poll.
965969
ReadyQueueItem item;
966-
if (this->discardResults) {
970+
if (discardResults) {
967971
SWIFT_TASK_DEBUG_LOG("poll group = %p; polled in eager-release mode; make up Void value to yield",
968972
this, assumed.readyTasks(), assumed.pendingTasks());
969973
result.status = PollStatus::Success;

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
1413
import Swift
1514
@_implementationOnly import _SwiftConcurrencyShims
16-
import Darwin
1715

1816
// ==== TaskGroup --------------------------------------------------------------
1917

20-
@available(SwiftStdlib 5.8, *)
21-
public protocol TaskGroupAdd {
22-
associatedtype ChildTaskResult: Sendable
23-
24-
mutating func addTask(
25-
priority: TaskPriority?,
26-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
27-
)
28-
29-
mutating func addTask(
30-
priority: TaskPriority?,
31-
operation: __owned @Sendable @escaping (inout any TaskGroupAdd) async -> ChildTaskResult
32-
)
33-
34-
// TODO: unless cancelled versions
35-
36-
}
37-
38-
@available(SwiftStdlib 5.8, *)
39-
public protocol TaskGroupConsume {
40-
associatedtype ChildTaskResult: Sendable
41-
42-
mutating func next() async -> ChildTaskResult?
43-
}
44-
45-
// TODO: throwing versions
46-
4718
/// Starts a new scope that can contain a dynamic number of child tasks.
4819
///
4920
/// A group waits for all of its child tasks
@@ -1166,16 +1137,16 @@ struct TaskGroupFlags {
11661137
/// The priority given to the job.
11671138
var discardResults: Bool? {
11681139
get {
1169-
let value = (Int(bits) & 1 << 8)
1140+
let value = (Int(bits) & 1 << 24)
11701141

11711142
return value > 0
11721143
}
11731144

11741145
set {
11751146
if newValue == true {
1176-
bits = bits | 1 << 8
1147+
bits = bits | 1 << 24
11771148
} else {
1178-
bits = (bits & ~(1 << 8))
1149+
bits = (bits & ~(1 << 23))
11791150
}
11801151
}
11811152
}

0 commit comments

Comments
 (0)