mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Introduce TypeInstId (#5288)
TypeInstId is an InstId whose constant value has a type of TypeType. This includes: - Type value instructions, the `ClassType` or `IntLiteralType` instructions. - Constraint value instructions, which are the `FacetType` and `TypeType` instructions, each of which also have type TypeType. TypeInstId encodes in the type system that it is safe to convert the instruction's value to a TypeId, and CHECKs at construction that this invariant is maintained. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
03a31bd0de
commit
cf57c85545
@@ -1076,16 +1076,16 @@ static auto PerformBuiltinConversion(
|
||||
// `FacetValue`, which requires an instruction of type `TypeType`. So if
|
||||
// we are converting from a facet value, we get its `type` via an extra
|
||||
// `FacetAccessType` instruction.
|
||||
auto type_inst_id = SemIR::InstId::None;
|
||||
auto type_inst_id = SemIR::TypeInstId::None;
|
||||
if (sem_ir.types().Is<SemIR::FacetType>(value_type_id)) {
|
||||
type_inst_id =
|
||||
type_inst_id = context.types().GetAsTypeInstId(
|
||||
AddInst(context, loc_id,
|
||||
SemIR::FacetAccessType{
|
||||
.type_id = SemIR::TypeType::SingletonTypeId,
|
||||
.facet_value_inst_id = const_value_id,
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
type_inst_id = const_value_id;
|
||||
type_inst_id = context.types().GetAsTypeInstId(const_value_id);
|
||||
}
|
||||
return AddInst<SemIR::FacetValue>(
|
||||
context, loc_id,
|
||||
@@ -1470,7 +1470,7 @@ auto ExprAsType(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id,
|
||||
auto type_inst_id = ConvertToValueOfType(context, loc_id, value_id,
|
||||
SemIR::TypeType::SingletonTypeId);
|
||||
if (type_inst_id == SemIR::ErrorInst::SingletonInstId) {
|
||||
return {.inst_id = type_inst_id,
|
||||
return {.inst_id = SemIR::ErrorInst::SingletonTypeInstId,
|
||||
.type_id = SemIR::ErrorInst::SingletonTypeId};
|
||||
}
|
||||
|
||||
@@ -1481,11 +1481,11 @@ auto ExprAsType(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id,
|
||||
"cannot evaluate type expression");
|
||||
context.emitter().Emit(loc_id, TypeExprEvaluationFailure);
|
||||
}
|
||||
return {.inst_id = SemIR::ErrorInst::SingletonInstId,
|
||||
return {.inst_id = SemIR::ErrorInst::SingletonTypeInstId,
|
||||
.type_id = SemIR::ErrorInst::SingletonTypeId};
|
||||
}
|
||||
|
||||
return {.inst_id = type_inst_id,
|
||||
return {.inst_id = context.types().GetAsTypeInstId(type_inst_id),
|
||||
.type_id = context.types().GetTypeIdForTypeConstantId(type_const_id)};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user