Skip to content

[Concurrency][startSynchronously] Improve in order synchronous enqueue of startSynchronously #80821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Apr 15, 2025

Previously there was still a sneaky hop which caused ordering issues. This introduced a specific test startSynchronously_order which checks that the task enqueues indeed are "immediate" and cleans up how we handle this.

This also prepares for the being discussed in SE review direction of this API that it SHOULD be ALLOWED to actually hop and NOT be synchronous at all IF the isolation is specified on the closure and is DIFFERENT than the callers dynamic isolation.

This effectively implements "synchronously run right now if dynamically on the exact isolation as requested by the closure; otherwise enqueue the task as usual".

resolves rdar://149284186
cc @drexin

Previously there was still a sneaky hop which caused ordering issues.
This introduced a specific test startSynchronously_order which checks
that the task enqueues indeed are "immediate" and cleans up how we
handle this.

This also prepares for the being discussed in SE review direction of
this API that it SHOULD be ALLOWED to actually hop and NOT be
synchronous at all IF the isolation is specified on the closure and is
DIFFERENT than the callers dynamic isolation.

This effectively implements "synchronously run right now if dynamically
on the exact isolation as requested by the closure; otherwise enqueue
the task as usual".

resolves rdar://149284186
cc @drexin
@ktoso ktoso requested review from rjmccall, a team and compnerd as code owners April 15, 2025 11:03
@ktoso
Copy link
Contributor Author

ktoso commented Apr 15, 2025

@swift-ci please smoke test

@ktoso ktoso requested review from drexin and al45tair April 15, 2025 11:30
@@ -59,14 +59,30 @@ extension Task where Failure == ${FAILURE_TYPE} {
public static func startSynchronously(
name: String? = nil,
priority: TaskPriority? = nil,
@_inheritActorContext @_implicitSelfCapture _ operation: __owned sending @escaping () async throws -> Success
% # NOTE: This closure cannot be 'sending' because we'll trigger ' pattern that the region based isolation checker does not understand how to check'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: figure out the exact signature we want here

@ktoso
Copy link
Contributor Author

ktoso commented Apr 15, 2025

@swift-ci please smoke test

Copy link
Contributor

@drexin drexin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ktoso ktoso changed the title [Concurrency] Improve in order synchronous enqueue of startSynchronously [Concurrency][startSynchronously] Improve in order synchronous enqueue of startSynchronously Apr 16, 2025
@ktoso ktoso merged commit 2dd6348 into swiftlang:main Apr 16, 2025
3 checks passed
@ktoso ktoso deleted the wip-refine-scheduling-of-task-start-synchronously branch April 16, 2025 11:24
xedin added a commit to xedin/swift that referenced this pull request May 28, 2025
swiftlang#80821 added `@isolated(any)`
which is an ABI breaking change but since we are not planning to keep
this API around, let's use `@_silgen_name` to bring the old name back
for now.

Resolves: rdar://152178221
xedin added a commit to xedin/swift that referenced this pull request May 28, 2025
swiftlang#80821 added `@isolated(any)`
which is an ABI breaking change but since we are not planning to keep
this API around, let's use `@_silgen_name` to bring the old name back
for now.

Resolves: rdar://152178221
ktoso pushed a commit to ktoso/swift that referenced this pull request May 28, 2025
swiftlang#80821 added `@isolated(any)`
which is an ABI breaking change but since we are not planning to keep
this API around, let's use `@_silgen_name` to bring the old name back
for now.

Resolves: rdar://152178221
ktoso pushed a commit to ktoso/swift that referenced this pull request May 28, 2025
swiftlang#80821 added `@isolated(any)`
which is an ABI breaking change but since we are not planning to keep
this API around, let's use `@_silgen_name` to bring the old name back
for now.

Resolves: rdar://152178221
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.

2 participants