Skip to content

[Concurrency] Add async to the Swift type system. #33147

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 7 commits into from
Jul 29, 2020

Conversation

DougGregor
Copy link
Member

Add async to the type system. async can be written as part of a
function type or function declaration, following the parameter list, e.g.,

func doSomeWork() async { ... }

async functions are distinct from non-async functions and there
are no conversions amongst them. At present, async functions do not
do anything, but this commit fully supports them as a distinct kind
of function throughout:

  • Parsing of async
  • AST representation of async in declarations and types
  • Syntactic type representation of async
  • (De-/re-)mangling of function types involving 'async'
  • Runtime type representation and reconstruction of function types
    involving async.
  • Dynamic casting restrictions for async function types
  • (De-)serialization of async function types
  • Disabling overriding, witness matching, and conversions with
    differing async

Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Mostly looks great, thanks!

@theblixguy
Copy link
Collaborator

theblixguy commented Jul 28, 2020

I don’t think this PR is an appropriate place to discuss syntax changes. Please move the discussion to the Swift forums. The most recent thread around async is here.

Use the more general name `-enable-experimental-concurrency` instead,
since async is one part of the model.
@swiftlang swiftlang deleted a comment from SAGESSE-CN Jul 28, 2020
@swiftlang swiftlang deleted a comment from p16r Jul 28, 2020
@swiftlang swiftlang deleted a comment from minuscorp Jul 28, 2020
@swiftlang swiftlang deleted a comment from kylebrowning Jul 28, 2020
@swiftlang swiftlang deleted a comment from juliand665 Jul 28, 2020
@swiftlang swiftlang deleted a comment from lattner Jul 28, 2020
@DougGregor
Copy link
Member Author

Editorial note: I've deleted all of the comments bike-shedding syntax. Those belong on the forums, in a pitch thread about concurrency designs, not on a pull request for the implementation.

@swiftlang swiftlang deleted a comment from ScottRobbins Jul 28, 2020
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

swiftlang/swift-syntax#230

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

swiftlang/swift-syntax#230

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#230

@swift-ci smoke test

@DougGregor
Copy link
Member Author

DougGregor commented Jul 29, 2020

SwiftSyntax part of this over at swiftlang/swift-syntax#231

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#231

@swift-ci please smoke test

@DougGregor DougGregor merged commit 4181722 into swiftlang:master Jul 29, 2020
@DougGregor DougGregor deleted the async-function-types branch July 29, 2020 15:59
"'throws' may only occur before '->'", ())
ERROR(rethrows_in_wrong_position,none,
"'rethrows' may only occur before '->'", ())
ERROR(async_or_throws_in_wrong_position,none,
Copy link
Contributor

@davezarzycki davezarzycki Jul 30, 2020

Choose a reason for hiding this comment

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

Hi @DougGregor – Congrats on this first wave of changes. A small nit here. It would be nice if the diagnostic selector aligned with the diagnostic name. Right now it's backwards. Specifically, the diag is named "async…" and then "…or_throws" but the first selector is "throws". The fix would be:

ERROR(async_or_throws_in_wrong_position,none,
      "%select{'async'|'throws'|'rethrows'}0 may only occur before '->'",
       (unsigned))

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.

6 participants