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
+2 -2
View File
@@ -140,7 +140,7 @@ static auto ConvertArgToTemplateArg(
context.types().TryGetAs<SemIR::CppTemplateNameType>(
inst.type_id())) {
clang::TemplateName name(cast<clang::TemplateDecl>(
context.clang_decls().Get(template_name_type->decl_id).key.decl));
context.clang_decls().Get(template_name_type->decl_id).decl()));
return clang::TemplateArgumentLoc(
context.ast_context(), clang::TemplateArgument(name),
/*TemplateKWLoc=*/clang::SourceLocation(),
@@ -346,7 +346,7 @@ auto PerformCallToCppTemplateName(Context& context, SemIR::LocId loc_id,
llvm::ArrayRef<SemIR::InstId> arg_ids)
-> SemIR::InstId {
auto* template_decl = dyn_cast<clang::TemplateDecl>(
context.clang_decls().Get(template_decl_id).key.decl);
context.clang_decls().Get(template_decl_id).decl());
auto loc = GetCppLocation(context, loc_id);
// Form a template argument list for this template.