Skip to content

Commit a6ea9bf

Browse files
authored
Merge pull request #39720 from DougGregor/pick-fix-task-instance-isCancelled
2 parents 06b73da + 363f3cb commit a6ea9bf

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ endif()
4141
# Don't emit extended frame info on platforms other than darwin, system
4242
# backtracer and system debugger are unlikely to support it.
4343
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
44-
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS
45-
"-fswift-async-fp=${swift_concurrency_async_fp_mode}")
4644
list(APPEND SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS
4745
"-Xfrontend"
4846
"-swift-async-frame-pointer=${swift_concurrency_async_fp_mode}")
4947
else()
50-
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS "-fswift-async-fp=never")
5148
endif()
5249

5350
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB

stdlib/public/Concurrency/Task.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ func _taskCancel(_ task: Builtin.NativeObject)
860860

861861
@available(SwiftStdlib 5.5, *)
862862
@_silgen_name("swift_task_isCancelled")
863+
@usableFromInline
863864
func _taskIsCancelled(_ task: Builtin.NativeObject) -> Bool
864865

865866
@available(SwiftStdlib 5.5, *)

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ extension Task {
5050
/// There is no way to uncancel a task.
5151
///
5252
/// - SeeAlso: `checkCancellation()`
53-
public var isCancelled: Bool {
54-
withUnsafeCurrentTask { task in
55-
guard let task = task else {
56-
return false
57-
}
58-
59-
return _taskIsCancelled(task._task)
60-
}
53+
@_transparent public var isCancelled: Bool {
54+
_taskIsCancelled(_task)
6155
}
6256
}
6357

test/Concurrency/Runtime/async_task_handle_cancellation.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@
1717
@available(SwiftStdlib 5.5, *)
1818
@main struct Main {
1919
static func main() async {
20-
let handle = detach {
20+
let task = Task.detached {
2121
while (!Task.isCancelled) { // no need for await here, yay
2222
print("waiting")
2323
}
2424

25-
print("done")
25+
print("inside: Task.isCancelled = \(Task.isCancelled)")
2626
}
2727

28-
handle.cancel()
28+
task.cancel()
2929

30-
// CHECK: done
31-
await handle.get()
30+
await task.value
31+
print("outside: task.isCancelled = \(task.isCancelled)")
32+
print("outside: Task.isCancelled = \(Task.isCancelled)")
33+
34+
// CHECK-DAG: inside: Task.isCancelled = true
35+
// CHECK-DAG: outside: task.isCancelled = true
36+
// CHECK-DAG: outside: Task.isCancelled = false
3237
}
3338
}

0 commit comments

Comments
 (0)