Skip to content

Commit a55ebff

Browse files
committed
[Concurrency] deprecate not implemented Task functions, until they're implemented
1 parent e7cfc8c commit a55ebff

13 files changed

+56
-79
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
////
1111
////===----------------------------------------------------------------------===//
1212

13-
import Dispatch
14-
#if canImport(Darwin)
15-
import Darwin
16-
#elseif canImport(Glibc)
17-
import Glibc
18-
#elseif os(Windows)
19-
import CRT
20-
#endif
21-
22-
2313
import Swift
2414
@_implementationOnly import _SwiftConcurrencyShims
2515

@@ -58,9 +48,11 @@ extension Task {
5848
/// this function was called.
5949
///
6050
/// 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.
51+
// TODO: once we can have async properties land make this computed property
52+
@available(*, deprecated, message: "Please use Builtin.getCurrentAsyncTask() or Task.__unsafeCurrentAsync() until this function becomes implemented.")
53+
public static func current(file: StaticString = #file, line: UInt = #line) async -> Task {
54+
fatalError("Task.current() is not implemented yet!", file: file, line: line)
55+
Task.unsafeCurrent!.task // !-safe, guaranteed to have a Task available within an async function.
6456
}
6557

6658
}
@@ -75,6 +67,7 @@ extension Task {
7567
///
7668
/// - SeeAlso: `Task.Priority`
7769
/// - SeeAlso: `Task.priority`
70+
@available(*, deprecated, message: "Not implemented yet, until unsafeCurrent is ready. Please use Task.__unsafeCurrentAsync().priority instead.")
7871
public static var currentPriority: Priority {
7972
Task.unsafeCurrent?.priority ?? Priority.default
8073
}
@@ -235,29 +228,29 @@ extension Task.Handle where Failure == Never {
235228

236229
extension Task.Handle: Hashable {
237230
public func hash(into hasher: inout Hasher) {
238-
unsafeBitCast(_task, to: size_t.self).hash(into: &hasher)
231+
UnsafeRawPointer(Builtin.bridgeToRawPointer(_task)).hash(into: &hasher)
239232
}
240233
}
241234

242235
extension Task.Handle: Equatable {
243236
public static func ==(lhs: Self, rhs: Self) -> Bool {
244-
unsafeBitCast(lhs._task, to: size_t.self) ==
245-
unsafeBitCast(rhs._task, to: size_t.self)
237+
UnsafeRawPointer(Builtin.bridgeToRawPointer(lhs._task)) ==
238+
UnsafeRawPointer(Builtin.bridgeToRawPointer(rhs._task))
246239
}
247240
}
248241

249242
// ==== Conformances -----------------------------------------------------------
250243

251244
extension Task: Hashable {
252245
public func hash(into hasher: inout Hasher) {
253-
unsafeBitCast(_task, to: size_t.self).hash(into: &hasher)
246+
UnsafeRawPointer(Builtin.bridgeToRawPointer(_task)).hash(into: &hasher)
254247
}
255248
}
256249

257250
extension Task: Equatable {
258251
public static func ==(lhs: Self, rhs: Self) -> Bool {
259-
unsafeBitCast(lhs._task, to: size_t.self) ==
260-
unsafeBitCast(rhs._task, to: size_t.self)
252+
UnsafeRawPointer(Builtin.bridgeToRawPointer(lhs._task)) ==
253+
UnsafeRawPointer(Builtin.bridgeToRawPointer(rhs._task))
261254
}
262255
}
263256

@@ -389,6 +382,8 @@ extension Task {
389382
startingOn executor: ExecutorRef? = nil,
390383
operation: @concurrent @escaping () async -> T
391384
) -> Handle<T, Never> {
385+
assert(executor == nil, "Custom executor support is not implemented yet.") // FIXME
386+
392387
// Set up the job flags for a new task.
393388
var flags = JobFlags()
394389
flags.kind = .task
@@ -441,6 +436,8 @@ extension Task {
441436
startingOn executor: ExecutorRef? = nil,
442437
operation: @concurrent @escaping () async throws -> T
443438
) -> Handle<T, Failure> {
439+
assert(executor == nil, "Custom executor support is not implemented yet.") // FIXME
440+
444441
// Set up the job flags for a new task.
445442
var flags = JobFlags()
446443
flags.kind = .task
@@ -476,6 +473,7 @@ extension Task {
476473
/// This is not a perfect cure for starvation;
477474
/// if the task is the highest-priority task in the system, it might go
478475
/// immediately back to executing.
476+
@available(*, deprecated, message: "Not implemented yet.")
479477
public static func yield() async {
480478
fatalError("\(#function) not implemented yet.")
481479
}
@@ -494,17 +492,18 @@ extension Task {
494492
/// asynchronous function present in this functions call stack.
495493
///
496494
/// The returned value must not be accessed from tasks other than the current one.
495+
@available(*, deprecated, message: "Not implemented yet, use Builtin.getCurrentAsyncTask() or Task.___unsafeCurrentAsync() until this function is implemented.")
497496
public static var unsafeCurrent: UnsafeCurrentTask? {
498497
// FIXME: rdar://70546948 implement this once getCurrentAsyncTask can be called from sync funcs
499498
// guard let _task = Builtin.getCurrentAsyncTask() else {
500499
// return nil
501500
// }
502501
// return UnsafeCurrentTask(_task)
503-
fatalError("\(#function) is not implemented yet, can not (yet) get task from sync function")
502+
fatalError("\(#function) is not implemented yet")
504503
}
505504

506-
@available(*, deprecated, message: "This should be removed", renamed: "unsafeCurrent()")
507-
public static func unsafeCurrentASYNC() async -> UnsafeCurrentTask {
505+
@available(*, deprecated, message: "This will be removed, and replaced by unsafeCurrent().", renamed: "unsafeCurrent()")
506+
public static func __unsafeCurrentAsync() async -> UnsafeCurrentTask {
508507
let task = Builtin.getCurrentAsyncTask()
509508
_swiftRetain(task)
510509
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ 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
18-
print(one == two) // CHECK: true
16+
let one = await Task.__unsafeCurrentAsync().task // FIXME: replace with Task.current
17+
let two = await Task.__unsafeCurrentAsync().task // FIXME: replace with Task.current
18+
print("same equal: \(one == two)") // CHECK: same equal: 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
24-
print(three == two) // CHECK: false
25-
print("hashes equal: \(three.hashValue == two.hashValue)") // CHECK: hashes equal: false
24+
print("parent/child equal: \(three == two)") // CHECK: parent/child equal: false
25+
print("parent/child hashes equal: \(three.hashValue == two.hashValue)") // CHECK: parent/child hashes equal: false
2626
}
2727
}

test/Concurrency/Runtime/async_task_priority_current.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@ 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 {
34+
@concurrent
3435
func loopUntil(priority: Task.Priority) async {
35-
while (await Task.unsafeCurrentASYNC().task.priority != priority) {
36+
while (await Task.__unsafeCurrentAsync().task.priority != priority) {
3637
sleep(1)
3738
}
3839
}

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/Runtime/basic_future.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func testSimple(
2727

2828
var completed = false
2929

30-
let taskHandle = Task.runDetached { () async throws -> String in
30+
let taskHandle: Task.Handle<String, Error> = Task.runDetached {
3131
let greeting = await formGreeting(name: name)
3232

3333
// If the intent is to test suspending, wait a bit so the second task

0 commit comments

Comments
 (0)