With -default-isolation MainActor, the SE-0470 rule that an isolated conformance can only be used in its own isolation domain is enforced for decode(User.self, ...) and not enforced for decode([User].self, ...). The same happens with several standard library algorithms.
// swiftc -swift-version 6 -default-isolation MainActor
import Foundation
struct User: Codable { var name: String }
struct Point: Comparable {
var x = 0
static func < (a: Point, b: Point) -> Bool { a.x < b.x }
}
@concurrent func one(_ d: Data) async throws -> User {
try JSONDecoder().decode(User.self, from: d)
}
@concurrent func many(_ d: Data) async throws -> [User] {
try JSONDecoder().decode([User].self, from: d)
}
@concurrent func sort(_ ps: [Point]) async -> [Point] {
ps.sorted()
}
@concurrent func find(_ ps: [Point], _ p: Point) async -> Bool {
ps.contains(p)
}
| Function | Swift 6.4.2 (Xcode 27.2) | main snapshot 2026-11-01 |
|---|---|---|
one: decode(User.self, ...) |
error | error |
many: decode([User].self, ...) |
accepted | accepted |
sort: ps.sorted() |
accepted | accepted |
find: ps.contains(p) |
accepted | accepted |
On 6.4.2 I also see no diagnostic for decoding [String: User] and User?, encoding [User], min(), max(), firstIndex(of:), == on [Tag]?, and Set built from [[Tag]].
Runtime effect. A model whose init(from:) writes to a main actor-isolated static dictionary, decoded as [User] from eight tasks in a @concurrent function, compiles with no diagnostics under -swift-version 6 -strict-memory-safety -warnings-as-errors. It crashed on every run I made on 6.4.2 and on the snapshot, and ThreadSanitizer on 6.4.2 reports a Swift access race in User.init(from:). The full program is in the PR comment linked below.
I wrote up the full program, the Swift 5 mode result and a workaround (nonisolated on the model) here:
Where the check stops. From reading the source, MismatchedIsolatedConformances::operator() in lib/Sema/TypeCheckConcurrency.cpp returns true for a conformance that is acceptable, and forEachConformance is documented to stop the traversal when its callback returns true. That matches what I see: the result depends on order. With func call<T: P, U: P>(_ t: T, _ u: U), an isolated conformance Iso: @MainActor P and a plain Plain: P, call(Iso(), Plain()) is an error in a nonisolated function and call(Plain(), Iso()) compiles.
Existing work. [Sema] Check all generic substitutions for isolated conformances by Dev10-sys · Pull Request #92043 · swiftlang/swift · GitHub changes that return value. It was opened on 7 September for issue 92004 in the same repository and has no reviews yet. Its tests cover functions with two generic parameters. I applied its diff on top of main at 248b7ce6 and built it: all four functions above are rejected, and so is a compile-only reduction of the code from Isolated conformances combined with conditional extensions can cross isolation boundaries without an `await` · Issue #87993 · swiftlang/swift · GitHub. The details are in [Sema] Check all generic substitutions for isolated conformances by Dev10-sys · Pull Request #92043 · swiftlang/swift · GitHub. I did not run the compiler test suite.
A second path that #92043 does not cover. With the same diff applied, a value returned from a generic call that used an isolated conformance can still be sent to another isolation domain, where the isolated witness then runs off its actor. AnyHashable(tag) created on the main actor and hashed inside Task.detached compiles with no diagnostics and traps at run time. The equivalent code with any P is rejected. Reproductions are in SE-0470 Rule 3 is not enforced for values returned from generic calls, including AnyHashable · Issue #94268 · swiftlang/swift · GitHub .
Is #92043 the intended fix for the first case, or is a different approach planned?