Improve ClangDeclStore ergonomics (#7311)

Change `Lookup` by InstId to return a ClangDecl pointer. All callers
were immediately calling `Get` anyway, so this makes call sites a little
shorter. The other `Lookup` method, by ClangDeclKey, is sometimes called
without calling `Get`, so left that as-is, but renamed to `LookupId`.

Also add a `decl` method to ClangDecl so that the commonly repeated
`clang_decl->key.decl` can be written `clang_decl->decl()`.
This commit is contained in:
Nicholas Bishop
2026-06-05 20:49:34 +00:00
committed by GitHub
parent 44b17ff436
commit 5e62791ad2
16 changed files with 70 additions and 95 deletions
+3 -6
View File
@@ -3452,13 +3452,10 @@ static auto TryEvalCall(EvalContext& outer_eval_context, SemIR::LocId loc_id,
const SemIR::Function& function,
SemIR::SpecificId specific_id,
SemIR::InstBlockId args_id) -> SemIR::ConstantId {
auto clang_decl_id = outer_eval_context.sem_ir().clang_decls().Lookup(
const auto* clang_decl = outer_eval_context.sem_ir().clang_decls().Lookup(
function.first_decl_id());
if (clang_decl_id.has_value() && outer_eval_context.sem_ir()
.clang_decls()
.Get(clang_decl_id)
.is_imported) {
return EvalCppCall(outer_eval_context.context(), loc_id, clang_decl_id,
if (clang_decl && clang_decl->is_imported) {
return EvalCppCall(outer_eval_context.context(), loc_id, *clang_decl,
args_id);
} else if (function.body_block_ids.empty()) {
// TODO: Diagnose this.