mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user