Add FieldStore and fix field initializer imports (#7287)

As suggested in [1], replace `FieldInitializerMap` with a `FieldStore`.
The corresponding `FieldId` is now stored in `FieldDecl`. To make room
for the `FieldId`, the `ElementIndex` is now stored in the `Field`,
along with the initializer.

In import_ref.cpp, resolving `FieldDecl` initializers is now supported,
and in convert.cpp `LoadImportRef` is called to do so. The
`field_initializer_import.carbon` test now passes.

Printing a `FieldDecl` instruction now prints the initializer as well,
if present. See field_initializer.carbon for an example.

[1]:
https://github.com/carbon-language/carbon-lang/pull/7238#discussion_r3283217158
This commit is contained in:
Nicholas Bishop
2026-06-01 19:02:01 +00:00
committed by GitHub
parent 14a213d095
commit 682f9fef16
39 changed files with 287 additions and 204 deletions
+7 -6
View File
@@ -153,13 +153,14 @@ auto AddBindingPattern(Context& context, SemIR::LocId name_loc,
}
auto field_id =
AddInst<SemIR::FieldDecl>(context, name_loc,
{.type_id = field_type_id,
.name_id = name_id,
.index = SemIR::ElementIndex::None});
context.field_decls_stack().AppendToTop(field_id);
context.fields().Add({.index = SemIR::ElementIndex::None,
.initializer_id = SemIR::InstId::None});
auto field_decl_id = AddInst<SemIR::FieldDecl>(
context, name_loc,
{.type_id = field_type_id, .name_id = name_id, .field_id = field_id});
context.field_decls_stack().AppendToTop(field_decl_id);
return {.pattern_id = field_id, .bind_id = field_id};
return {.pattern_id = field_decl_id, .bind_id = field_decl_id};
}
auto bind_id = AddInstInNoBlock(