Skip to content

feat(modifier): add _TaskModifier2 and _TaskValueModifier2 - #1268

Draft
cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:feat/task-modifier2
Draft

cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:feat/task-modifier2

Conversation

@cristim

@cristim cristim commented Nov 24, 2026

Copy link
Copy Markdown

Summary

Adds _TaskModifier2 and _TaskValueModifier2<Value>, the modifiers behind the task(name:executorPreference:priority:_:) family: like _TaskModifier/_TaskValueModifier plus a task name, a TaskExecutor preference and an @isolated(any) action. The task starts when the view appears, is cancelled when it disappears, and (value variant) is cancelled and restarted when the id changes. No public View.task(name:...) overload is added here; only the modifier types, which are underscored.

Why

Apps linked against SwiftUI import the init symbols of these two types, and OpenSwiftUI had none. The init labels, parameter types and mangled names follow the symbol names observed as imports (names only; no code, interface files or binaries were read). One detail matters for the ABI: the inits must be nonisolated. Inheriting ViewModifier's @preconcurrency @MainActor isolation makes swiftc 6.3.3 mangle the action parameter without YA (@isolated(any)), so the imported symbol would not be defined. _TaskValueModifier2.value is therefore nonisolated(unsafe) like action.

Provenance

Local commits c1164316 (feat), f51f218f, 83bfdd48, 86da0aed, 1bfe82ed and b7c3e9de (2026-10-09 and 2026-10-10, Cristian Magherusan-Stanciu), squashed into the final state. A maintainer may want to look at the provenance wording above; I did not use anything but names. Dropped: Scripts/check-taskmodifier2-symbols.sh (a manual llvm-nm check on a built Mach-O, not run in CI; the test comment now says "check with nm"). Kept: the source, Tests/OpenSwiftUITests/Modifier/TaskModifier2Tests.swift (parameter storage, ViewModifier conformance, the mangled names as comments) and Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/TaskModifier2LifecycleTests.swift (start on appear, cancel and restart on id change). 400 lines in total, all additions.

Testing

Not compiled and tests not run: no Swift toolchain is available on the machine where I prepared this port. For the original commits the author reported standalone probes with swiftc 6.3.3 (arm64-apple-macosx26.0, -swift-version 5, -enable-library-evolution) confirming that the two init names match exactly when the inits are nonisolated and drop YA otherwise; those probes were not part of this repo's build. Needs a full swift test run (OpenSwiftUITests and OpenSwiftUICompatibilityTests) before it is marked ready. The compatibility tests need a host that can show a window.

🤖 Generated with Claude Code

Add the task modifiers behind View.task(name:executorPreference:priority:_:)
and its id: variant. Unlike _TaskModifier they also carry a task name and a
TaskExecutor preference, and the action is @isolated(any). They start the task
when the view appears, cancel it when it disappears and, for the value
variant, cancel and restart it when the id changes.

The inits are nonisolated: inherited from ViewModifier's @preconcurrency
@mainactor isolation they would mangle the action parameter without YA
(@isolated(any)), so the symbols SwiftUI-linked apps import would not be
defined. The `n` in the mangled name comes from the sending action parameter.
Tests pin the init shape and the mangled names, and the compatibility tests
cover starting on appear and cancel and restart on an id change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant