Skip to content

Add AST representation for coroutines#85372

Open
asl wants to merge 8 commits intomainfrom
coro-ast-no-diff
Open

Add AST representation for coroutines#85372
asl wants to merge 8 commits intomainfrom
coro-ast-no-diff

Conversation

@asl
Copy link
Copy Markdown
Contributor

@asl asl commented Nov 6, 2025

This is a proof-of-concept PR adding AST representation for coroutines

Further background at https://forums.swift.org/t/pitch-yield-once-functions-first-class-coroutines/77081

@asl
Copy link
Copy Markdown
Contributor Author

asl commented Nov 6, 2025

@tkremenek @rjmccall Following discussions on LLVM Dev Meeting, this is a stripped-down version of #78508:

  • No autodiff-related parts
  • No silgen (besides the "standard" special path used for coroutine accessors)
  • Some other fixes for SIL optimizer is omitted

Essentially the PR contains AST-related bits for coroutine declarations and coroutine function types as well as required boilerplate for AST mangling, dumping, serialization, etc.

@xedin comments from the original PR were addressed as well.

@asl
Copy link
Copy Markdown
Contributor Author

asl commented Nov 6, 2025

Please test with following pull request: swiftlang/llvm-project#11396
@swift-ci please test

@asl asl force-pushed the coro-ast-no-diff branch from 8805213 to 29ab221 Compare November 13, 2025 07:01
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Nov 13, 2025

Please test with following pull request: swiftlang/llvm-project#11396
@swift-ci please test

@asl asl force-pushed the coro-ast-no-diff branch from 29ab221 to 28dadc4 Compare November 13, 2025 20:34
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Nov 13, 2025

Please test with following pull request: swiftlang/llvm-project#11396
@swift-ci please test

@asl
Copy link
Copy Markdown
Contributor Author

asl commented Nov 14, 2025

Please test with following pull request: swiftlang/llvm-project#11396
@swift-ci please test windows platform

@asl asl closed this Feb 20, 2026
@asl asl reopened this Feb 20, 2026
@asl asl requested a review from hnrklssn as a code owner February 20, 2026 18:55
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Feb 20, 2026

@asl
Copy link
Copy Markdown
Contributor Author

asl commented Feb 26, 2026

@rjmccall ping

@asl asl force-pushed the coro-ast-no-diff branch from 1d89ed5 to 71559c2 Compare March 9, 2026 22:53
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Mar 9, 2026

@asl
Copy link
Copy Markdown
Contributor Author

asl commented Mar 9, 2026

@rjmccall Ping. Will you please check it out?

Copy link
Copy Markdown
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.

Sorry for letting this slip. I'm confused about the structure of yields that we're modeling here, because we seem to allow a list of (ownership, type) pairs in some places but only a single type in others.

Comment thread include/swift/AST/ASTBridging.h Outdated
Comment thread include/swift/AST/Decl.h Outdated
Comment thread include/swift/AST/Decl.h Outdated
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Mar 10, 2026

Sorry for letting this slip. I'm confused about the structure of yields that we're modeling here, because we seem to allow a list of (ownership, type) pairs in some places but only a single type in others.

This is a good question :) And I'd suppose this is the similar to what @slavapestov asked about thrown error types: should we allow multiple thrown error types? Or tuple with types, etc.

At SIL level we can have multiple yields each could be direct and indirect. AnyFunctionType::Yield is pre-existing (though it was essentially unused) and from that I deduced that you wanted to support multiple yields when you added it.

Currently declarations only support a single yield type (similar to thrown error type) and it could only be optionally inout, but function types potentially support multiple yields with all possible value ownerships, however, I put couple of asserts to ensure we only proceed with the single yield type.

I can potentially support multiple yield types on declarations and all different value ownership, if you think it would make sense.

@rjmccall
Copy link
Copy Markdown
Contributor

Error types are different — listing multiple error types is really just saying that the error could be any of the given types. With yields, yeah, I think it's more like a parameter list in the sense that it makes sense to be able to yield multiple independent values at once. Even if accessors don't need it, I think it's consistent to just go ahead and use a type that allows that to be modeled directly. Plus that way you can just have a YieldList type that includes the keyword location instead of passing that around separately.

The grammar you're using already delimits the yields, like yields(Int), right? So there's no ambiguity between a tuple and a list of separate yields.

@asl
Copy link
Copy Markdown
Contributor Author

asl commented Mar 11, 2026

The grammar you're using already delimits the yields, like yields(Int), right? So there's no ambiguity between a tuple and a list of separate yields.

Right, there is no ambiguity here. Looks like then we will need to extend yield here as well, so it will be able to yield multiple values. Looks like again closing gap between source language and SIL as SIL yield could yield multiple values.

I will extend the declarations then, looks straightforward.

@asl asl force-pushed the coro-ast-no-diff branch from 71559c2 to 0a71407 Compare April 21, 2026 22:01
@asl asl requested a review from a team as a code owner April 21, 2026 22:01
@asl asl force-pushed the coro-ast-no-diff branch from 0a71407 to 2fcddf1 Compare April 21, 2026 23:18
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Apr 22, 2026

@asl asl requested a review from rjmccall April 22, 2026 18:28
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Apr 22, 2026

@rjmccall This new version allows for multiple yields on declarations as well. Will you please take a look?

@asl asl closed this Apr 22, 2026
@asl asl reopened this Apr 22, 2026
@asl
Copy link
Copy Markdown
Contributor Author

asl commented Apr 22, 2026

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.

3 participants