-
Notifications
You must be signed in to change notification settings - Fork 1.5k
C++ interop: Call a subset of C++ from Carbon #4666
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
Comments
Hi, Is this issue still opened? |
Yes, I'm looking into this one. |
…rbon files (carbon-language#4667) This would be used to test interop with C++. carbon-language#4666
Ignore the AST, for now. Report cpp compilation errors and warnings. Part of carbon-language#4666
Ignore the AST, for now. Report cpp compilation errors and warnings. Part of carbon-language#4666
Ignore the AST and support a single Cpp import, for now. Report cpp compilation errors and warnings. Part of #4666
Propagate `FileSystem` to `buildASTFromCodeWithArgs`(). Part of #4666
Instead of compiling the imported file, generate a C++ header that includes all `Cpp` import files. Part of carbon-language#4666
Instead of compiling the imported file, generate a C++ header that includes all `Cpp` import files. Part of carbon-language#4666
Instead of compiling the imported file, generate a C++ header that includes all `Cpp` import files. Part of #4666
…age#4814) Instead of compiling the imported file, generate a C++ header that includes all `Cpp` import files. Part of carbon-language#4666
Also defined a dedicated `ImportCppDecl` `InstKind`. Part of #4666
This function is used by `import.cpp` and `import_cpp.cpp` to deduplciate some of the logic. However, it's not really part of the importing API, so it makes more sense to put it in the bottom. In the .cpp, it was between static functions, just for easier reviewing of the refactoring PR (carbon-language#4873). Part of carbon-language#4666.
ASTUnit is owned by `CompileSubcommand`, passed through `Unit` to be populated in `ImportCppFiles()` and used via `SemIR::File`. When generating the AST, pass `-x c++` args to compile C++ (temporary until we pass args properly). `Cpp` namespace is marked as a special namespace and has dedicated logic in `LookupNameInExactScope()`. The logic for importing declarations from C++ to Carbon is in `import_cpp.cpp`, but we're likely to want to refactor this signfiicantly over time as it grows (perhaps a dedicated directory?). Part of #4666.
…#5062) Keep a pointer to the Clang declaration in Carbon's function declaration and use it in Carbon mangling by calling Clang mangling. Create Clang's `MangleContext` once on demand. Part of #4666. C++ Interop Demo: ```c++ // hello_world.h void hello_world(); ``` ```c++ // hello_world.cpp #include <cstdio> void hello_world() { printf("Hello World!\n"); } ``` ``` // main.carbon library "Main"; import Cpp library "hello_world.h"; fn Run() -> i32 { Cpp.hello_world(); return 0; } ``` ```shell $ clang -c hello_world.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link hello_world.o main.o --output=demo $ ./demo Hello World! ```
…decl` since it's not specific for functions Part of carbon-language#4666
This is a followup of [a comment](https://github.com/carbon-language/carbon-lang/pull/5062/files/89e56d51858bcc18d4242d4e5c9ee0e7496d887e#r1979993815) in #5062. Add a mutable AST pointer to `FileContext`. This is necessary since we use [Clang with lack of const correctness](llvm/llvm-project#130096 (comment)). Alternatives in Clang: * Change `ASTUnit::getASTContext() const` to return a non-const `ASTContext`. [Tried and was rejected upstream due to weakening const correctness](llvm/llvm-project#130096). * Change `createMangleContext()` to be `const`. Tried that and it seems like it relies heavily on non const API. * Change `MangleContext::mangleName()` to `const`. Tried that but there are several lazy initialization and id creations happening that modify the context. See details in llvm/llvm-project#130613. Alternatives in Carbon: * Use `const_cast` on `ASTContext` when calling `createMangleContext()`. * Make `FileContext::sem_ir_` point to a mutable `SemIR::File`. * Change `File::cpp_ast()` to be const while keeping it return a mutable pointer. Part of #4666.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the This issue is labeled |
Currently has no effect because we can't do lookup in classes, yet. Part of carbon-language#4666.
Doc: Carbon: Early interop in toolchain
The text was updated successfully, but these errors were encountered: