mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:51:03 +01:00
Add a flag to build a single ASTContext shared across all compilations (#7567)
Instead of building one Clang `ASTContext` per compilation, the `--share-cpp-ast` flag causes us to build a single `ASTContext` and share it across all contexts. One new abstraction is added: `CppDomain` represents the Carbon-side view of a Clang AST that might be shared across multiple `SemIR::File`s. This object owns the Clang instance and the AST. For now, we have no isolation between the C++ state exposed to different Carbon compilations, and we have no multiplexing of generated LLVM IR from C++ into different Carbon compilations, so the mode is not usable yet. The plan is to keep it behind a flag until it's ready. Assisted-by: Gemini via Antigravity
This commit is contained in:
@@ -118,9 +118,7 @@ static auto AddNamespace(Context& context, PackageNameId cpp_package_id,
|
||||
|
||||
auto ImportCpp(Context& context,
|
||||
llvm::ArrayRef<Parse::Tree::PackagingNames> imports,
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
||||
llvm::LLVMContext* llvm_context,
|
||||
std::shared_ptr<clang::CompilerInvocation> invocation) -> void {
|
||||
CppDomain* domain) -> void {
|
||||
if (imports.empty()) {
|
||||
// TODO: Consider always having a (non-null) AST even if there are no Cpp
|
||||
// imports.
|
||||
@@ -137,7 +135,7 @@ auto ImportCpp(Context& context,
|
||||
SemIR::NameScope& name_scope = context.name_scopes().Get(name_scope_id);
|
||||
name_scope.set_is_closed_import(true);
|
||||
|
||||
if (GenerateAst(context, imports, fs, llvm_context, std::move(invocation))) {
|
||||
if (domain && GenerateAst(context, imports, *domain)) {
|
||||
name_scope.set_clang_decl_context_id(
|
||||
context.clang_decls().Add(
|
||||
{.key = SemIR::ClangDeclKey(
|
||||
|
||||
Reference in New Issue
Block a user