Skip to content

Commit 8ba48c6

Browse files
committed
do a CI test run
1 parent b70e21e commit 8ba48c6

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
390390
virtual void enqueueCompletedTask(AsyncTask *completedTask, bool hadErrorResult) = 0;
391391

392392
/// Resume waiting task with result from `completedTask`
393-
void resumeWaitingTask(AsyncTask *completedTask, TaskGroupStatus &assumed, bool hadErrorResult, bool alreadyDecremented = false);
393+
void resumeWaitingTask(AsyncTask *completedTask,
394+
TaskGroupStatus &assumed,
395+
bool hadErrorResult,
396+
bool alreadyDecremented = false,
397+
bool taskWasRetained = false);
394398

395399
// ==== Status manipulation -------------------------------------------------
396400

@@ -827,7 +831,9 @@ class DiscardingTaskGroup: public TaskGroupBase {
827831

828832
private:
829833
/// Resume waiting task with specified error
830-
void resumeWaitingTaskWithError(SwiftError *error, TaskGroupStatus &assumed, bool alreadyDecremented);
834+
void resumeWaitingTaskWithError(SwiftError *error,
835+
TaskGroupStatus &assumed,
836+
bool alreadyDecremented);
831837
};
832838

833839
} // end anonymous namespace
@@ -1240,11 +1246,16 @@ void DiscardingTaskGroup::offer(AsyncTask *completedTask, AsyncContext *context)
12401246
switch (readyErrorItem.getStatus()) {
12411247
case ReadyStatus::RawError:
12421248
SWIFT_TASK_GROUP_DEBUG_LOG(this, "offer, complete, resume with raw error:%p", readyErrorItem.getRawError(this));
1243-
resumeWaitingTaskWithError(readyErrorItem.getRawError(this), assumed, alreadyDecrementedStatus);
1249+
resumeWaitingTaskWithError(readyErrorItem.getRawError(this), assumed,
1250+
alreadyDecrementedStatus);
12441251
break;
12451252
case ReadyStatus::Error:
12461253
SWIFT_TASK_GROUP_DEBUG_LOG(this, "offer, complete, resume with errorItem.task:%p", readyErrorItem.getTask());
1247-
resumeWaitingTask(readyErrorItem.getTask(), assumed, /*hadErrorResult=*/true, alreadyDecrementedStatus);
1254+
SWIFT_TASK_GROUP_DEBUG_LOG(this, "offer, complete, expect that it was extra retained %p", readyErrorItem.getTask());
1255+
resumeWaitingTask(readyErrorItem.getTask(), assumed,
1256+
/*hadErrorResult=*/true,
1257+
alreadyDecrementedStatus,
1258+
/*taskWasRetained=*/true);
12481259
break;
12491260
default:
12501261
swift_Concurrency_fatalError(0,
@@ -1283,7 +1294,10 @@ void DiscardingTaskGroup::offer(AsyncTask *completedTask, AsyncContext *context)
12831294
resumeWaitingTaskWithError(readyErrorItem.getRawError(this), assumed, alreadyDecrementedStatus);
12841295
break;
12851296
case ReadyStatus::Error:
1286-
resumeWaitingTask(readyErrorItem.getTask(), assumed, /*hadErrorResult=*/true, alreadyDecrementedStatus);
1297+
resumeWaitingTask(readyErrorItem.getTask(), assumed,
1298+
/*hadErrorResult=*/true,
1299+
alreadyDecrementedStatus,
1300+
/*taskWasRetained=*/true);
12871301
break;
12881302
default:
12891303
swift_Concurrency_fatalError(0,
@@ -1317,7 +1331,8 @@ void TaskGroupBase::resumeWaitingTask(
13171331
AsyncTask *completedTask,
13181332
TaskGroupStatus &assumed,
13191333
bool hadErrorResult,
1320-
bool alreadyDecremented) {
1334+
bool alreadyDecremented,
1335+
bool taskWasRetained) {
13211336
auto waitingTask = waitQueue.load(std::memory_order_acquire);
13221337
assert(waitingTask && "waitingTask must not be null when attempting to resume it");
13231338
assert(assumed.hasWaitingTask());
@@ -1384,13 +1399,21 @@ void TaskGroupBase::resumeWaitingTask(
13841399
auto before = completedTask;
13851400
_swift_taskGroup_detachChild(asAbstract(this), completedTask);
13861401
SWIFT_TASK_GROUP_DEBUG_LOG(this, "completedTask %p; AFTER DETACH (count:%d)", completedTask, swift_retainCount(completedTask));
1387-
if (isDiscardingResults() && hadErrorResult) {
1402+
if (isDiscardingResults() && hadErrorResult && taskWasRetained) {
13881403
SWIFT_TASK_GROUP_DEBUG_LOG(this, "BEFORE RELEASE error task=%p (count:%d)\n",
13891404
completedTask,
13901405
swift_retainCount(completedTask));
1391-
// We only used the task to keep the error in the future fragment around
1406+
// We only used the task to keep the error in the future fragment around
13921407
// so now that we emitted the error and detached the task, we are free to release the task immediately.
1393-
swift_release(completedTask); // we need to do this if the error is a class
1408+
auto error = completedTask->futureFragment()->getError();
1409+
fprintf(stderr, "[%s:%d](%s) THE ERRROR IN RELEASING %p\n", __FILE_NAME__, __LINE__, __FUNCTION__,
1410+
error);
1411+
swift_release(completedTask);
1412+
// swift_errorRelease(error);
1413+
} else {
1414+
fprintf(stderr, "[%s:%d](%s) DID NOT RELEASE %p\n", __FILE_NAME__, __LINE__, __FUNCTION__,
1415+
completedTask);
1416+
// assert(false);
13941417
}
13951418

13961419
_swift_tsan_acquire(static_cast<Job *>(waitingTask));
@@ -1799,6 +1822,7 @@ void TaskGroupBase::waitAll(SwiftError* bodyError, AsyncTask *waitingTask,
17991822

18001823
#if SWIFT_TASK_GROUP_BODY_THROWN_ERROR_WINS
18011824
if (bodyError) {
1825+
// FIXME: are we ok with releases here?
18021826
fillGroupNextErrorResult(context, bodyError);
18031827
} else {
18041828
fillGroupNextResult(context, result);

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class TaskFutureWaitAsyncContext : public AsyncContext {
292292
fillWithError(future->getError());
293293
}
294294
void fillWithError(SwiftError *error) {
295+
fprintf(stderr, "[%s:%d](%s) FILL WITH ERROR %p\n", __FILE_NAME__, __LINE__, __FUNCTION__, error);
295296
errorResult = error;
296297
swift_errorRetain(error);
297298
}

stdlib/public/runtime/HeapObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ void swift::swift_unownedCheck(HeapObject *object) {
797797
void _swift_release_dealloc(HeapObject *object) {
798798
// assert(object);
799799
// if (!object->metadata) {
800-
fprintf(stderr, "[%s:%d](%s) object: %p\n", __FILE_NAME__, __LINE__, __FUNCTION__, object);
800+
// fprintf(stderr, "[%s:%d](%s) object: %p\n", __FILE_NAME__, __LINE__, __FUNCTION__, object);
801801
// }
802802
// assert(object->metadata);
803803
asFullMetadata(object->metadata)->destroy(object);

test/Concurrency/Runtime/async_taskgroup_discarding_dontLeak_class_error.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-leaks-swift( -Xfrontend -disable-availability-checking -parse-as-library)
1+
// RUN: %target-run-simple-leaks-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s --dump-input=always
22

33
// This test uses `leaks` which is only available on apple platforms; limit it to macOS:
44
// REQUIRES: OS=macosx
@@ -14,16 +14,18 @@
1414
// UNSUPPORTED: OS=windows-msvc
1515

1616
import _Concurrency
17+
import Darwin
1718

1819
final class ClassBoom: Error {
1920
let id: String
2021

2122
init(file: String = #fileID, line: UInt = #line) {
2223
self.id = "\(file):\(line)"
24+
fputs("INIT OF ClassBoom from \(id)", stderr)
2325
}
2426

25-
init(id: String) {
26-
self.id = id
27+
deinit {
28+
fputs("DEINIT OF ClassBoom from \(id)", stderr)
2729
}
2830
}
2931

@@ -49,6 +51,7 @@ final class ClassBoom: Error {
4951
}
5052

5153
return 12
54+
// CHECK: : 0 leaks
5255
}
5356
}
5457
}

0 commit comments

Comments
 (0)