Store Clang Decls in a CanonicalValueStore (#5638)

Saves space since in most cases, we only need a `None` 32 bits index
instead of a null 64 bits pointer.

Based on discussions in [Carbon C++ Interop
weekly](https://docs.google.com/document/d/1YlxEOJ0r-o19o19TCJbFl4Ln1U88yn_Vj23y1Hr5vTk/edit?tab=t.0#heading=h.23l56bt5xwlu)
and Discord
([1](https://discord.com/channels/655572317891461132/768530752592805919/1375121180306047106),
[2](https://discord.com/channels/655572317891461132/768530752592805919/1380575881050718469)).

Note: Any `clang::DeclContext` is also a `clang::Decl`.

Part of #4666.
This commit is contained in:
Boaz Brickner
2025-06-10 16:55:29 +00:00
committed by GitHub
parent 6753a715f6
commit e4c8150f2c
7 changed files with 53 additions and 30 deletions
+4 -2
View File
@@ -670,10 +670,12 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id,
}
// If this is a C++ function, tell Clang that we referenced it.
if (auto* cpp_decl = sem_ir().functions().Get(function_id).cpp_decl) {
if (auto clang_decl_id = sem_ir().functions().Get(function_id).clang_decl_id;
clang_decl_id.has_value()) {
CARBON_CHECK(!specific_id.has_value(),
"Specific functions cannot have C++ definitions");
HandleReferencedCppFunction(cpp_decl);
HandleReferencedCppFunction(clang::dyn_cast<clang::FunctionDecl>(
sem_ir().clang_decls().Get(clang_decl_id)));
// TODO: Check that the signature and mangling generated by Clang and the
// one we generated are the same.
}