Convert StructTypeField to a specific type. (#4492)

This converts `StructTypeField` from an instruction to a dedicated type,
with its own store. This had originated from discussing how
`.GetAs<SemIR::StructTypeField>` was more prevalent than for other
instructions, but is probably more interesting for the storage savings
(16 bytes StructTypeField + 4 byte LocId + 4 byte InstId -> 8 byte
StructTypeField).

Due to the different structure, these now have their own stack during
construction, reducing (but not eliminating) `args_type_info_stack_`
use-cases.

The test changes of different InstIds is expected because structs and
classes generate fewer instructions now. Other than that, results should
remain the same.

I'm generally trying to avoid unrelated cleanup here due to the PR size,
though I did scrutinize the `VerifyOnFinish` calls, adding one and
commenting others (putting them in member order because that's how I was
checking what was verified and what wasn't).
This commit is contained in:
Jon Ross-Perkins
2024-11-06 21:38:27 +00:00
committed by GitHub
parent 7977a9cddc
commit be56ff87c6
48 changed files with 535 additions and 436 deletions
+4 -7
View File
@@ -131,15 +131,12 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
binding_id,
{.type_id = field_type_id,
.name_id = name_id,
.index = SemIR::ElementIndex(context.args_type_info_stack()
.PeekCurrentBlockContents()
.size())});
.index = SemIR::ElementIndex(
context.struct_type_fields_stack().PeekArray().size())});
// Add a corresponding field to the object representation of the class.
context.args_type_info_stack().AddInstId(
context.AddInstInNoBlock<SemIR::StructTypeField>(
binding_id,
{.name_id = name_id, .field_type_id = cast_type_id}));
context.struct_type_fields_stack().AppendToTop(
{.name_id = name_id, .type_id = cast_type_id});
context.node_stack().Push(node_id, field_id);
break;
}