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:
Dana Jansens
2025-04-10 22:59:02 +00:00
committed by GitHub
co-authored by Richard Smith
parent 03a31bd0de
commit cf57c85545
27 changed files with 202 additions and 111 deletions
+10
View File
@@ -421,6 +421,16 @@ static auto GetConstantValue(EvalContext& eval_context,
return inst_id;
}
static auto GetConstantValue(EvalContext& eval_context,
SemIR::TypeInstId inst_id, Phase* phase)
-> SemIR::TypeInstId {
// The input instruction is a TypeInstId, and eval does not change concrete
// types (like TypeType which TypeInstId implies), so the result is also a
// valid TypeInstId.
return SemIR::TypeInstId::UnsafeMake(GetConstantValue(
eval_context, static_cast<SemIR::InstId>(inst_id), phase));
}
// Explicitly discard a `DestInstId`, because we should not be using the
// destination as part of evaluation.
static auto GetConstantValue(EvalContext& /*eval_context*/,