-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Add initial support for coroutines operators #4178
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
Conversation
62cbd25 to
65c8957
Compare
jbj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can add CFG and IR support in follow-up PRs.
|
|
||
| override string getOperator() { result = "co_yield" } | ||
|
|
||
| override int getPrecedence() { result = 2 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you find these precedence numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec doesn't explicitly give the precedence; it comes out of the grammar. You can also compare with https://en.cppreference.com/w/cpp/language/operator_precedence where we put e.g. AddressOfExpr and CoAwaitExpr in the same bucket, and Assignment and CoYieldExpr in the same bucket, although we number the buckets differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
intrigus-lgtm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Nice to have" But not terrible useful either.
|
|
||
| /** | ||
| * A C/C++ co_await expression | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, but I think that for consistency, if we're going to do this then we should do it for all QL examples at once, in a separate PR, rather than just doing it for these new ones here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can understand your thought, but at the same time doing that for all QL examples would be a huge amount of work.
I know that only doing this for new code leads to inconsistency, but if you never start you just have more work for when you also do the other examples.
Anyway, feel free to ignore my suggestions :)
|
|
||
| /** | ||
| * A C/C++ co_yield expression | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * A C/C++ 'co_return' statement. | ||
| * | ||
| * For example: | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * co_return 1+2; | ||
| * ``` | ||
| * or | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * Gets the operand of this 'co_return' statement. | ||
| * | ||
| * For example, for | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * co_return 1+2; | ||
| * ``` | ||
| * the operand is a function call `return_value(1+2)`, and for | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * co_return 1+2; | ||
| * ``` | ||
| * the result is `1+2`, and there is no result for | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * Gets the expression of this 'co_return' statement, if any. | ||
| * | ||
| * For example, for | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * Holds if this 'co_return' statement has an expression. | ||
| * | ||
| * For example, this holds for | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
| * co_return 1+2; | ||
| * ``` | ||
| * but not for | ||
| * ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * ``` | |
| * ```cpp |
6a4cb80 to
c3fb584
Compare
geoffw0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments are nitpicky, this LGTM.
It would be good at some point soon to have some complete test cases where coroutines are used, i.e. both implemented and called in a natural way. I think I know what this would look like but I haven't ever used coroutines myself.
| } | ||
|
|
||
| /** | ||
| * A C/C++ co_await expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backticks around co_await (and other similar cases).
| } | ||
|
|
||
| /** | ||
| * A C/C++ 'co_return' statement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be backticks.
|
There are a few tests for this in the extractor testsuite. |
Add classes for expressions co_yield and co_await. Adds classes for statements co_return and `for co_await`.
This commit fixes the previous one.
Initial impl won't support it
d2b69f6 to
d49bc4c
Compare
No description provided.