Skip to content

Commit 599572b

Browse files
committed
cleanups of tests after merge
1 parent 6e525d7 commit 599572b

10 files changed

+27
-25
lines changed

include/swift/ABI/Task.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include "swift/Basic/RelativePointer.h"
2121
#include "swift/ABI/Executor.h"
2222
#include "swift/ABI/HeapObject.h"
23+
#include "swift/ABI/TaskGroup.h"
2324
#include "swift/ABI/Metadata.h"
2425
#include "swift/ABI/MetadataValues.h"
25-
#include "swift/Runtime/Concurrency.h"
2626
#include "swift/Runtime/Config.h"
2727
#include "swift/Basic/STLExtras.h"
2828
#include "bitset"
@@ -313,7 +313,7 @@ class AsyncTask : public HeapObject, public Job {
313313
assert(task);
314314
size_t amountToAllocate = TaskLocalItem::itemSize(valueType);
315315
// assert(amountToAllocate % MaximumAlignment == 0); // TODO: do we need this?
316-
void *allocation = malloc(amountToAllocate); // TODO: use task-local allocator
316+
void *allocation = malloc(amountToAllocate); // TODO: use task-local allocator rdar://74218679
317317
TaskLocalItem *item =
318318
new(allocation) TaskLocalItem(keyType, valueType);
319319

include/swift/ABI/TaskGroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/ABI/Executor.h"
2222
#include "swift/ABI/HeapObject.h"
2323
#include "swift/ABI/Metadata.h"
24+
#include "swift/ABI/TaskStatus.h"
2425
#include "swift/ABI/MetadataValues.h"
2526
#include "swift/Runtime/Config.h"
2627
#include "swift/Basic/STLExtras.h"

include/swift/Runtime/Concurrency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_RUNTIME_CONCURRENCY_H
1919

2020
#include "swift/ABI/TaskStatus.h"
21+
#include "swift/ABI/TaskGroup.h"
2122

2223
namespace swift {
2324
class DefaultActor;

stdlib/public/Concurrency/Task.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension Task {
5050
/// All functions available on the Task
5151
// TODO: once we can have async properties land make this computed property
5252
public static func current() async -> Task {
53-
Task.unsafeCurrent!.task // !-safe, we are guaranteed to have a task available within an async function
53+
return Task.unsafeCurrent!.task // !-safe, we are guaranteed to have a task available within an async function
5454
}
5555

5656
}

test/Concurrency/Runtime/async_task_cancellation_early.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func test_runDetached_cancel_child_early() async {
1717
let h: Task.Handle<Bool, Error> = Task.runDetached {
1818
async let childCancelled: Bool = { () -> Bool in
1919
sleep(2)
20-
return await Task.__unsafeCurrentAsync().isCancelled
20+
return Task.isCancelled
2121
}()
2222

2323
let xx = await childCancelled
2424
print("child, cancelled: \(xx)") // CHECK: child, cancelled: true
25-
let cancelled = await Task.__unsafeCurrentAsync().isCancelled
25+
let cancelled = Task.isCancelled
2626
print("self, cancelled: \(cancelled )") // CHECK: self, cancelled: true
2727
return cancelled
2828
}

test/Concurrency/Runtime/async_task_cancellation_while_running.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func test_runDetached_cancel_while_child_running() async {
1616
let h: Task.Handle<Bool, Error> = Task.runDetached {
1717
async let childCancelled: Bool = { () -> Bool in
1818
sleep(3)
19-
return await Task.__unsafeCurrentAsync().isCancelled
19+
return Task.isCancelled
2020
}()
2121

2222
let childWasCancelled = await childCancelled
2323
print("child, cancelled: \(childWasCancelled)") // CHECK: child, cancelled: true
24-
let selfWasCancelled = await Task.__unsafeCurrentAsync().isCancelled
24+
let selfWasCancelled = Task.isCancelled
2525
print("self, cancelled: \(selfWasCancelled )") // CHECK: self, cancelled: true
2626
return selfWasCancelled
2727
}

test/Concurrency/Runtime/async_taskgroup_cancelAll_only_specific_group.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func test_taskGroup_cancelAll_onlySpecificGroup() async {
2424
for i in 1...5 {
2525
await group.add {
2626
sleep(1)
27-
let c = await Task.__unsafeCurrentAsync().isCancelled
27+
let c = Task.isCancelled
2828
print("add: \(i) (cancelled: \(c))")
2929
return i
3030
}
@@ -36,7 +36,7 @@ func test_taskGroup_cancelAll_onlySpecificGroup() async {
3636
sum += got
3737
}
3838

39-
let c = await Task.__unsafeCurrentAsync().isCancelled
39+
let c = Task.isCancelled
4040
print("g1 task cancelled: \(c)")
4141
let cc = group.isCancelled
4242
print("g1 group cancelled: \(cc)")
@@ -49,7 +49,7 @@ func test_taskGroup_cancelAll_onlySpecificGroup() async {
4949
for i in 1...3 {
5050
await group.add {
5151
sleep(1)
52-
let c = await Task.__unsafeCurrentAsync().isCancelled
52+
let c = Task.isCancelled
5353
print("g1 task \(i) (cancelled: \(c))")
5454
return i
5555
}
@@ -58,7 +58,7 @@ func test_taskGroup_cancelAll_onlySpecificGroup() async {
5858
print("cancelAll")
5959
group.cancelAll()
6060

61-
let c = await Task.__unsafeCurrentAsync().isCancelled
61+
let c = Task.isCancelled
6262
print("g2 task cancelled: \(c)")
6363
let cc = group.isCancelled
6464
print("g2 group cancelled: \(cc)")

test/Concurrency/Runtime/async_taskgroup_cancel_parent_affects_group.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ func test_taskGroup_cancel_parent_affects_group() async {
2222
try! await Task.withGroup(resultType: Int.self) { group -> Void in
2323
await group.add {
2424
sleep(3)
25-
let c = await Task.__unsafeCurrentAsync().isCancelled
25+
let c = Task.isCancelled
2626
print("group task isCancelled: \(c)")
2727
return 0
2828
}
2929

3030
_ = try! await group.next()
31-
let c = await Task.__unsafeCurrentAsync().isCancelled
31+
let c = Task.isCancelled
3232
print("group isCancelled: \(c)")
3333
}
34-
let c = await Task.__unsafeCurrentAsync().isCancelled
34+
let c = Task.isCancelled
3535
print("detached task isCancelled: \(c)")
3636
}
3737

test/Concurrency/Runtime/async_taskgroup_cancel_then_completions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func test_taskGroup_cancel_then_completions() async {
2626
print("start first")
2727
sleep(1)
2828
print("done first")
29-
return (1, await Task.__unsafeCurrentAsync().isCancelled)
29+
return (1, Task.isCancelled)
3030
}
3131
print("added first: \(addedFirst)") // CHECK: added first: true
3232
assert(addedFirst)
@@ -35,7 +35,7 @@ func test_taskGroup_cancel_then_completions() async {
3535
print("start second")
3636
sleep(3)
3737
print("done second")
38-
return (2, await Task.__unsafeCurrentAsync().isCancelled)
38+
return (2, Task.isCancelled)
3939
}
4040
print("added second: \(addedSecond)") // CHECK: added second: true
4141
assert(addedSecond)

test/Concurrency/Runtime/async_taskgroup_next_not_invoked_cancelAll.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ func test_skipCallingNext_butInvokeCancelAll() async {
1818
let result = try! await Task.withGroup(resultType: Int.self) { (group) async -> Int in
1919
for n in numbers {
2020
print("group.add { \(n) }")
21-
await group.add { () async -> Int in
21+
await group.add { [group] () async -> Int in
2222
sleep(2)
2323
print(" inside group.add { \(n) }")
24-
let cancelled = Task.isCancelled
25-
print(" inside group.add { \(n) } (canceled: \(cancelled))")
24+
print(" inside group.add { \(n) } (group cancelled: \(group.isCancelled))")
25+
print(" inside group.add { \(n) } (group child task cancelled: \(Task.isCancelled))")
2626
return n
2727
}
2828
}
2929

3030
group.cancelAll()
3131

3232
// return immediately; the group should wait on the tasks anyway
33-
let c = Task.isCancelled
34-
print("return immediately 0 (canceled: \(c))")
3533
print("return immediately 0 (group cancelled: \(group.isCancelled))")
34+
print("return immediately 0 (task cancelled: \(Task.isCancelled))")
3635
return 0
3736
}
3837

3938
// CHECK: group.add { 1 }
40-
// CHECK: group.add { 1 }
41-
// CHECK: return immediately 0 (task cancelled: false)
39+
//
4240
// CHECK: return immediately 0 (group cancelled: true)
43-
// CHECK: inside group.add { 1 } (task cancelled: true)
44-
// CHECK: inside group.add { 1 } (task cancelled: true)
41+
// CHECK: return immediately 0 (task cancelled: false)
42+
//
43+
// CHECK: inside group.add { 1 } (group cancelled: true)
44+
// CHECK: inside group.add { 1 } (group child task cancelled: true)
4545

4646
// CHECK: result: 0
4747
print("result: \(result)")

0 commit comments

Comments
 (0)