Skip to content

Commit 9e18cbd

Browse files
committed
[Concurrency] deprecate not implemented Task functions, until they're implemented
1 parent 9c6d89b commit 9e18cbd

11 files changed

+45
-58
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Glibc
1919
import CRT
2020
#endif
2121

22-
2322
import Swift
2423
@_implementationOnly import _SwiftConcurrencyShims
2524

@@ -58,9 +57,11 @@ extension Task {
5857
/// this function was called.
5958
///
6059
/// All functions available on the Task
61-
// TODO: once Kavon's async properties land make this computed property
62-
public static func current() async -> Task {
63-
Task.unsafeCurrent!.task // !-safe, guaranteed to have a Task available.
60+
// TODO: once we can have async properties land make this computed property
61+
@available(*, deprecated, message: "Please use Builtin.getCurrentAsyncTask() or Task.__unsafeCurrentAsync() until this function becomes implemented.")
62+
public static func current(file: StaticString = #file, line: UInt = #line) async -> Task {
63+
fatalError("Task.current() is not implemented yet!", file: file, line: line)
64+
Task.unsafeCurrent!.task // !-safe, guaranteed to have a Task available within an async function.
6465
}
6566

6667
}
@@ -75,6 +76,7 @@ extension Task {
7576
///
7677
/// - SeeAlso: `Task.Priority`
7778
/// - SeeAlso: `Task.priority`
79+
@available(*, deprecated, message: "Not implemented yet, until unsafeCurrent is ready. Please use Task.__unsafeCurrentAsync().priority instead.")
7880
public static var currentPriority: Priority {
7981
Task.unsafeCurrent?.priority ?? Priority.default
8082
}
@@ -389,6 +391,8 @@ extension Task {
389391
startingOn executor: ExecutorRef? = nil,
390392
operation: @concurrent @escaping () async -> T
391393
) -> Handle<T, Never> {
394+
assert(executor == nil, "Custom executor support is not implemented yet.") // FIXME
395+
392396
// Set up the job flags for a new task.
393397
var flags = JobFlags()
394398
flags.kind = .task
@@ -441,6 +445,8 @@ extension Task {
441445
startingOn executor: ExecutorRef? = nil,
442446
operation: @concurrent @escaping () async throws -> T
443447
) -> Handle<T, Failure> {
448+
assert(executor == nil, "Custom executor support is not implemented yet.") // FIXME
449+
444450
// Set up the job flags for a new task.
445451
var flags = JobFlags()
446452
flags.kind = .task
@@ -476,6 +482,7 @@ extension Task {
476482
/// This is not a perfect cure for starvation;
477483
/// if the task is the highest-priority task in the system, it might go
478484
/// immediately back to executing.
485+
@available(*, deprecated, message: "Not implemented yet.")
479486
public static func yield() async {
480487
fatalError("\(#function) not implemented yet.")
481488
}
@@ -494,17 +501,18 @@ extension Task {
494501
/// asynchronous function present in this functions call stack.
495502
///
496503
/// The returned value must not be accessed from tasks other than the current one.
504+
@available(*, deprecated, message: "Not implemented yet, use Builtin.getCurrentAsyncTask() or Task.___unsafeCurrentAsync() until this function is implemented.")
497505
public static var unsafeCurrent: UnsafeCurrentTask? {
498506
// FIXME: rdar://70546948 implement this once getCurrentAsyncTask can be called from sync funcs
499507
// guard let _task = Builtin.getCurrentAsyncTask() else {
500508
// return nil
501509
// }
502510
// return UnsafeCurrentTask(_task)
503-
fatalError("\(#function) is not implemented yet, can not (yet) get task from sync function")
511+
fatalError("\(#function) is not implemented yet")
504512
}
505513

506-
@available(*, deprecated, message: "This should be removed", renamed: "unsafeCurrent()")
507-
public static func unsafeCurrentASYNC() async -> UnsafeCurrentTask {
514+
@available(*, deprecated, message: "This will be removed, and replaced by unsafeCurrent().", renamed: "unsafeCurrent()")
515+
public static func __unsafeCurrentAsync() async -> UnsafeCurrentTask {
508516
let task = Builtin.getCurrentAsyncTask()
509517
_swiftRetain(task)
510518
return UnsafeCurrentTask(task)

test/Concurrency/Runtime/actor_counters.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
5858
}
5959

6060
// Create a bunch of worker threads.
61-
var workers: [Task.Handle<Void>] = []
61+
var workers: [Task.Handle<Void, Error>] = []
6262
for i in 0..<numWorkers {
6363
workers.append(
6464
Task.runDetached {

test/Concurrency/Runtime/async_task_equals_hashCode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import Glibc
1313

1414
@main struct Main {
1515
static func main() async {
16-
let one = await Task.unsafeCurrentASYNC().task // FIXME: replace with Task.current
17-
let two = await Task.unsafeCurrentASYNC().task // FIXME: replace with Task.current
16+
let one = await Task.__unsafeCurrentAsync().task // FIXME: replace with Task.current
17+
let two = await Task.__unsafeCurrentAsync().task // FIXME: replace with Task.current
1818
print(one == two) // CHECK: true
1919
print("hashes equal: \(one.hashValue == two.hashValue)") // CHECK: hashes equal: true
2020

21-
async let x = Task.unsafeCurrentASYNC().task // FIXME: replace with Task.current
21+
async let x = Task.__unsafeCurrentAsync().task // FIXME: replace with Task.current
2222

2323
let three = await x
2424
print(three == two) // CHECK: false

test/Concurrency/Runtime/async_task_priority_current.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ import CRT
1515
// FIXME: use `Task.currentPriority` once unsafeCurrent works in all these
1616

1717
func test_detach() async {
18-
let a1 = await Task.unsafeCurrentASYNC().task.priority
18+
let a1 = await Task.__unsafeCurrentAsync().task.priority
1919
print("a1: \(a1)") // CHECK: a1: default
2020

2121
// Note: remember to detach using a higher priority, otherwise a lower one
2222
// might be escalated by the get() and we could see `default` in the detached
2323
// task.
2424
await Task.runDetached(priority: .userInitiated) {
25-
let a2 = await Task.unsafeCurrentASYNC().task.priority
25+
let a2 = await Task.__unsafeCurrentAsync().task.priority
2626
print("a2: \(a2)") // CHECK: a2: userInitiated
2727
}.get()
2828

29-
let a3 = await Task.unsafeCurrentASYNC().task.priority
29+
let a3 = await Task.__unsafeCurrentAsync().task.priority
3030
print("a3: \(a3)") // CHECK: a3: default
3131
}
3232

3333
func test_multiple_lo_indirectly_escalated() async {
3434
func loopUntil(priority: Task.Priority) async {
35-
while (await Task.unsafeCurrentASYNC().task.priority != priority) {
35+
while (await Task.__unsafeCurrentAsync().task.priority != priority) {
3636
sleep(1)
3737
}
3838
}

test/Concurrency/Runtime/async_taskgroup_is_empty.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input always
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s
22
// REQUIRES: executable_test
33
// REQUIRES: concurrency
44
// XFAIL: windows

test/Concurrency/Runtime/async_taskgroup_next_not_invoked_cancelAll.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func test_skipCallingNext_butInvokeCancelAll() async {
1616
await group.add { () async -> Int in
1717
sleep(1)
1818
print(" inside group.add { \(n) }")
19-
let cancelled = Task.isCancelled
19+
let cancelled = await Task.__unsafeCurrentAsync().isCancelled
2020
print(" inside group.add { \(n) } (canceled: \(cancelled))")
2121
return n
2222
}
@@ -25,7 +25,8 @@ func test_skipCallingNext_butInvokeCancelAll() async {
2525
group.cancelAll()
2626

2727
// return immediately; the group should wait on the tasks anyway
28-
print("return immediately 0 (canceled: \(Task.isCancelled))")
28+
let c = await Task.__unsafeCurrentAsync().isCancelled
29+
print("return immediately 0 (canceled: \(c))")
2930
return 0
3031
}
3132

test/Concurrency/Runtime/async_taskgroup_next_not_invoked_without_cancelAll.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ func test_skipCallingNext() async {
1515
print("group.add { \(n) }")
1616
await group.add { () async -> Int in
1717
sleep(1)
18-
print(" inside group.add { \(n) } (canceled: \(Task.isCancelled))")
18+
let c = await Task.__unsafeCurrentAsync().isCancelled
19+
print(" inside group.add { \(n) } (canceled: \(c))")
1920
return n
2021
}
2122
}
2223

2324
// return immediately; the group should wait on the tasks anyway
24-
print("return immediately 0 (canceled: \(Task.isCancelled))")
25+
let c = await Task.__unsafeCurrentAsync().isCancelled
26+
print("return immediately 0 (canceled: \(c))")
2527
return 0
2628
}
2729

test/Concurrency/Runtime/async_taskgroup_throw_recover.swift

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input always
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s
22
// REQUIRES: executable_test
33
// REQUIRES: concurrency
44
// XFAIL: windows
@@ -7,21 +7,12 @@
77

88
import Dispatch
99

10-
struct Boom: Error {
11-
}
12-
13-
struct IgnoredBoom: Error {
14-
}
15-
16-
func one()
17-
18-
async -> Int {
19-
1
20-
}
10+
struct Boom: Error {}
11+
struct IgnoredBoom: Error {}
2112

22-
func boom()
13+
func one() async -> Int { 1 }
2314

24-
async throws -> Int {
15+
func boom() async throws -> Int {
2516
throw Boom()
2617
}
2718

@@ -40,7 +31,8 @@ func test_taskGroup_throws() async {
4031
print("error caught in group: \(error)")
4132

4233
await group.add { () async -> Int in
43-
print("task 3 (cancelled: \(Task.isCancelled))")
34+
let c = await Task.__unsafeCurrentAsync().isCancelled
35+
print("task 3 (cancelled: \(c))")
4436
return 3
4537
}
4638

test/Concurrency/Runtime/async_taskgroup_throw_rethrow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input always
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s
22
// REQUIRES: executable_test
33
// REQUIRES: concurrency
44

test/Concurrency/async_cancellation.swift

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ enum PictureData {
77
}
88

99
func test_cancellation_checkCancellation() async throws {
10-
try await Task.checkCancellation()
10+
try Task.checkCancellation()
1111
}
1212

1313
func test_cancellation_guard_isCancelled(_ any: Any) async -> PictureData {
14-
guard await !Task.isCancelled() else {
14+
guard !Task.isCancelled else {
1515
return PictureData.failedToLoadImagePlaceholder
1616
}
1717

@@ -23,7 +23,7 @@ struct SomeFile {
2323
}
2424

2525
func test_cancellation_withCancellationHandler(_ anything: Any) async -> PictureData {
26-
let handle = Task.runDetached { () -> PictureData in
26+
let handle: Task.Handle<PictureData, Error> = Task.runDetached {
2727
let file = SomeFile()
2828

2929
return try await Task.withCancellationHandler(
@@ -41,25 +41,9 @@ func test_cancellation_loop() async -> Int {
4141

4242
let tasks = [SampleTask(), SampleTask()]
4343
var processed = 0
44-
for t in tasks where await !Task.isCancelled() {
44+
for t in tasks where !Task.isCancelled {
4545
await t.process()
4646
processed += 1
4747
}
4848
return processed
4949
}
50-
51-
// ==== Deadlines --------------------------------------------------------------
52-
53-
func int() async -> Int { 42 }
54-
55-
func test_cancellation_withDeadline_in() async throws -> Int {
56-
await Task.withDeadline(in: .seconds(5), operation: {
57-
await int()
58-
})
59-
}
60-
61-
func test_cancellation_withDeadline(specificDeadline: Task.Deadline) async -> Int {
62-
await Task.withDeadline(specificDeadline) {
63-
await int()
64-
}
65-
}

test/Concurrency/async_tasks.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ func test_detached() async throws {
8282
await someAsyncFunc() // able to call async functions
8383
}
8484

85-
let result: String = try await handle.get()
85+
let result: String = await handle.get()
8686
_ = result
8787
}
8888

8989
func test_detached_throwing() async -> String {
90-
let handle: Task.Handle<String> = Task.runDetached() {
90+
let handle: Task.Handle<String, Error> = Task.runDetached() {
9191
try await someThrowingAsyncFunc() // able to call async functions
9292
}
9393

0 commit comments

Comments
 (0)