Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ee9ebb7
Replace DispatchQueue-backed locks with Mutex
claude Nov 13, 2026
83b0b2d
Cancel tasks that are still being enqueued when cancelTasks() is called
claude Nov 14, 2026
e07cf88
Run ActorQueue operations in the task returned to the caller
claude Nov 13, 2026
601ea69
Run FIFOQueue operations in the task returned to the caller
claude Nov 13, 2026
02bd142
Document task-local, priority, and cancellation behavior
claude Nov 13, 2026
23a5e48
Escalate the task holding the current turn on behalf of waiting tasks
claude Nov 14, 2026
854ba0f
Test escalating a task while it waits for its turn
claude Nov 14, 2026
af76f0e
Escalate the task holding the turn outside the escalation handler
claude Nov 16, 2026
2c1f90f
Keep the deadlock tests off the cooperative pool while the status loc…
claude Nov 16, 2026
8047e87
Add isIdle to ActorQueue and FIFOQueue
claude Nov 15, 2026
1bf79f4
Add a minimum priority to ActorQueue
claude Nov 15, 2026
faea01c
Run Thread Sanitizer on macOS
claude Nov 16, 2026
65a03c1
Test on the iOS 18 simulator
claude Nov 16, 2026
30cd22c
Run each test once and require deterministic tests
claude Nov 16, 2026
f1e21f6
Run the manual executors' jobs without a dispatch queue
claude Nov 16, 2026
6bf50d5
Upload test results and crash reports when a test job fails
claude Nov 16, 2026
a38d43c
Tighten the README
claude Nov 16, 2026
7e5269a
Rename ActorQueue.isIdle to hasStartedAllWork
dfed Nov 16, 2026
04a38b7
Start main-actor queue tasks on the main actor
dfed Nov 16, 2026
d87d8b9
Replace nondeterministic turn-ending tests with a coverage test
dfed Nov 16, 2026
8442ac5
Test that FIFO main-actor tasks end their turn on the main actor
dfed Nov 16, 2026
d14a799
Install Rosetta before CodeQL analyzes Swift
dfed Nov 16, 2026
343b1a2
Build without SwiftPM's sandbox under CodeQL
dfed Nov 16, 2026
35aefaa
Drop the Rosetta step, which the sandbox fix makes unnecessary
dfed Nov 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,89 @@ jobs:
with:
fail_ci_if_error: true
verbose: true
# A test process that crashes, such as one in a simulator, fails
# the job without saying why in the log. The test results and the
# crash reports that macOS writes for the process explain it.
- name: Upload Test Results and Crash Reports
if: failure()
uses: actions/upload-artifact@v7
with:
name: xcode-test-results-${{ matrix.platforms }}
path: |
.build/derivedData/*/Logs/Test/*.xcresult
~/Library/Logs/DiagnosticReports/*.ips
if-no-files-found: ignore
retention-days: 7
# Xcode 27 can't download the iOS 18 simulator runtime, but the
# `macos-15` image has it installed, so this job copies its disk image
# and passes it to `spm-minimum-ios` as an artifact.
minimum-ios-runtime:
name: Copy Minimum iOS Simulator
runs-on: macos-15
# Copying and uploading the 9 GB disk image takes a few minutes, so
# stop a stalled upload after 15 minutes rather than at GitHub's
# six-hour default.
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Checkout Repo
uses: actions/checkout@v7
- name: Copy the Simulator Runtime
run: Scripts/copy-ios-18-simulator.sh runtime
- name: Upload the Simulator Runtime
uses: actions/upload-artifact@v7
with:
name: ios-18-simulator-runtime
path: runtime
# Skip compressing the 9 GB disk image, which only slows the upload.
compression-level: 0
# Only `spm-minimum-ios` needs the image, minutes later.
retention-days: 1
spm-minimum-ios:
name: Build Xcode Minimum iOS
needs: minimum-ios-runtime
runs-on: xcode-27
# A test that deadlocks keeps the test run from ending, so stop the
# job after 50 minutes rather than at GitHub's six-hour default.
timeout-minutes: 50
permissions:
contents: read
steps:
- name: Checkout Repo
uses: actions/checkout@v7
- name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_27.2.app/Contents/Developer
- name: Download the Simulator Runtime
uses: actions/download-artifact@v8
with:
name: ios-18-simulator-runtime
path: runtime
- name: Install the Simulator Runtime
run: Scripts/install-ios-18-simulator.sh runtime/iphonesimulator_18.5_22F77.dmg
- name: Build and Test Framework
run: Scripts/build.swift iOS18
- name: Prepare Coverage Reports
run: ./Scripts/prepare-coverage-reports.sh
- name: Upload Coverage Reports
if: success()
uses: codecov/codecov-action@v7
with:
fail_ci_if_error: true
verbose: true
# A test process that crashes, such as one in a simulator, fails
# the job without saying why in the log. The test results and the
# crash reports that macOS writes for the process explain it.
- name: Upload Test Results and Crash Reports
if: failure()
uses: actions/upload-artifact@v7
with:
name: xcode-test-results-iOS18
path: |
.build/derivedData/*/Logs/Test/*.xcresult
~/Library/Logs/DiagnosticReports/*.ips
if-no-files-found: ignore
retention-days: 7
spm-swift:
name: Swift Build Xcode
runs-on: xcode-27
Expand All @@ -62,6 +145,45 @@ jobs:
run: sudo xcode-select --switch /Applications/Xcode_27.2.app/Contents/Developer
- name: Build and Test Framework
run: xcrun swift test -c release -Xswiftc -enable-testing
# A test process that crashes fails the job without saying why in
# the log. The crash report that macOS writes for it explains it.
- name: Upload Crash Reports
if: failure()
uses: actions/upload-artifact@v7
with:
name: swift-build-xcode-crash-reports
path: ~/Library/Logs/DiagnosticReports/*.ips
if-no-files-found: ignore
retention-days: 7
tsan:
name: "Thread Sanitizer on macOS"
runs-on: xcode-27
# A test that deadlocks keeps the test run from ending, so stop the
# job after 15 minutes rather than at GitHub's six-hour default.
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Checkout Repo
uses: actions/checkout@v7
- name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_27.2.app/Contents/Developer
- name: Build With Thread Sanitizer
run: xcrun swift build --build-tests --sanitize=thread
# When Thread Sanitizer reports a data race, the test process exits
# with an error, which fails this step.
- name: Test With Thread Sanitizer
run: xcrun swift test --skip-build --sanitize=thread
# A test process that crashes fails the job without saying why in
# the log. The crash report that macOS writes for it explains it.
- name: Upload Crash Reports
if: failure()
uses: actions/upload-artifact@v7
with:
name: thread-sanitizer-crash-reports
path: ~/Library/Logs/DiagnosticReports/*.ips
if-no-files-found: ignore
retention-days: 7
linux:
name: "Build and Test on Linux"
runs-on: ubuntu-24.04
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ jobs:
export PATH="$TOOLCHAIN:$DEVELOPER_DIR/usr/bin:$PATH"
SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export SDKROOT
arch -arm64 "$TOOLCHAIN/swift" build --target AsyncQueue
# Under the CodeQL tracer, SwiftPM's sandbox-exec cannot launch the compiled manifest
# ("Bad CPU type in executable"), so build without SwiftPM's sandbox.
arch -arm64 "$TOOLCHAIN/swift" build --target AsyncQueue --disable-sandbox

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
Expand Down
46 changes: 46 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# swift-async-queue

## Tests

All tests must be deterministic. A test gives the same result on every
run of the same code: on correct code it passes every run, and on the
regression it guards it fails every run, or hangs, in which case CI's
job timeout is the failure.

- Force the interleaving a test needs with semaphores, manual
executors, and test hooks.
- Never rely on sleeps, wall-clock timeouts, polling, or repetition.
- CI runs each test once.

A few older tests loop in the hope of catching a bad interleaving: the
`sendsEventsInOrder` tests, the `executesAsyncBlocksAtomically` tests,
and `task_isNotReentrant` and `throwingTask_isNotReentrant`. They stay
as backstops because no deterministic test catches what they catch yet.
Delete a probabilistic test only once a deterministic test fails 10 of
10 runs for every bug it catches.

## Coverage

Code coverage must stay at 100%, the target in `codecov.yml`.

## Concurrency

Never cancel, resume, or escalate a task while holding a lock. That
includes the runtime's own lock on a task, which it holds while it runs
the task's cancellation and priority escalation handlers: do that work
after the lock is released, or from a new task.

## Performance

Prefer the faster code over the shorter code on the path that enqueues
a task.

## Style

`guard` is fine, but don't return early from an `if` without an `else`.

## Documentation

Write the README and documentation comments in the plain style of The
Swift Programming Language's chapter on concurrency. Use the terms it
uses, and don't invent new concepts.
Loading
Loading