Skip to content
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

[Concurrency] Perform Sendable checking on parameter and result types for async function conversions that change actor isolation. #72691

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 29, 2024

Such conversions are unsafe because they allow sneaking non-Sendable types across isolation boundaries:

class NotSendable {}

func testUnsafeAsyncFunctionConversions(
  f: @escaping @MainActor (NotSendable) async -> Void,
  ns: NotSendable
) {
  let newF: (NotSendable) async -> Void = f
  await newF(ns) // non-Sendable state escapes to the main actor here!
}

This change isn't ready yet (just putting the PR up so I don't forget about it!) because it doesn't handle function conversions in the other direction - nonisolated functions converted to global actor isolated functions. However, the constraint system currently injects function conversions from nonisolated functions to global actor isolated functions for all calls to global actor isolated functions due to the way adjustFunctionTypeForConcurrency is called. I believe we need to split that function up into two steps - one that adds global actor isolation, and a separate one that strips annotations for @preconcurrenty. The first function type should be used as the original type and the stripped function type should be used as the adjusted type, eliminating the function conversion except in the cases where it's needed for @preconcurrency. Then, this code in the actor isolation checker can be applied to function conversations that add global actor isolation.

for async function conversions that change actor isolation.
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.

None yet

1 participant