Mark @ResourceWrapper-generated extensions and Definition types nonisolated - #22
Draft
NicoMulet wants to merge 1 commit into
Draft
Mark @ResourceWrapper-generated extensions and Definition types nonisolated#22NicoMulet wants to merge 1 commit into
NicoMulet wants to merge 1 commit into
Conversation
…olated
Under Swift 6.2's default MainActor isolation ("Approachable Concurrency",
the default for new Xcode 26 projects), macro-generated extensions and
nested types inherit @mainactor isolation unless marked otherwise. This
made the generated `Definition`/`BodyDefinition` conformance to
`ResourceDefinition` main-actor isolated, which is incompatible with the
non-isolated `ResourceDefinitionProviding` protocol and fails to compile
with "conformance ... crosses into main actor-isolated code".
Mark the macro's generated extensions and the Definition/BodyDefinition
struct declarations `nonisolated` so the generated code no longer depends
on the consuming module's default-isolation setting. Attributes/
Relationships structs are left untouched since their mutable stored
properties can't be marked nonisolated.
Fixes #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19
TL;DR
Mark
@ResourceWrapper's generated extensions andDefinition/BodyDefinitiontypesnonisolatedso the macro output no longer depends on the consuming module's default actor-isolation setting.Context
Xcode 26's "Approachable Concurrency" makes
@MainActorthe default isolation for any declaration that doesn't opt out explicitly.@ResourceWrappergenerates severalextension Person: ...conformances and a nestedDefinitionstruct without marking themnonisolated, so under that default they inherit@MainActorisolation. SinceResourceDefinition/ResourceDefinitionProvidingare ordinary nonisolated protocols, this produces:Reported in #19, where the reporter found that adding
nonisolatedto their own model works around it. Resource models are plain data-transfer types encoded/decoded across concurrency domains, so they shouldn't be actor-isolated regardless of what isolation default the consuming module picked — the fix belongs in the macro.Summary of Changes
@ResourceWrappernow emitsnonisolatedon all 5 generated extensions (ResourceDefinitionProviding,ResourceIdentifiable,ResourceLinkageProviding,Codable, and the body-factory extension).DefinitionandBodyDefinitionstruct declarations are also markednonisolated, since nested type declarations are independent isolation-inference roots and don't inherit isolation from their enclosing (now-nonisolated) extension.Attributes/Relationshipsare intentionally left unmarked: they hold mutablevarstored properties, andnonisolatedon a mutable stored property is a hard error in the Swift 6 language mode. They don't need it anyway — the compiler error was specifically aboutDefinition's conformance, not these nested value types.ResourceWrapperMacroTestsexpansion snapshots to match.How to Test
Verified against the reporter's exact repro (
Personwithid/firstName/lastName/twitter) usingswift build -Xswiftc -swift-version -Xswiftc 6 -Xswiftc -default-isolation -Xswiftc MainActoron a client target depending on this branch:Also ran the full existing test suite (
swift test), all green with no new warnings.Demo