Skip to content

[test] silgen test coverage for async thunks of non-async funcs #62984

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
Jan 12, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented Jan 12, 2023

In light of SE-338, you'd think all functions converted to be async would have hops in their reabstraction thunks.

But that's not the case. A non-async function that is not otherwise isolated according to its type, when converted to become an async function, should not have hops in its reabstraction thunk; not even to the generic executor.

That was not intuitive for me, so I thought I'd add extra test coverage to ensure we maintain that existing behavior, since we rely on it when non-async functions have their isolation casted away when in an isolated context (only allowed when it's not also Sendable). Thus, when it's called later on, it needs to inherit the executor, as its guaranteed to only be called while on a matching one. For example:

@MainActor func caller() async {
  let f: () -> () = mainActorFn
  let g: () async -> () = f
  await g()  // g cannot be hopping to a different executor, it must inherit!
}

In light of SE-338, you'd think all functions converted to
be `async` would have hops in their reabstraction thunks.

But that's not the case. A non-async function that is not
otherwise isolated according to its type, when converted
to become an async function, should not have hops in its
reabstraction thunk; not even to the generic executor.

That was not intuitive for me, so I thought I'd add
extra test coverage to ensure we maintain that existing
behavior, since we rely on it when non-async functions
have their isolation casted away when in an isolated
context (only allowed when it's not also Sendable).
Thus, when it's called later on, it needs to inherit the
executor, as its guaranteed to only be called while on
a matching one. For example:

```
@mainactor func caller() async {
  let f: () -> () = mainActorFn
  let g: () async -> () = f
  await g()  // g cannot be hopping to a different executor, it must inherit!
}
```
@kavon
Copy link
Member Author

kavon commented Jan 12, 2023

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 3d1add2 into swiftlang:main Jan 12, 2023
@kavon kavon deleted the testcoverage-async-thunks branch January 17, 2023 19:42
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