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
+4 -8
View File
@@ -219,13 +219,11 @@ static auto ConvertArgToExpr(Context& context, SemIR::InstId arg_inst_id,
}
auto EvalCppCall(Context& context, SemIR::LocId loc_id,
SemIR::ClangDeclId clang_decl_id, SemIR::InstBlockId args_id)
const SemIR::ClangDecl& clang_decl, SemIR::InstBlockId args_id)
-> SemIR::ConstantId {
const auto& args = context.inst_blocks().Get(args_id);
auto* decl = context.clang_decls().Get(clang_decl_id).GetAsKey().decl;
auto* function_decl = cast<clang::FunctionDecl>(decl);
auto* function_decl = cast<clang::FunctionDecl>(clang_decl.decl());
// Create expr for the function declaration.
auto* decl_ref_expr = clang::DeclRefExpr::Create(
@@ -305,10 +303,8 @@ auto MaybeModifyCppThunkCallForConstEval(Context& context, SemIR::Call* call)
function_decl = cast<clang::FunctionDecl>(
context.clang_decls()
.Get(context.clang_decls().Lookup(
thunk_callee_function.first_decl_id()))
.GetAsKey()
.decl);
.Lookup(thunk_callee_function.first_decl_id())
->decl());
if (!(function_decl->isConstexpr() || function_decl->isConsteval())) {
return;