Skip to content

Commit 07d6715

Browse files
committed
cleanup: remove all println debugging from task infra
1 parent 999758c commit 07d6715

File tree

9 files changed

+28
-126
lines changed

9 files changed

+28
-126
lines changed

include/swift/ABI/TaskStatus.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,11 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
203203

204204
/// Attach the passed in `child` task to this group.
205205
void attachChild(AsyncTask *child) {
206-
fprintf(stderr, "[%s:%d] (%s): attaching GROUP CHILD, group:%d, record:%d child:%d\n", __FILE__, __LINE__, __FUNCTION__,
207-
Group, this, child);
208-
209206
assert(child->groupChildFragment());
210207
assert(child->hasGroupChildFragment());
211208
assert(child->groupChildFragment()->getGroup() == Group);
212209

213210
if (!FirstChild) {
214-
fprintf(stderr, "[%s:%d] (%s): stored (first) CHILD, group:%d, record:%d child:%d\n", __FILE__, __LINE__, __FUNCTION__,
215-
Group, this, child);
216211
// This is the first child we ever attach, so store it as FirstChild.
217212
FirstChild = child;
218213
return;
@@ -228,19 +223,13 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
228223
// no need to check hasChildFragment, all tasks we store here have them.
229224
auto fragment = cur->childFragment();
230225
if (auto next = fragment->getNextChild()) {
231-
fprintf(stderr, "[%s:%d] (%s): storing GROUP CHILD, search, is %d [i:%d] the last one?\n", __FILE__, __LINE__, __FUNCTION__,
232-
cur, i);
233226
cur = next;
234227
} else {
235228
// we're done searching and `cur` is the last
236-
fprintf(stderr, "[%s:%d] (%s): storing GROUP CHILD, done searching, is %d [i:%d] the last one?\n", __FILE__, __LINE__, __FUNCTION__,
237-
cur, i);
238229
break;
239230
}
240231
}
241232

242-
fprintf(stderr, "[%s:%d] (%s): stored %d-th GROUP CHILD, group:%d, record:%d child:%d (was %d <--- %d)\n", __FILE__, __LINE__, __FUNCTION__,
243-
i, Group, this, child, FirstChild, child);
244233
cur->childFragment()->setNextChild(child);
245234
}
246235

stdlib/public/Concurrency/AsyncCall.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ pushAsyncContext(AsyncTask *task, ExecutorRef executor,
159159
assert(calleeContextSize >= sizeof(CalleeContext));
160160

161161
void *rawCalleeContext = swift_task_alloc(task, calleeContextSize);
162-
fprintf(stderr, "[%s:%d] (%s): alloc raw callee context %d\n", __FILE__, __LINE__, __FUNCTION__, rawCalleeContext);
163162
return new (rawCalleeContext) CalleeContext(resumeFunction, executor,
164163
callerContext, args...);
165164
}

stdlib/public/Concurrency/Task.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ AsyncTaskAndContext swift::swift_task_create_group_future_f(
334334
// Initialize the task-local allocator.
335335
// TODO: consider providing an initial pre-allocated first slab to the allocator.
336336
_swift_task_alloc_initialize(task);
337-
fprintf(stderr, "[%s:%d] (%s): created task: %d\n", __FILE__, __LINE__, __FUNCTION__, task);
338337

339338
return {task, initialContext};
340339
}

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ TaskGroup* swift::swift_task_group_create(AsyncTask *task) {
5757
TaskGroupTaskStatusRecord(reinterpret_cast<TaskGroup*>(allocation));
5858

5959
TaskGroup *group = new (allocation) TaskGroup(record);
60-
fprintf(stderr, "[%s:%d] (%s): create group; task: %d, group:%d\n", __FILE__, __LINE__, __FUNCTION__, task, group);
6160

6261
// ok, now that the group actually is initialized: attach it to the task
6362
swift_task_addStatusRecord(task, record);
64-
fprintf(stderr, "[%s:%d] (%s): attach GROUP, task record in parent [%d]; record:%d\n", __FILE__, __LINE__, __FUNCTION__, task, record);
6563

6664
return group;
6765
}
@@ -73,8 +71,6 @@ void swift::swift_task_group_attachChild(TaskGroup *group,
7371
AsyncTask *parent, AsyncTask *child) {
7472
auto groupRecord = group->getTaskRecord();
7573
assert(groupRecord->getGroup() == group);
76-
fprintf(stderr, "[%s:%d] (%s): attach GROUP CHILD, task:%d, group record:%d, child:%d\n", __FILE__, __LINE__, __FUNCTION__,
77-
parent, groupRecord, child);
7874
return groupRecord->attachChild(child);
7975
}
8076

@@ -87,7 +83,6 @@ void swift::swift_task_group_destroy(AsyncTask *task, TaskGroup *group) {
8783

8884
void TaskGroup::destroy(AsyncTask *task) {
8985
// First, remove the group from the task and deallocate the record
90-
fprintf(stderr, "[%s:%d] (%s): detach GROUP, task:%d, group record:%d, group:%d\n", __FILE__, __LINE__, __FUNCTION__, task, Record, this);
9186
swift_task_removeStatusRecord(task, Record);
9287
swift_task_dealloc(task, Record);
9388

@@ -117,8 +112,6 @@ void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context,
117112
assert(completedTask->hasGroupChildFragment());
118113
assert(completedTask->groupChildFragment()->getGroup() == this);
119114

120-
fprintf(stderr, "[%s:%d] (%s): offer %d\n", __FILE__, __LINE__, __FUNCTION__, completedTask);
121-
122115
mutex.lock(); // TODO: remove fragment lock, and use status for synchronization
123116

124117
// Immediately increment ready count and acquire the status
@@ -129,8 +122,6 @@ void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context,
129122
// W:n R:0 P:1 -> W:y R:1 P:3 // complete immediately, 2 more pending tasks
130123
auto assumed = statusAddReadyAssumeAcquire();
131124

132-
fprintf(stderr, "[%s:%d] (%s): offer %s\n", __FILE__, __LINE__, __FUNCTION__, assumed.to_string().c_str());
133-
134125
// If an error was thrown, save it in the future fragment.
135126
auto futureContext = static_cast<FutureAsyncContext *>(context);
136127
bool hadErrorResult = false;
@@ -142,9 +133,7 @@ void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context,
142133
// ==== a) has waiting task, so let us complete it right away
143134
if (assumed.hasWaitingTask()) {
144135
auto waitingTask = waitQueue.load(std::memory_order_acquire);
145-
fprintf(stderr, "[%s:%d] (%s): has waiter! waiter:%d %s\n", __FILE__, __LINE__, __FUNCTION__, waitingTask, assumed.to_string().c_str());
146136
while (true) {
147-
fprintf(stderr, "[%s:%d] (%s): run waiting task directly!\n", __FILE__, __LINE__, __FUNCTION__);
148137
// ==== a) run waiting task directly -------------------------------------
149138
assert(assumed.hasWaitingTask());
150139
assert(assumed.pendingTasks() && "offered to group with no pending tasks!");
@@ -155,15 +144,11 @@ void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context,
155144
/*success*/ std::memory_order_release,
156145
/*failure*/ std::memory_order_acquire) &&
157146
statusCompletePendingReadyWaiting(assumed)) {
158-
fprintf(stderr, "[%s:%d] (%s): offer, claimed task!\n", __FILE__, __LINE__, __FUNCTION__);
159-
fprintf(stderr, "[%s:%d] (%s): status now! assumed: %s\n", __FILE__, __LINE__, __FUNCTION__, assumed.to_string().c_str());
160-
fprintf(stderr, "[%s:%d] (%s): status now! load: %s\n", __FILE__, __LINE__, __FUNCTION__, statusLoadRelaxed().to_string().c_str());
161147
// Run the task.
162148
auto result = PollResult::get(
163149
completedTask, hadErrorResult, /*needsRelease*/ false);
164150

165151
mutex.unlock(); // TODO: remove fragment lock, and use status for synchronization
166-
fprintf(stderr, "[%s:%d] (%s): RUN waiting:%d with result completed:%d\n", __FILE__, __LINE__, __FUNCTION__, waitingTask, completedTask);
167152
swift::runTaskWithPollResult(waitingTask, completingExecutor, result);
168153
return;
169154
} // else, try again
@@ -189,7 +174,6 @@ void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context,
189174

190175
assert(completedTask == readyItem.getTask());
191176
assert(readyItem.getTask()->isFuture());
192-
fprintf(stderr, "[%s:%d] (%s): enqueue in ready queue %d\n", __FILE__, __LINE__, __FUNCTION__, completedTask);
193177
readyQueue.enqueue(readyItem);
194178
mutex.unlock(); // TODO: remove fragment lock, and use status for synchronization
195179
return;
@@ -207,29 +191,16 @@ void swift::swift_task_group_wait_next(
207191
waitingTask->ResumeContext = rawContext;
208192

209193
auto context = static_cast<TaskGroupNextWaitAsyncContext *>(rawContext);
210-
fprintf(stderr, "[%s:%d] (%s): context %d\n", __FILE__, __LINE__, __FUNCTION__, context);
211194
auto task = context->task;
212195
auto group = context->group;
213-
fprintf(stderr, "[%s:%d] (%s): task %d\n", __FILE__, __LINE__, __FUNCTION__, task);
214-
fprintf(stderr, "[%s:%d] (%s): waitingTask %d\n", __FILE__, __LINE__, __FUNCTION__, waitingTask);
215-
fprintf(stderr, "[%s:%d] (%s): group %d\n", __FILE__, __LINE__, __FUNCTION__, group);
216196
TaskGroup::PollResult polled = group->poll(waitingTask);
217-
fprintf(stderr, "[%s:%d] (%s): group polled: %d\n", __FILE__, __LINE__, __FUNCTION__, polled.status);
218197

219198
if (polled.status == TaskGroup::GroupPollStatus::MustWait) {
220-
fprintf(stderr, "[%s:%d] (%s): group polled: WAITING\n", __FILE__, __LINE__, __FUNCTION__);
221199
// The waiting task has been queued on the channel,
222200
// there were pending tasks so it will be woken up eventually.
223201
return;
224202
}
225203

226-
if (polled.status == TaskGroup::GroupPollStatus::Empty)
227-
fprintf(stderr, "[%s:%d] (%s): group polled: RUN EMPTY\n", __FILE__, __LINE__, __FUNCTION__);
228-
if (polled.status == TaskGroup::GroupPollStatus::Success)
229-
fprintf(stderr, "[%s:%d] (%s): group polled: RUN SUCCESS\n", __FILE__, __LINE__, __FUNCTION__);
230-
if (polled.status == TaskGroup::GroupPollStatus::Error)
231-
fprintf(stderr, "[%s:%d] (%s): group polled: RUN ERROR\n", __FILE__, __LINE__, __FUNCTION__);
232-
233204
runTaskWithPollResult(waitingTask, executor, polled);
234205
}
235206

@@ -241,16 +212,12 @@ TaskGroup::PollResult TaskGroup::poll(AsyncTask *waitingTask) {
241212
result.storage = nullptr;
242213
result.retainedTask = nullptr;
243214

244-
fprintf(stderr, "[%s:%d] (%s): status %s\n", __FILE__, __LINE__, __FUNCTION__, assumed.to_string().c_str());
245-
246215
// ==== 1) bail out early if no tasks are pending ----------------------------
247216
if (assumed.isEmpty()) {
248217
// No tasks in flight, we know no tasks were submitted before this poll
249218
// was issued, and if we parked here we'd potentially never be woken up.
250219
// Bail out and return `nil` from `group.next()`.
251-
fprintf(stderr, "[%s:%d] (%s): empty! assumed: %s\n", __FILE__, __LINE__, __FUNCTION__, assumed.to_string().c_str());
252220
statusRemoveWaiting();
253-
fprintf(stderr, "[%s:%d] (%s): debug now: %s\n", __FILE__, __LINE__, __FUNCTION__, statusLoadRelaxed().to_string().c_str());
254221
result.status = TaskGroup::GroupPollStatus::Empty;
255222
mutex.unlock(); // TODO: remove group lock, and use status for synchronization
256223
return result;
@@ -260,8 +227,6 @@ TaskGroup::PollResult TaskGroup::poll(AsyncTask *waitingTask) {
260227

261228
// ==== 2) Ready task was polled, return with it immediately -----------------
262229
if (assumed.readyTasks()) {
263-
fprintf(stderr, "[%s:%d] (%s): there are ready tasks... %s\n", __FILE__, __LINE__, __FUNCTION__, statusLoadRelaxed().to_string().c_str());
264-
265230
auto assumedStatus = assumed.status;
266231
auto newStatus = TaskGroup::GroupStatus{assumedStatus};
267232
if (status.compare_exchange_weak(
@@ -287,8 +252,6 @@ TaskGroup::PollResult TaskGroup::poll(AsyncTask *waitingTask) {
287252
// be swift_release'd; we kept it alive while it was in the readyQueue by
288253
// an additional retain issued as we enqueued it there.
289254
result.retainedTask = item.getTask();
290-
fprintf(stderr, "[%s:%d] (%s): about to return: %d\n", __FILE__, __LINE__, __FUNCTION__, result.retainedTask);
291-
292255
switch (item.getStatus()) {
293256
case ReadyStatus::Success:
294257
// Immediately return the polled value
@@ -326,7 +289,6 @@ TaskGroup::PollResult TaskGroup::poll(AsyncTask *waitingTask) {
326289
waitHead, waitingTask,
327290
/*success*/ std::memory_order_release,
328291
/*failure*/ std::memory_order_acquire)) {
329-
fprintf(stderr, "[%s:%d] (%s): added to wait queue\n", __FILE__, __LINE__, __FUNCTION__);
330292
mutex.unlock(); // TODO: remove fragment lock, and use status for synchronization
331293
// no ready tasks, so we must wait.
332294
result.status = TaskGroup::GroupPollStatus::MustWait;
@@ -358,21 +320,13 @@ void swift::swift_task_group_cancel_all(AsyncTask *task, TaskGroup *group) {
358320
}
359321

360322
bool TaskGroup::cancelAll(AsyncTask *task) {
361-
fprintf(stderr, "[%s:%d] (%s): cancel all child tasks %d\n", __FILE__, __LINE__, __FUNCTION__, task);
362-
363323
// store the cancelled bit
364324
auto old = statusCancel();
365325
if (old.isCancelled()) {
366-
fprintf(stderr, "[%s:%d] (%s): already was cancelled, group:%d\n", __FILE__, __LINE__, __FUNCTION__, this);
367326
// already was cancelled previously, nothing to do?
368327
return false;
369328
}
370329

371-
// // first time this group is being called cancelAll on, so we must cancel all tasks
372-
// if (this->isEmpty())
373-
// return true;
374-
375-
fprintf(stderr, "[%s:%d] (%s): calling swift_task_cancel_group_child_tasks, group:%d\n", __FILE__, __LINE__, __FUNCTION__, this);
376330
// cancel all existing tasks within the group
377331
swift_task_cancel_group_child_tasks(task, this);
378332
return true;

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,13 @@ bool swift::swift_task_removeStatusRecord(AsyncTask *task,
350350
if (task->Status.compare_exchange_weak(oldStatus, newStatus,
351351
/*success*/ std::memory_order_release,
352352
/*failure*/ std::memory_order_relaxed)) {
353-
fprintf(stderr, "[%s:%d] (%s): removed record:%d in [%d]\n", __FILE__, __LINE__, __FUNCTION__, record, task);
354353
return !oldStatus.isCancelled();
355354
}
356355

357356
// Otherwise, restart.
358357
continue;
359358
}
360359

361-
fprintf(stderr, "[%s:%d] (%s): removing; no record match (found: %d kind:%d, want:%d kind:%d) in [%d]\n", __FILE__, __LINE__, __FUNCTION__,
362-
oldStatus.getInnermostRecord(), oldStatus.getInnermostRecord()->getKind(),
363-
record, record->getKind(),
364-
task);
365-
366360
// If the record is not the innermost record, we need to acquire the
367361
// record lock; there's no way to splice the record list safely with
368362
// a thread that's attempting to acquire the lock.
@@ -386,7 +380,6 @@ bool swift::swift_task_removeStatusRecord(AsyncTask *task,
386380
while (true) {
387381
auto next = cur->getParent();
388382
if (next == record) {
389-
fprintf(stderr, "[%s:%d] (%s): splicing out record:%d in [%d]\n", __FILE__, __LINE__, __FUNCTION__, record, task);
390383
cur->spliceParent(record->getParent());
391384
break;
392385
}
@@ -410,15 +403,12 @@ ChildTaskStatusRecord*
410403
swift::swift_task_attachChild(AsyncTask *parent, AsyncTask *child) {
411404
void *allocation = malloc(sizeof(swift::ChildTaskStatusRecord));
412405
auto record = new (allocation) swift::ChildTaskStatusRecord(child);
413-
fprintf(stderr, "[%s:%d] (%s): attach CHILD, task record in parent [%d]; child:%d %d\n", __FILE__, __LINE__, __FUNCTION__, parent, child, record);
414406
swift_task_addStatusRecord(parent, record);
415407
return record;
416408
}
417409

418410
void
419411
swift::swift_task_detachChild(AsyncTask *parent, ChildTaskStatusRecord *record) {
420-
fprintf(stderr, "[%s:%d] (%s): detach CHILD, task record in parent [%d]; child record:%d\n", __FILE__, __LINE__, __FUNCTION__,
421-
parent, record);
422412
swift_task_removeStatusRecord(parent, record);
423413
}
424414

@@ -434,15 +424,13 @@ static void performCancellationAction(TaskStatusRecord *record) {
434424

435425
// Child tasks need to be recursively cancelled.
436426
case TaskStatusRecordKind::ChildTask: {
437-
fprintf(stderr, "[%s:%d] (%s) child task\n", __FILE__, __LINE__, __FUNCTION__);
438427
auto childRecord = cast<ChildTaskStatusRecord>(record);
439428
for (AsyncTask *child: childRecord->children())
440429
swift_task_cancel(child);
441430
return;
442431
}
443432

444433
case TaskStatusRecordKind::TaskGroup: {
445-
fprintf(stderr, "[%s:%d] (%s) group child task\n", __FILE__, __LINE__, __FUNCTION__);
446434
auto childRecord = cast<TaskGroupTaskStatusRecord>(record);
447435
for (AsyncTask *child: childRecord->children())
448436
swift_task_cancel(child);
@@ -490,7 +478,6 @@ static void performGroupCancellationAction(TaskStatusRecord *record,
490478
// returns, all its task have been completed.
491479
assert(group == groupChildRecord->getGroup());
492480
for (AsyncTask *child: groupChildRecord->children()) {
493-
fprintf(stderr, "[%s:%d] (%s): fire cancel group:%d, record:%d\n", __FILE__, __LINE__, __FUNCTION__, group, record);
494481
swift_task_cancel(child);
495482
}
496483
return;
@@ -501,7 +488,6 @@ static void performGroupCancellationAction(TaskStatusRecord *record,
501488
case TaskStatusRecordKind::CancellationNotification:
502489
case TaskStatusRecordKind::EscalationNotification:
503490
case TaskStatusRecordKind::Private_RecordLock:
504-
fprintf(stderr, "[%s:%d] (%s): fire perform performCancellationAction group:%d, record:%d\n", __FILE__, __LINE__, __FUNCTION__, group, record);
505491
performCancellationAction(record);
506492
return;
507493
}
@@ -511,7 +497,6 @@ static void performGroupCancellationAction(TaskStatusRecord *record,
511497
}
512498

513499
void swift::swift_task_cancel(AsyncTask *task) {
514-
fprintf(stderr, "[%s:%d] (%s): cancel task: %d\n", __FILE__, __LINE__, __FUNCTION__, task);
515500
Optional<StatusRecordLockRecord> recordLockRecord;
516501

517502
// Acquire the status record lock.
@@ -531,8 +516,6 @@ void swift::swift_task_cancel(AsyncTask *task) {
531516
// Carry out the cancellation operations associated with all
532517
// the active records.
533518
for (auto cur: oldStatus.records()) {
534-
fprintf(stderr, "[%s:%d] (%s): task:%d record:%d type: %d\n", __FILE__, __LINE__, __FUNCTION__,
535-
task, cur, cur->getKind());
536519
performCancellationAction(cur);
537520
}
538521

@@ -545,7 +528,6 @@ void swift::swift_task_cancel(AsyncTask *task) {
545528
}
546529

547530
void swift::swift_task_cancel_group_child_tasks(AsyncTask *task, TaskGroup *group) {
548-
fprintf(stderr, "[%s:%d] (%s): cancel group task, task:%d group:\n", __FILE__, __LINE__, __FUNCTION__, task, group);
549531
Optional<StatusRecordLockRecord> recordLockRecord;
550532

551533
// Acquire the status record lock.
@@ -564,7 +546,7 @@ void swift::swift_task_cancel_group_child_tasks(AsyncTask *task, TaskGroup *grou
564546
// Release the status record lock, being sure to flag that
565547
// the task is now cancelled.
566548
ActiveTaskStatus cancelledStatus(oldStatus.getInnermostRecord(),
567-
/*cancelled*/ oldStatus.isCancelled(), // FIXME???
549+
/*cancelled*/ oldStatus.isCancelled(),
568550
/*locked*/ false);
569551
releaseStatusRecordLock(task, cancelledStatus, recordLockRecord);
570552
}

0 commit comments

Comments
 (0)