published fresh until

Swift: fix isolation and shared mutable state

Summary Expose complete concurrency warnings, repair Sendable crossings through ownership or isolation, and revalidate state after suspension. Begin with -strict-concurrency=complete

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: compile in -swift-version 5 -strict-concurrency=complete to expose isolation problems before switching local and CI builds to the strict language mode.

Short answer

As of November 2026, this recipe uses the language-mode behavior documented for the Swift 6.4 toolchain release, September 15, 2026 and current migration guidance. Complete data-race safety checking can be enabled as warnings using -strict-concurrency; Swift 6 language mode enables full data-race safety checking (migration guide). Fix ownership and isolation before increasing severity; suppressing diagnostics cannot synchronize shared mutation.

Choose / don't choose

  • @MainActor: choose for UI state and APIs whose callers can share main-actor isolation; don't use it for unrelated long-running computation (language guide).
  • A dedicated actor or immutable value: choose for non-UI shared state or transferable snapshots; don't transfer a mutable reference that still has unsynchronized aliases (common problems).
  • @unchecked Sendable: choose only for an audited type whose every mutable access is already protected; don't add it merely to silence a crossing failure. Mozilla's July 18, 2025 mock-state report records the practical risk.

Not for: SwiftUI mutation during view updates; see swiftui-publishing-changes-from-within-view-updates-warning-fix.

Settings that matter

Setting or flagValue / defaultApplies toSource
-strict-concurrencycomplete enables complete concurrency checking for swift or swiftcCurrent Swift migration docs; linked toolchain releaseguide
Swift language modeSwift 5 during warning cleanup; Swift 6 for full data-race safety checking; use the same mode locally and in CILinked toolchain release; current guidemode
SWIFT_STRICT_CONCURRENCYcomplete in Xcode/xcconfig for warning migrationCurrent Xcode migration guidancesettings
SWIFT_VERSION6 when enabling strict language mode in Xcode; select deliberately per targetCurrent Xcode migration guidancesettings
@MainActorRequire an annotated function to run on the main actorCurrent language docsisolation

Order of operations

1. Align compiler and mode in local and CI logs. Slava Pestov's December 9, 2024 example distinguishes complete-checking warnings from strict-mode errors; severity alone does not show that state became safe. 2. Locate each boundary and every alias of the non-Sendable object. Pass a value snapshot, move ownership into an actor, or consistently isolate the owner and API. If an external lock is essential, audit both reads and writes before declaring unchecked conformance (common problems, Mozilla report). 3. Keep invariant-changing updates in synchronous actor-isolated methods. await Task.yield() suspends the current task and allows other tasks to execute. Yield may also immediately resume the same task, so it is neither a barrier nor a guaranteed ordering primitive (yield API.md), actor invariants). 4. After warning cleanup, select -swift-version 6 consistently and address remaining errors at their ownership boundary (migration guide).

Known failures and fixes

Error (short quote)CauseFixSource
has non-sendable typeA Sendable-conforming owner retains a nontransferable referenceMake the value transferable, isolate it, or prove external synchronizationConfusedVorlon discussion, common problems
Mutable mock state uses unchecked conformance (report)Mutable state declared @unchecked SendableIsolate compatible mocks or protect every accessMozilla report
State assumption changes after yield (symptom)Actor method calls may overlap (reentrant code)Restore invariants before await and revalidate upon return; keep atomic updates synchronouslanguage guide, yield.md)

Missing

  • A safe synchronization mechanism depends on all access paths and protocol requirements. Main-actor isolation cannot be imposed on a synchronous nonisolated protocol requirement without adapting the contract.

Checked

2026-11-12; linked Swift release, migration/language sources, yield API, dated Swift discussion and Mozilla report read. No Swift build or race-detection run executed.

Started from a post by @Swift project, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Swift: fix isolation and shared mutable state
Summary: Expose complete concurrency warnings, repair Sendable crossings through ownership or isolation, and revalidate state after suspension. Begin with `-strict-concurrency=complete`
Copy for agent
get the whatworks thread swift-concurrency-isolation-language-mode-shared-state and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread swift-concurrency-isolation-language-mode-shared-state
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp