Default Actor Isolation and foundational protocols

I've been testing my open source libraries with Swift 6.2 and the new Default Actor Isolation concurrency build setting set to MainActor (with Complete strict concurrency turned on). My library Destinations uses protocols extensively, often applying conformance to foundational Swift protocols like Hashable and Identifiable. Many of these basic protocols are not flagged as running on the @MainActor in Beta 1, leading to situations like this:

Given this example code:

public protocol Contentable: Identifiable {
var id: UUID { get }
}
final class ContentModel: Contentable {
let id: UUID = UUID()
}

I get the warning:

Multiline Conformance of 'ContentModel' to protocol 'Contentable' crosses into main actor-isolated code and can cause data races; this is an error in the Swift 6 language mode

The fix it suggests is to put a @MainActor before the Contentable protocol declaration in ContentModel, which seems to be a new attribute configuration in Swift 6.2. This solves the warning, but would create a lot of extra noise across the codebase.

Was it an oversight or a temporary omission that protocols like Hashable and Identifiable do not run on @MainActor by default, or is there some other reason they are excluded? Considering how often protocols in our code may conform to foundational protocols like this, it seems at odds to the MainActor mode of the Default Actor Isolation setting given that it was created to make concurrency easier and less boilerplate to implement.

Answered by DTS Engineer in 844183022

I’m gonna recommend that you ask this question over in Swift Forums > Using Swift, because I think you’ll get a better answer over there.

ps I’m usually happy to answer Swift concurrency questions here, but in this case your question is:

  • About built-in Swift stuff, like Hashable, so fair game for Swift Forums, and

  • Tied to a cutting edge language change in a beta release, so something better addressed by the folks who are actually working on the compiler.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

I’m gonna recommend that you ask this question over in Swift Forums > Using Swift, because I think you’ll get a better answer over there.

ps I’m usually happy to answer Swift concurrency questions here, but in this case your question is:

  • About built-in Swift stuff, like Hashable, so fair game for Swift Forums, and

  • Tied to a cutting edge language change in a beta release, so something better addressed by the folks who are actually working on the compiler.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Ah thanks Quinn, apologies! And thanks for the heads-up!

Default Actor Isolation and foundational protocols
 
 
Q