Skip to content

Commit 679a24a

Browse files
committed
do a CI test run
1 parent b70e21e commit 679a24a

File tree

5 files changed

+64
-48
lines changed

5 files changed

+64
-48
lines changed

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
using namespace swift;
6666

67-
#if 1
67+
#if 0
6868
#define SWIFT_TASK_GROUP_DEBUG_LOG(group, fmt, ...) \
6969
fprintf(stderr, "[%#lx] [%s:%d][group(%p%s)] (%s) " fmt "\n", \
7070
(unsigned long)Thread::current().platformThreadId(), \
@@ -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.swift

Lines changed: 14 additions & 15 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
// REQUIRES: concurrency
44
// REQUIRES: executable_test
@@ -11,31 +11,30 @@
1111
// UNSUPPORTED: OS=windows-msvc
1212

1313
import _Concurrency
14-
import Darwin
1514

16-
final class FIRST_PAYLOAD {}
17-
final class SECOND_PAYLOAD {}
15+
final class PayloadFirst {}
16+
final class PayloadSecond {}
1817

19-
final class FIRST_ERROR: Error {
20-
let first: FIRST_PAYLOAD
18+
final class ErrorFirst: Error {
19+
let first: PayloadFirst
2120

2221
init(file: String = #fileID, line: UInt = #line) {
2322
first = .init()
2423
}
2524
deinit {
26-
fputs("\(Self.self) deinit\n", stderr)
25+
print("deinit \(self)")
2726
}
2827
}
2928

30-
final class SECOND_ERROR: Error {
31-
let second: SECOND_PAYLOAD
29+
final class ErrorSecond: Error {
30+
let second: PayloadSecond
3231

3332
init(file: String = #fileID, line: UInt = #line) {
3433
second = .init()
3534
}
3635

3736
deinit {
38-
fputs("\(Self.self) deinit\n", stderr)
37+
print("deinit \(self)")
3938
}
4039
}
4140

@@ -55,20 +54,20 @@ func shouldStartWith(_ lhs: Any, _ rhs: Any) {
5554
1
5655
}
5756
group.addTask {
58-
throw FIRST_ERROR()
57+
throw ErrorFirst()
5958
}
6059

61-
// try? await Task.sleep(for: .seconds(1))
62-
6360
group.addTask {
64-
throw SECOND_ERROR()
61+
throw ErrorSecond()
6562
}
6663

6764
return 12
6865
}
6966
fatalError("expected error to be re-thrown, got: \(got)")
7067
} catch {
71-
// shouldStartWith(error, "main.Boom")
68+
shouldStartWith(error, "main.Error")
7269
}
70+
// CHECK: deinit main.Error
71+
// CHECK: deinit main.Error
7372
}
7473
}
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// RUN: %target-run-simple-leaks-swift( -Xfrontend -disable-availability-checking -parse-as-library)
2-
3-
// This test uses `leaks` which is only available on apple platforms; limit it to macOS:
4-
// REQUIRES: OS=macosx
1+
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s --dump-input=always
52

63
// REQUIRES: concurrency
74
// REQUIRES: executable_test
@@ -20,10 +17,11 @@ final class ClassBoom: Error {
2017

2118
init(file: String = #fileID, line: UInt = #line) {
2219
self.id = "\(file):\(line)"
20+
print("INIT OF ClassBoom from \(id)")
2321
}
2422

25-
init(id: String) {
26-
self.id = id
23+
deinit {
24+
print("DEINIT OF ClassBoom from \(id)")
2725
}
2826
}
2927

@@ -32,23 +30,17 @@ final class ClassBoom: Error {
3230

3331
// many errors
3432
_ = try? await withThrowingDiscardingTaskGroup() { group in
35-
group.addTask {
36-
throw ClassBoom()
37-
}
38-
group.addTask {
39-
throw ClassBoom()
40-
}
41-
group.addTask {
42-
throw ClassBoom()
43-
}
44-
group.addTask {
45-
throw ClassBoom()
46-
}
47-
group.addTask {
48-
12
49-
}
50-
33+
group.addTask { throw ClassBoom() }
34+
group.addTask { throw ClassBoom() }
35+
group.addTask { throw ClassBoom() }
36+
group.addTask { throw ClassBoom() }
37+
group.addTask { 12 }
5138
return 12
39+
40+
// CHECK: DEINIT OF ClassBoom
41+
// CHECK: DEINIT OF ClassBoom
42+
// CHECK: DEINIT OF ClassBoom
43+
// CHECK: DEINIT OF ClassBoom
5244
}
5345
}
5446
}

0 commit comments

Comments
 (0)