Assign a constant to ClassDecl/InterfaceDecl for name references. (#3722)

By adding a constant to ClassDecl/InterfaceDecl, we're able to remove
name reference special-casing. Use TryEvalInst on the Decl to generate
the Type. For ClassDecl, then use the generated constant for
self_type_id.
This commit is contained in:
Jon Ross-Perkins
2024-02-24 00:00:18 +00:00
committed by GitHub
parent 8e8eeb3243
commit 364ea5d3f2
109 changed files with 420 additions and 429 deletions
+21 -5
View File
@@ -364,12 +364,30 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
case SemIR::TupleInit::Kind:
return RebuildInitAsValue(context, inst, SemIR::TupleValue::Kind);
// These cases are always template constants.
case SemIR::Builtin::Kind:
// Builtins are always template constants.
return MakeConstantResult(context, inst, Phase::Template);
case SemIR::ClassDecl::Kind:
// TODO: Once classes have generic arguments, handle them.
return MakeConstantResult(
context,
SemIR::ClassType{SemIR::TypeId::TypeType,
inst.As<SemIR::ClassDecl>().class_id},
Phase::Template);
case SemIR::InterfaceDecl::Kind:
// TODO: Once interfaces have generic arguments, handle them.
return MakeConstantResult(
context,
SemIR::InterfaceType{SemIR::TypeId::TypeType,
inst.As<SemIR::InterfaceDecl>().interface_id},
Phase::Template);
case SemIR::ClassType::Kind:
case SemIR::InterfaceType::Kind:
// TODO: Once classes and interfaces have generic arguments, handle them.
return MakeConstantResult(context, inst, Phase::Template);
CARBON_FATAL() << inst.kind()
<< " is only created during corresponding Decl handling.";
// These cases are treated as being the unique canonical definition of the
// corresponding constant value.
@@ -475,10 +493,8 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
case SemIR::Branch::Kind:
case SemIR::BranchIf::Kind:
case SemIR::BranchWithArg::Kind:
case SemIR::ClassDecl::Kind:
case SemIR::ImplDecl::Kind:
case SemIR::Import::Kind:
case SemIR::InterfaceDecl::Kind:
case SemIR::Param::Kind:
case SemIR::ReturnExpr::Kind:
case SemIR::Return::Kind: