-
Notifications
You must be signed in to change notification settings - Fork 1.5k
More closely mimic the Clang compilation #5543
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
base: trunk
Are you sure you want to change the base?
More closely mimic the Clang compilation #5543
Conversation
Instead of using ASTUnit and tooling APIs, directly mimic what Clang does during the compilation. Run the Clang frontend until the translation unit parsing is done, at which point switch back to Carbon to finish the `Check` face and interface with Clang through `ASTContext` and `Sema`. In lower, finish the corresponding Clang compilation phase, i.e. CodeGen. Clang does not have the corresponding APIs and instead provides a callback-based mechanism. To map this back to Carbon APIs, we create a separate thread that gives control back to Carbon through the callbacks, and then finishes the compilation when the Carbon code is done. Although essentially a hack, this allows to easily fit into the Carbon codebase quickly and we should have an option of refactoring Clang code in LLVM upstream if this approach proves fruitful.
Did you mean |
This is very raw: tests fail, an approach to codegen needs to be updated, the documentation and PR description needs to be improved. Still posting this to get early feedback about the feasibility of this approach, especially the dance with multiple threads. |
…tion and Clang-related logic
🤦 I did, thanks for pointing that out. |
@@ -24,6 +24,21 @@ cc_library( | |||
], | |||
) | |||
|
|||
cc_library( | |||
name = "in_flight_clang", | |||
hdrs = ["in_flight_clang.h"], |
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.
[diff] reported by reviewdog 🐶
hdrs = ["in_flight_clang.h"], |
name = "in_flight_clang", | ||
hdrs = ["in_flight_clang.h"], | ||
srcs = ["in_flight_clang.cpp"], | ||
deps = [ |
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.
[diff] reported by reviewdog 🐶
deps = [ | |
hdrs = ["in_flight_clang.h"], | |
deps = [ |
srcs = ["in_flight_clang.cpp"], | ||
deps = [ | ||
"//common:check", | ||
"@llvm-project//llvm:Support", |
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.
[diff] reported by reviewdog 🐶
"@llvm-project//llvm:Support", |
"@llvm-project//clang:driver", | ||
"@llvm-project//clang:frontend", | ||
"@llvm-project//clang:frontend_tool", | ||
], |
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.
[diff] reported by reviewdog 🐶
], | |
"@llvm-project//llvm:Support", | |
], |
I've picked this up again and it's shaping up now, should be close to something I'd like to land. I want to do one last polish of the code before sending this out for review, but it's now roughly what I want it to be in terms of behavior. One last bit that I want to do a little later is to get rid of the use of |
Instead of using ASTUnit and tooling APIs, directly mimic what Clang does during the compilation.
Run the Clang frontend until the translation unit parsing is done, at which point switch back to Carbon to finish the
Check
phase and interface with Clang throughASTContext
andSema
. In lower, finish the corresponding Clang compilation phase, i.e. CodeGen.Clang does not have the corresponding APIs and instead provides a callback-based mechanism. To map this back to Carbon APIs, we create a separate thread that gives control back to Carbon through the callbacks, and then finishes the compilation when the Carbon code is done.
Although essentially a hack, this allows to easily fit into the Carbon codebase quickly and we should have an option of refactoring Clang code in LLVM upstream if this approach proves fruitful.
Replace this paragraph with a description of what this PR is changing or
adding, and why.
Closes #ISSUE