mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:54:44 +01:00
Convert remaining type-value InstId fields to TypeInstId (#5294)
After #5280 there are a few more typed instructions that have an `InstId type_inst_id` that always holds a type value. These are converted to `TypeInstId` to encode this fact in the type system. The `ConvertAggregateElement()` function in convert.cpp is now able to receive `TypeInstId` for a couple arguments as well. Additionally, the `type_inst_id` field of `StructTypeField` is made into a `TypeInstId`. The `TupleType::elements_id` is renamed to `TupleType::type_elements_id` to try record the fact that it's an InstBlock of type value instructions. We don't introduce a TypeInstBlockId at this time, but it might be nice to make blocks of TypeInstIds in the future. To assist in working with a block of InstId that are type values, two additional helpers are added to the TypeStore: - GetBlockAsTypeInstIds which turns an `ArrayRef<InstId>` into a range of `TypeInstId` - GetBlockAsTypeIds which turns an `ArrayRef<InstId>` into a range of `TypeId` We use these helpers in places that iterate over the `TupleType::type_elements_id`.
This commit is contained in:
@@ -528,17 +528,16 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
|
||||
auto tuple_type =
|
||||
context.types().GetAs<SemIR::TupleType>(tuple_pattern.type_id);
|
||||
auto element_type_inst_ids =
|
||||
context.inst_blocks().Get(tuple_type.elements_id);
|
||||
context.inst_blocks().Get(tuple_type.type_elements_id);
|
||||
llvm::SmallVector<SemIR::InstId> subscrutinee_ids;
|
||||
subscrutinee_ids.reserve(element_type_inst_ids.size());
|
||||
for (auto [i, element_type_inst_id] :
|
||||
llvm::enumerate(element_type_inst_ids)) {
|
||||
subscrutinee_ids.push_back(AddInst<SemIR::TupleAccess>(
|
||||
context, scrutinee.loc_id,
|
||||
{.type_id =
|
||||
context.types().GetTypeIdForTypeInstId(element_type_inst_id),
|
||||
.tuple_id = entry.scrutinee_id,
|
||||
.index = SemIR::ElementIndex(i)}));
|
||||
for (auto [i, element_type_id] : llvm::enumerate(
|
||||
context.types().GetBlockAsTypeIds(element_type_inst_ids))) {
|
||||
subscrutinee_ids.push_back(
|
||||
AddInst<SemIR::TupleAccess>(context, scrutinee.loc_id,
|
||||
{.type_id = element_type_id,
|
||||
.tuple_id = entry.scrutinee_id,
|
||||
.index = SemIR::ElementIndex(i)}));
|
||||
}
|
||||
add_all_subscrutinees(subscrutinee_ids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user