Skip to content

[Concurrency] Add an API in the Concurrency library for extracting isolation from a dynamically isolated function value. #71906

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
merged 2 commits into from
Feb 27, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Feb 27, 2024

Extracting the isolation value from a function whose type is @isolated(any) needs a surface syntax. There's already a builtin, so for now I've exposed this with the following function in the Concurrency library, copied from the _Concurrency swiftinterface in my local build to demonstrate availability and compiler feature guards:

#if compiler(>=5.3) && $ParameterPacks && $IsolatedAny
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func extractIsolation<each Arg, Result>(_ fn: @escaping @isolated(any) (repeat each Arg) async throws -> Result) -> (any _Concurrency.Actor)?
#endif

Note that I needed to fix a few small issues in the mandatory SILOptimizer passes, as this change introduces the first use of Builtin.extractFunctionIsolation / FunctionExtractIsolationInst.

@hborla
Copy link
Member Author

hborla commented Feb 27, 2024

@swift-ci please smoke test

let _: (any Actor)? = extractIsolation(myActor.asyncActorFunction)
let _: (any Actor)? = extractIsolation(myActor.asyncThrowsActorFunction)
let _: (any Actor)? = extractIsolation(myActor.actorFunctionWithArgs(value:))
}
Copy link
Contributor

@ktoso ktoso Feb 27, 2024

Choose a reason for hiding this comment

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

Can we add a test with myActor being a distributed actor? Doug did the work for #isolated to convert, but would it work here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a test for this separately; it'll work as long as the type checker erasure to an @isolated(any) function type works when the function has an isolated distributed actor parameter. The type checker support was added in #71433, this PR just exposes a surface syntax for Builtin.extractFunctionIsolation

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, I'm just always nervous when we add such surface API that we might break it if not covered with DA tests. Thanks in advance, should be quick one to add :)

@hborla hborla force-pushed the extract-function-isolation branch from aa17eac to 59507ba Compare February 27, 2024 01:59
@hborla
Copy link
Member Author

hborla commented Feb 27, 2024

@swift-ci please smoke test

@hborla hborla merged commit 420859c into swiftlang:main Feb 27, 2024
@hborla hborla deleted the extract-function-isolation branch February 27, 2024 17:19
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