Skip to content

[Concurrency] Don't attempt to hop to executor inside default argument generators and stored property initializers. #72332

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 1 commit into from
Mar 15, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 14, 2024

Otherwise, the compiler will fail an assertion or crash in IRGen because there's a suspension point in a synchronous function. For example:

@MainActor func onMain() -> Int { 0 }

@MainActor func useDefault(_ x: Int = onMain()) -> Int { x }

@MainActor func anotherDefault(_ x: Int = useDefault()) -> Int { x }

The actor isolation checker ensures that the isolation of default arguments matches the isolation of the callee, so this code is valid. However, default argument generators and stored property initializers don't formally model their isolation in these cases, so the compiler attempts to emit a hop in the middle of a synchronous function when the default argument itself makes a call that uses an isolated default argument value. For now, don't emit the hop if the function is synchronous. A better approach would be to formally model the isolation for these function declarations that are generated in SIL.

Resolves: rdar://124502334

@hborla hborla requested a review from ktoso as a code owner March 14, 2024 16:51
@hborla
Copy link
Member Author

hborla commented Mar 14, 2024

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Mar 14, 2024

@swift-ci please test Windows

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