Skip to content

Commit

Permalink
Add a test that ensures tasks get invalidated
Browse files Browse the repository at this point in the history
This detects a bug unique to the oldest back-deployment targets
for Swift concurrency, where Tasks were getting created with an
incorrect bit pattern that made them immortal.

Verifies that rdar://93087343 has been fixed.
  • Loading branch information
DougGregor committed Jun 6, 2022
1 parent 06061a6 commit 3c6f6f2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/Concurrency/Runtime/task_destruction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -disable-availability-checking) | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: concurrency_runtime

// UNSUPPORTED: back_deployment_runtime

class C {}

@_silgen_name("exit")
func exit(_ code : UInt32) -> Never

@main
enum Main {
static func main() async {
weak var weakRef: C?
do {
let c = C()
let t = Task.detached { return c }
weakRef = c
}
Task.detached {
try await Task.sleep(nanoseconds: 10_000_000_000)
print("Fail!")
exit(1)
}

while weakRef != nil {
await Task.yield()
}
// CHECK: Success
print("Success!")
}
}

0 comments on commit 3c6f6f2

Please sign in to comment.