xwu
(Xiaodi Wu)
July 9, 2025, 2:32am
2
Looks like the link that Steve provided currently points to the proposed amendments to SE-0470. Here's the corrected link to the SE-0466 amendment under review here:
main ← DougGregor:se-0466-disable-inference-from-conformances
opened 08:11PM - 30 Jun 25 UTC
Libraries need a way to communicate that certain protocols can't reasonably be u… sed with global-actor-isolated types. When the primary definition of a type conforms to such a protocol, it will disable `@MainActor` inference for that type. This has the effect of keeping more types `nonisolated` when there's signal that they should not be on the main actor. There are some protocols like this in the standard library (e.g., CodingKey, which was hardcoded to be nonisolated in the synthesis code), where the following code is ill-formed in with main-actor isolation by default:
struct S: Codable {
var a: Int
// error: CodingKeys inferred to `@MainActor`, which makes the conformance
// to CodingKey main-actor-isolated and then fails (because the requirements
// need to be nonisolated).
enum CodingKeys: CodingKey {
case a
}
}
With this amendment, the conformance to `CodingKey` (which inherits from `Sendable`), prevents `CodingKeys` from being inferred to be`@MainActor`.
Those of you who've liked the OP might want to take another gander at the corrected link and/or comment over on the review thread for amending SE-0470 once it is up
2 Likes