Add specific_id and pattern_inst_id to ClangDecl (#7583)

Exporting class fields in class specifics will require looking up
`ClangDecl`s by the field's `InstId` and the class's `SpecificId`. Add
the `specific_id` to ClangeDecl, and rework the reverse lookup to use a
`Set` with a `KeyContext` rather than a `Map`. The `Lookup` method now
takes an optional `SpecificId` argument, although currently it is always
`None`.

For `VarStorage`, reverse lookup is performed by the pattern `InstId`
rather than the `InstId` of the `VarStorage` itself, so also add
`pattern_inst_id` to `ClangDecl`, and provide a separate
`LookupByPatternInstId` method for reverse lookups. For this lookup, the
`inst_id` part of the key is set to `None`, so only the pattern's
`InstId` is used for lookup.
This commit is contained in:
Nicholas Bishop
2026-07-29 19:53:12 +00:00
committed by GitHub
parent f4e7a84df2
commit 198e447e4a
6 changed files with 69 additions and 39 deletions
+3 -3
View File
@@ -1439,10 +1439,10 @@ auto ExportVarToCpp(Context& context, SemIR::InstId inst_id,
context.ast_context(), decl_context,
/*StartLoc=*/clang_loc, /*IdLoc=*/clang_loc, identifier_info, cpp_type,
/*TInfo=*/nullptr, clang::SC_Extern);
context.clang_decls().AddVar(
context.clang_decls().Add(
{.key = SemIR::ClangDeclKey::ForNonFunctionDecl(var_decl),
.inst_id = inst_id},
var_storage.pattern_id);
.inst_id = var_storage.pattern_id,
.var_storage_inst_id = inst_id});
if (scope_inst.Is<SemIR::ClassDecl>()) {
SetCppClassMemberAccess(name_scope, entity_name.name_id, var_decl);