-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes #77311
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 \ | ||
// RUN: -fsyntax-only -ast-dump -ast-dump-filter test | FileCheck %s | ||
|
||
#include "Inputs/std-coroutine.h" | ||
|
||
using namespace std; | ||
|
||
struct Task { | ||
struct promise_type { | ||
std::suspend_always initial_suspend() { return {}; } | ||
Task get_return_object() { | ||
return std::coroutine_handle<promise_type>::from_promise(*this); | ||
} | ||
std::suspend_always final_suspend() noexcept { return {}; } | ||
std::suspend_always return_void() { return {}; } | ||
void unhandled_exception() {} | ||
|
||
auto await_transform(int s) { | ||
struct awaiter { | ||
promise_type *promise; | ||
bool await_ready() { return true; } | ||
int await_resume() { return 1; } | ||
void await_suspend(std::coroutine_handle<>) {} | ||
}; | ||
|
||
return awaiter{this}; | ||
} | ||
}; | ||
|
||
Task(std::coroutine_handle<promise_type> promise); | ||
|
||
std::coroutine_handle<promise_type> handle; | ||
}; | ||
|
||
Task test() { | ||
co_await 1; | ||
// Writen souce code, verify no implicit bit for the co_await expr. | ||
// CHECK: CompoundStmt {{.*}} | ||
// CHECK-NEXT: | `-ExprWithCleanups {{.*}} 'int' | ||
// CHECK-NEXT: | `-CoawaitExpr {{.*}} 'int'{{$}} | ||
// CHECK-NEXT: | |-IntegerLiteral {{.*}} <col:12> 'int' 1 | ||
// CHECK-NEXT: | |-MaterializeTemporaryExpr {{.*}} 'awaiter' | ||
// CHECK-NEXT: | | `-CXXMemberCallExpr {{.*}} 'awaiter' | ||
// CHECK-NEXT: | | |-MemberExpr {{.*}} .await_transform | ||
} | ||
// Verify the implicit AST nodes for coroutines. | ||
// CHECK: |-DeclStmt {{.*}} | ||
// CHECK-NEXT: | `-VarDecl {{.*}} implicit used __promise | ||
// CHECK-NEXT: | `-CXXConstructExpr {{.*}} | ||
// CHECK-NEXT: |-ExprWithCleanups {{.*}} 'void' | ||
// CHECK-NEXT: | `-CoawaitExpr {{.*}} 'void' implicit | ||
// CHECK-NEXT: |-CXXMemberCallExpr {{.*}} 'std::suspend_always' | ||
// CHECK-NEXT: | | `-MemberExpr {{.*}} .initial_suspend | ||
// ... | ||
// FIXME: the CoreturnStmt should be marked as implicit | ||
// CHECK: CoreturnStmt {{.*}} <col:6>{{$}} | ||
|
||
Task test2() { | ||
// Writen souce code, verify no implicit bit for the co_return expr. | ||
// CHECK: CompoundStmt {{.*}} | ||
// CHECK-NEXT: | `-CoreturnStmt {{.*}} <line:{{.*}}:{{.*}}>{{$}} | ||
co_return; | ||
} | ||
// Verify the implicit AST nodes for coroutines. | ||
// CHECK: |-DeclStmt {{.*}} | ||
// CHECK-NEXT: | `-VarDecl {{.*}} implicit used __promise | ||
// ... | ||
// FIXME: the CoreturnStmt should be marked as implicit | ||
// CHECK: CoreturnStmt {{.*}} <col:6>{{$}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this node implicit for initial suspend, for a call to
await_transform
or both? It would be useful to clarify by matching some child nodes or the dump ofCoawaitExpr
itself.Also, could you add matching for both implicit and non-implicit
co_await
andco_return
instances to show that the bit does not incidentally gets set/unset all the time?Fixing
CoreturnStmt
in a follow-up does make a lot of sense!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.
This implicit node is just for initial suspend, it is the
InitSuspend
substmt of theCoroutineBodyStmt
.Added some more tests and matches for the written
co_await
andco_return
statements.