Skip to content

[5.6] Hop to the generic executor in non-actor-isolated async functions #41055

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

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Jan 28, 2022

Async functions are now expected to set ExpectedExecutor in their prologue (and, generally, immediately hop to it). I updated the prologue code for a bunch of function emission, most of which was uninteresting. Top-level code was not returning to the main executor, which is now fixed; fortunately, we weren't assuming that we were on the main executor yet.

We had some code that only kicked in when an ExpectedExecutor wasn't set which made us capture the current executor before a hop and then return to it later. This code has been removed; there's no situation in which save-and-return is the semantically correct thing to do given the possibility of hop optimization. I suspect it could also have led to crashes if the current executor is being kept alive only because it's currently running code. If we ever add async functions that are supposed to inherit their caller's executor, we should have the caller pass the right executor down to it.

This is the first half of SE-0338; the second, sendability enforcement, is much more complicated, and Doug has volunteered to do it.

Fixes rdar://79284465, as well as some tests that were XFAILed on Windows.

This is the 5.6 version of #40910.

Explanation: fixes a widely-reported semantic problem with non-actor-isolated async functions
Scope: affects the emission of SIL for all non-actor-isolated async functions
Risk: moderate because of the scope; however, the resulting SIL closely resembles that used by actor-isolated async functions, so there shouldn't be huge surprises waiting here. Biggest risk is that there are uncommon paths for generating special async functions that are somehow untested in the test suite
Testing: common code path extensively tested by the test suite
Reviewer: @DougGregor (on main PR)

@rjmccall rjmccall requested a review from a team as a code owner January 28, 2022 06:14
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall rjmccall changed the title Hop to the generic executor in non-actor-isolated async functions. [5.6] Hop to the generic executor in non-actor-isolated async functions. Jan 28, 2022
@rjmccall rjmccall changed the title [5.6] Hop to the generic executor in non-actor-isolated async functions. [5.6] Hop to the generic executor in non-actor-isolated async functions Jan 28, 2022
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 35e5b52632d7cb9ab7a4e0a25ab258e95f89720c

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 35e5b52632d7cb9ab7a4e0a25ab258e95f89720c

Async functions are now expected to set ExpectedExecutor in their
prologue (and, generally, immediately hop to it).  I updated the
prologue code for a bunch of function emission, most of which was
uninteresting.  Top-level code was not returning to the main
executor, which is now fixed; fortunately, we weren't assuming
that we were on the main executor yet.

We had some code that only kicked in when an ExpectedExecutor
wasn't set which made us capture the current executor before
a hop and then return to it later.  This code has been removed;
there's no situation in which save-and-return is the semantically
correct thing to do given the possibility of hop optimization.
I suspect it could also have led to crashes if the current
executor is being kept alive only because it's currently running
code.  If we ever add async functions that are supposed to inherit
their caller's executor, we should have the caller pass the right
executor down to it.

This is the first half of SE-0338; the second, sendability
enforcement, is much more complicated, and Doug has volunteered
to do it.

Fixes rdar://79284465, as well as some tests that were XFAILed
on Windows.
@rjmccall rjmccall force-pushed the hop-to-generic-executor-5.6 branch from 35e5b52 to 0106bde Compare January 28, 2022 08:03
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 0106bde

@rjmccall
Copy link
Contributor Author

Please test with pull request:
swiftlang/llvm-project#3858

@swift-ci Please test macOS

@rjmccall rjmccall merged commit 97f8ef6 into swiftlang:release/5.6 Jan 29, 2022
@rjmccall rjmccall deleted the hop-to-generic-executor-5.6 branch January 29, 2022 04:48
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.

4 participants