diff --git a/toolchain/check/action.cpp b/toolchain/check/action.cpp index c588f5f2c2aa..2426de19f6ae 100644 --- a/toolchain/check/action.cpp +++ b/toolchain/check/action.cpp @@ -102,7 +102,7 @@ static auto AddDependentActionSpliceImpl(Context& context, if (!result_type_inst_id.has_value()) { result_type_inst_id = AddDependentActionTypeInst( context, action.loc_id, - SemIR::TypeOfInst{.type_id = SemIR::TypeType::SingletonTypeId, + SemIR::TypeOfInst{.type_id = SemIR::TypeType::TypeId, .inst_id = inst_id}); } return AddInst( @@ -132,11 +132,11 @@ static auto RefineOperand(Context& context, SemIR::LocId loc_id, auto type_inst_id = context.types().GetInstId(inst.type_id()); inst_id = AddDependentActionSpliceImpl( context, - SemIR::LocIdAndInst(loc_id, - SemIR::RefineTypeAction{ - .type_id = SemIR::InstType::SingletonTypeId, - .inst_id = *inst_id, - .inst_type_inst_id = type_inst_id}), + SemIR::LocIdAndInst( + loc_id, + SemIR::RefineTypeAction{.type_id = SemIR::InstType::TypeId, + .inst_id = *inst_id, + .inst_type_inst_id = type_inst_id}), type_inst_id); } diff --git a/toolchain/check/call.cpp b/toolchain/check/call.cpp index d51820749188..6306f7359a39 100644 --- a/toolchain/check/call.cpp +++ b/toolchain/check/call.cpp @@ -101,13 +101,12 @@ static auto PerformCallToGenericClass(Context& context, SemIR::LocId loc_id, /*self_type_id=*/SemIR::InstId::None, /*self_id=*/SemIR::InstId::None, arg_ids); if (!callee_specific_id) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } - return GetOrAddInst( - context, loc_id, - {.type_id = SemIR::TypeType::SingletonTypeId, - .class_id = class_id, - .specific_id = *callee_specific_id}); + return GetOrAddInst(context, loc_id, + {.type_id = SemIR::TypeType::TypeId, + .class_id = class_id, + .specific_id = *callee_specific_id}); } // Performs a call where the callee is the name of a generic interface, such as @@ -123,7 +122,7 @@ static auto PerformCallToGenericInterface( /*self_type_id=*/SemIR::InstId::None, /*self_id=*/SemIR::InstId::None, arg_ids); if (!callee_specific_id) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } return GetOrAddInst( context, loc_id, @@ -149,23 +148,23 @@ static auto BuildCalleeSpecificFunction( // This is an associated function in an interface; the callee is the // specific function in the impl that corresponds to the specific function // we deduced. - callee_id = GetOrAddInst( - context, context.insts().GetLocId(generic_callee_id), - SemIR::SpecificImplFunction{ - .type_id = GetSingletonType( - context, SemIR::SpecificFunctionType::SingletonInstId), - .callee_id = generic_callee_id, - .specific_id = callee_specific_id}); + callee_id = + GetOrAddInst(context, context.insts().GetLocId(generic_callee_id), + SemIR::SpecificImplFunction{ + .type_id = GetSingletonType( + context, SemIR::SpecificFunctionType::InstId), + .callee_id = generic_callee_id, + .specific_id = callee_specific_id}); } else { // This is a regular generic function. The callee is the specific function // we deduced. - callee_id = GetOrAddInst( - context, context.insts().GetLocId(generic_callee_id), - SemIR::SpecificFunction{ - .type_id = GetSingletonType( - context, SemIR::SpecificFunctionType::SingletonInstId), - .callee_id = generic_callee_id, - .specific_id = callee_specific_id}); + callee_id = + GetOrAddInst(context, context.insts().GetLocId(generic_callee_id), + SemIR::SpecificFunction{ + .type_id = GetSingletonType( + context, SemIR::SpecificFunctionType::InstId), + .callee_id = generic_callee_id, + .specific_id = callee_specific_id}); } // Add the `self` argument back if there was one. @@ -208,7 +207,7 @@ static auto PerformCallToFunction(Context& context, SemIR::LocId loc_id, EntityKind::Function, callee_function.enclosing_specific_id, callee_function.self_type_id, callee_function.self_id, arg_ids); if (!callee_specific_id) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (callee_specific_id->has_value()) { @@ -240,7 +239,7 @@ static auto PerformCallToFunction(Context& context, SemIR::LocId loc_id, case SemIR::InitRepr::Incomplete: // Don't form an initializing expression with an incomplete type. // CheckFunctionReturnType will have diagnosed this for us if needed. - return_info.type_id = SemIR::ErrorInst::SingletonTypeId; + return_info.type_id = SemIR::ErrorInst::TypeId; break; } @@ -262,7 +261,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id, // Try treating the callee as a function first. auto callee_function = GetCalleeFunction(context.sem_ir(), callee_id); if (callee_function.is_error) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (callee_function.function_id.has_value()) { return PerformCallToFunction(context, loc_id, callee_id, callee_function, @@ -287,7 +286,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id, CARBON_DIAGNOSTIC(CallToNonCallable, Error, "value of type {0} is not callable", TypeOfInstId); context.emitter().Emit(loc_id, CallToNonCallable, callee_id); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } } } diff --git a/toolchain/check/check_unit.cpp b/toolchain/check/check_unit.cpp index ea5d4080f948..c3d68d40ab71 100644 --- a/toolchain/check/check_unit.cpp +++ b/toolchain/check/check_unit.cpp @@ -88,7 +88,7 @@ auto CheckUnit::Run() -> void { auto CheckUnit::InitPackageScopeAndImports() -> void { // Importing makes many namespaces, so only canonicalize the type once. auto namespace_type_id = - GetSingletonType(context_, SemIR::NamespaceType::SingletonInstId); + GetSingletonType(context_, SemIR::NamespaceType::InstId); // Define the package scope, with an instruction for `package` expressions to // reference. diff --git a/toolchain/check/class.cpp b/toolchain/check/class.cpp index a8f869c05163..566eba98c4cc 100644 --- a/toolchain/check/class.cpp +++ b/toolchain/check/class.cpp @@ -56,7 +56,7 @@ static auto CheckCompleteAdapterClassType( .Build(class_info.adapt_id, AdaptWithBase) .Note(class_info.base_id, AdaptWithBaseHere) .Emit(); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (!field_decls.empty()) { @@ -67,7 +67,7 @@ static auto CheckCompleteAdapterClassType( .Build(class_info.adapt_id, AdaptWithFields) .Note(field_decls.front(), AdaptWithFieldHere) .Emit(); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } for (auto inst_id : body) { @@ -84,7 +84,7 @@ static auto CheckCompleteAdapterClassType( .Build(class_info.adapt_id, AdaptWithVirtual) .Note(inst_id, AdaptWithVirtualHere) .Emit(); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } } } @@ -97,8 +97,7 @@ static auto CheckCompleteAdapterClassType( return AddInst( context, node_id, - {.type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::WitnessType::InstId), // TODO: Use InstId from the adapt declaration. .object_repr_type_inst_id = context.types().GetInstId(object_repr_id)}); } @@ -112,10 +111,10 @@ static auto AddStructTypeFields( field_decl.index = SemIR::ElementIndex{static_cast(struct_type_fields.size())}; ReplaceInstPreservingConstantValue(context, field_decl_id, field_decl); - if (field_decl.type_id == SemIR::ErrorInst::SingletonTypeId) { + if (field_decl.type_id == SemIR::ErrorInst::TypeId) { struct_type_fields.push_back( {.name_id = field_decl.name_id, - .type_inst_id = SemIR::ErrorInst::SingletonTypeInstId}); + .type_inst_id = SemIR::ErrorInst::TypeInstId}); continue; } auto unbound_element_type = @@ -141,8 +140,8 @@ static auto BuildVtable(Context& context, Parse::NodeId node_id, LoadImportRef(context, base_vtable_id); auto canonical_base_vtable_id = context.constant_values().GetConstantInstId(base_vtable_id); - if (canonical_base_vtable_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (canonical_base_vtable_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } auto base_vtable_inst_block = context.inst_blocks().Get( context.insts() @@ -183,7 +182,7 @@ static auto BuildVtable(Context& context, Parse::NodeId node_id, } return AddInst( context, node_id, - {.type_id = GetSingletonType(context, SemIR::VtableType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::VtableType::InstId), .virtual_functions_id = context.inst_blocks().Add(vtable)}); } @@ -222,7 +221,7 @@ static auto CheckCompleteClassType( struct_type_fields.push_back( {.name_id = SemIR::NameId::Vptr, .type_inst_id = context.types().GetInstId( - GetPointerType(context, SemIR::VtableType::SingletonInstId))}); + GetPointerType(context, SemIR::VtableType::InstId))}); } if (base_type_id.has_value()) { auto base_decl = context.insts().GetAs(class_info.base_id); @@ -242,14 +241,13 @@ static auto CheckCompleteClassType( auto struct_type_inst_id = AddTypeInst( context, node_id, - {.type_id = SemIR::TypeType::SingletonTypeId, + {.type_id = SemIR::TypeType::TypeId, .fields_id = AddStructTypeFields(context, struct_type_fields, field_decls)}); return AddInst( context, node_id, - {.type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::WitnessType::InstId), .object_repr_type_inst_id = struct_type_inst_id}); } diff --git a/toolchain/check/control_flow.cpp b/toolchain/check/control_flow.cpp index 258d930ff20d..2a38b56cd187 100644 --- a/toolchain/check/control_flow.cpp +++ b/toolchain/check/control_flow.cpp @@ -106,9 +106,9 @@ auto SetBlockArgResultBeforeConstantUse(Context& context, const_id = context.constant_values().Get( literal.value().value.ToBool() ? if_true : if_false); } else { - CARBON_CHECK(cond_const_id == SemIR::ErrorInst::SingletonConstantId, + CARBON_CHECK(cond_const_id == SemIR::ErrorInst::ConstantId, "Unexpected constant branch condition."); - const_id = SemIR::ErrorInst::SingletonConstantId; + const_id = SemIR::ErrorInst::ConstantId; } if (const_id.is_constant()) { diff --git a/toolchain/check/convert.cpp b/toolchain/check/convert.cpp index fda030be195a..6c943925e938 100644 --- a/toolchain/check/convert.cpp +++ b/toolchain/check/convert.cpp @@ -125,9 +125,9 @@ static auto MakeElementAccessInst(Context& context, SemIR::LocId loc_id, // index so that we don't need an integer literal instruction here, and // remove this special case. auto index_id = block.template AddInst( - loc_id, {.type_id = GetSingletonType( - context, SemIR::IntLiteralType::SingletonInstId), - .int_id = context.ints().Add(static_cast(i))}); + loc_id, + {.type_id = GetSingletonType(context, SemIR::IntLiteralType::InstId), + .int_id = context.ints().Add(static_cast(i))}); return AddInst(block, loc_id, {elem_type_id, aggregate_id, index_id}); } else { @@ -222,7 +222,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type, "list of initializers"); context.emitter().Emit(value_loc_id, ArrayInitDependentBound); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (tuple_elem_types.size() != array_bound) { if (target.diagnose) { @@ -241,7 +241,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type, : ArrayInitFromLiteralArgCountMismatch, *array_bound, tuple_elem_types.size()); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } PendingBlock target_block_storage(&context); @@ -272,8 +272,8 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type, context, value_loc_id, value_id, src_type_inst_id, literal_elems, ConversionTarget::FullInitializer, return_slot_arg_id, array_type.element_type_inst_id, target_block, i, i); - if (init_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (init_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } inits.push_back(init_id); } @@ -324,7 +324,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type, context.emitter().Emit(value_loc_id, TupleInitElementCountMismatch, dest_elem_types.size(), src_elem_types.size()); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // If we're forming an initializer, then we want an initializer for each @@ -358,8 +358,8 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type, context, value_loc_id, value_id, src_type_inst_id, literal_elems, inner_kind, target.init_id, dest_type_inst_id, target.init_block, i, i); - if (init_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (init_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } new_block.Set(i, init_id); } @@ -426,7 +426,7 @@ static auto ConvertStructToStructOrClass( ToClass, dest_elem_fields_size, src_elem_fields.size()); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // Prepare to look up fields in the source by index. @@ -508,7 +508,7 @@ static auto ConvertStructToStructOrClass( target.type_id, dest_field.name_id); } } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } } auto src_field = src_elem_fields[src_field_index]; @@ -521,8 +521,8 @@ static auto ConvertStructToStructOrClass( literal_elems, inner_kind, target.init_id, dest_field.type_inst_id, target.init_block, src_field_index, src_field_index + dest_vptr_offset, dest_vtable_id); - if (init_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (init_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } new_block.Set(i, init_id); } @@ -571,8 +571,8 @@ static auto ConvertStructToClass( CARBON_CHECK(dest_class_info.inheritance_kind != SemIR::Class::Abstract); auto object_repr_id = dest_class_info.GetObjectRepr(context.sem_ir(), dest_type.specific_id); - if (object_repr_id == SemIR::ErrorInst::SingletonTypeId) { - return SemIR::ErrorInst::SingletonInstId; + if (object_repr_id == SemIR::ErrorInst::TypeId) { + return SemIR::ErrorInst::InstId; } auto dest_struct_type = context.types().GetAs(object_repr_id); @@ -755,7 +755,7 @@ static auto GetTransitiveAdaptedType(Context& context, SemIR::TypeId type_id) static auto DiagnoseConversionFailureToConstraintValue( Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, SemIR::TypeId target_type_id) -> void { - CARBON_DCHECK(target_type_id == SemIR::TypeType::SingletonTypeId || + CARBON_DCHECK(target_type_id == SemIR::TypeType::TypeId || context.types().Is(target_type_id)); auto type_of_expr_id = context.insts().Get(expr_id).type_id(); @@ -888,8 +888,8 @@ static auto PerformBuiltinConversion( .init_id = foundation_init_id, .init_block = target.init_block, .diagnose = target.diagnose}); - if (foundation_value_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (foundation_value_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } } @@ -993,7 +993,7 @@ static auto PerformBuiltinConversion( } } - if (target.type_id == SemIR::TypeType::SingletonTypeId) { + if (target.type_id == SemIR::TypeType::TypeId) { // A tuple of types converts to type `type`. // TODO: This should apply even for non-literal tuples. if (auto tuple_literal = value.TryAs()) { @@ -1047,7 +1047,7 @@ static auto PerformBuiltinConversion( // FacetTypes, but we assume constant values for impl lookup at the moment. if (!const_value_id.has_value()) { context.TODO(loc_id, "conversion of runtime facet value"); - const_value_id = SemIR::ErrorInst::SingletonInstId; + const_value_id = SemIR::ErrorInst::InstId; } if (auto facet_access_type_inst = @@ -1072,7 +1072,7 @@ static auto PerformBuiltinConversion( sem_ir.types().GetConstantId(target.type_id)); if (lookup_result.has_value()) { if (lookup_result.has_error_value()) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } else { // We bind the input value to the target `FacetType` with a // `FacetValue`, which requires an instruction of type `TypeType`. So if @@ -1080,12 +1080,11 @@ static auto PerformBuiltinConversion( // `FacetAccessType` instruction. auto type_inst_id = SemIR::TypeInstId::None; if (sem_ir.types().Is(value_type_id)) { - type_inst_id = - AddTypeInst(context, loc_id, - SemIR::FacetAccessType{ - .type_id = SemIR::TypeType::SingletonTypeId, - .facet_value_inst_id = const_value_id, - }); + type_inst_id = AddTypeInst(context, loc_id, + SemIR::FacetAccessType{ + .type_id = SemIR::TypeType::TypeId, + .facet_value_inst_id = const_value_id, + }); } else { type_inst_id = context.types().GetAsTypeInstId(const_value_id); } @@ -1104,7 +1103,7 @@ static auto PerformBuiltinConversion( DiagnoseConversionFailureToConstraintValue(context, loc_id, value_id, target.type_id); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } } @@ -1118,8 +1117,8 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id, bool diagnose) -> SemIR::InstId { auto expr = context.insts().Get(expr_id); auto type_id = expr.type_id(); - if (type_id == SemIR::ErrorInst::SingletonTypeId) { - return SemIR::ErrorInst::SingletonInstId; + if (type_id == SemIR::ErrorInst::TypeId) { + return SemIR::ErrorInst::InstId; } if (InitReprIsCopyOfValueRepr(context.sem_ir(), type_id)) { @@ -1135,7 +1134,7 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id, bool diagnose) "cannot copy value of type {0}", TypeOfInstId); context.emitter().Emit(expr_id, CopyOfUncopyableType, expr_id); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto PerformAction(Context& context, SemIR::LocId loc_id, @@ -1154,10 +1153,9 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, // Start by making sure both sides are non-errors. If any part is an error, // the result is an error and we shouldn't diagnose. - if (sem_ir.insts().Get(expr_id).type_id() == - SemIR::ErrorInst::SingletonTypeId || - target.type_id == SemIR::ErrorInst::SingletonTypeId) { - return SemIR::ErrorInst::SingletonInstId; + if (sem_ir.insts().Get(expr_id).type_id() == SemIR::ErrorInst::TypeId || + target.type_id == SemIR::ErrorInst::TypeId) { + return SemIR::ErrorInst::InstId; } if (SemIR::GetExprCategory(sem_ir, expr_id) == SemIR::ExprCategory::NotExpr) { @@ -1169,7 +1167,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, "expression cannot be used as a value"); context.emitter().Emit(expr_id, UseOfNonExprAsValue); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // We can only perform initialization for complete, non-abstract types. Note @@ -1208,13 +1206,13 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, return context.emitter().Build(loc_id, AbstractTypeInInit, target.type_id); })) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // Check whether any builtin conversion applies. expr_id = PerformBuiltinConversion(context, loc_id, expr_id, target, vtable_id); - if (expr_id == SemIR::ErrorInst::SingletonInstId) { + if (expr_id == SemIR::ErrorInst::InstId) { return expr_id; } @@ -1233,7 +1231,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, auto target_type_inst_id = context.types().GetInstId(target.type_id); return AddDependentActionSplice( context, loc_id, - SemIR::ConvertToValueAction{.type_id = SemIR::InstType::SingletonTypeId, + SemIR::ConvertToValueAction{.type_id = SemIR::InstType::TypeId, .inst_id = expr_id, .target_type_inst_id = target_type_inst_id}, target_type_inst_id); @@ -1254,7 +1252,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, if (!target.diagnose) { return context.emitter().BuildSuppressed(); } - if (target.type_id == SemIR::TypeType::SingletonTypeId || + if (target.type_id == SemIR::TypeType::TypeId || sem_ir.types().Is(target.type_id)) { CARBON_DIAGNOSTIC( ConversionFailureNonTypeToFacet, Error, @@ -1265,7 +1263,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, return context.emitter().Build( loc_id, ConversionFailureNonTypeToFacet, target.kind == ConversionTarget::ExplicitAs, expr_id, - target.type_id == SemIR::TypeType::SingletonTypeId, target.type_id); + target.type_id == SemIR::TypeType::TypeId, target.type_id); } else { CARBON_DIAGNOSTIC(ConversionFailure, Error, "cannot{0:| implicitly} convert expression of type " @@ -1280,7 +1278,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, }); // Pull a value directly out of the initializer if possible and wanted. - if (expr_id != SemIR::ErrorInst::SingletonInstId && + if (expr_id != SemIR::ErrorInst::InstId && CanUseValueOfInitializer(sem_ir, target.type_id, target.kind)) { expr_id = AddInst( context, loc_id, {.type_id = target.type_id, .init_id = expr_id}); @@ -1309,7 +1307,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, sem_ir.insts().Get(expr_id)); case SemIR::ExprCategory::Error: - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; case SemIR::ExprCategory::Initializing: if (target.is_initializer()) { @@ -1423,7 +1421,7 @@ auto ConvertToBoolValue(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id) -> SemIR::InstId { return ConvertToValueOfType( context, loc_id, value_id, - GetSingletonType(context, SemIR::BoolType::SingletonInstId)); + GetSingletonType(context, SemIR::BoolType::InstId)); } auto ConvertForExplicitAs(Context& context, Parse::NodeId as_node, @@ -1459,7 +1457,7 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id, .Build(call_loc_id, MissingObjectInMethodCall) .Note(callee_decl_id, InCallToFunction) .Emit(); - self_id = SemIR::ErrorInst::SingletonInstId; + self_id = SemIR::ErrorInst::InstId; } return CallerPatternMatch(context, callee_specific_id, callee.self_param_id, @@ -1469,11 +1467,11 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id, auto ExprAsType(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id, bool diagnose) -> TypeExpr { - auto type_inst_id = ConvertToValueOfType(context, loc_id, value_id, - SemIR::TypeType::SingletonTypeId); - if (type_inst_id == SemIR::ErrorInst::SingletonInstId) { - return {.inst_id = SemIR::ErrorInst::SingletonTypeInstId, - .type_id = SemIR::ErrorInst::SingletonTypeId}; + auto type_inst_id = + ConvertToValueOfType(context, loc_id, value_id, SemIR::TypeType::TypeId); + if (type_inst_id == SemIR::ErrorInst::InstId) { + return {.inst_id = SemIR::ErrorInst::TypeInstId, + .type_id = SemIR::ErrorInst::TypeId}; } auto type_const_id = context.constant_values().Get(type_inst_id); @@ -1483,8 +1481,8 @@ 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::SingletonTypeInstId, - .type_id = SemIR::ErrorInst::SingletonTypeId}; + return {.inst_id = SemIR::ErrorInst::TypeInstId, + .type_id = SemIR::ErrorInst::TypeId}; } return {.inst_id = context.types().GetAsTypeInstId(type_inst_id), diff --git a/toolchain/check/convert.h b/toolchain/check/convert.h index a3f425daa386..ac32105c2fc9 100644 --- a/toolchain/check/convert.h +++ b/toolchain/check/convert.h @@ -119,9 +119,9 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id, // A type that has been converted for use as a type expression. struct TypeExpr { - // The converted expression of type `type`, or `ErrorInst::SingletonInstId`. + // The converted expression of type `type`, or `ErrorInst::InstId`. SemIR::TypeInstId inst_id; - // The corresponding type, or `ErrorInst::SingletonTypeId`. + // The corresponding type, or `ErrorInst::TypeId`. SemIR::TypeId type_id; }; diff --git a/toolchain/check/deduce.cpp b/toolchain/check/deduce.cpp index 299620b22164..880da32774df 100644 --- a/toolchain/check/deduce.cpp +++ b/toolchain/check/deduce.cpp @@ -321,7 +321,7 @@ auto DeductionContext::Deduce() -> bool { param_type_id) : TryConvertToValueOfType(context(), loc_id_, arg_id, param_type_id); - if (arg_id == SemIR::ErrorInst::SingletonInstId) { + if (arg_id == SemIR::ErrorInst::InstId) { return false; } } @@ -578,7 +578,7 @@ auto DeductionContext::CheckDeductionIsComplete() -> bool { NoteGenericHere(context(), generic_id_, diag); diag.Emit(); } - deduced_arg_id = SemIR::ErrorInst::SingletonInstId; + deduced_arg_id = SemIR::ErrorInst::InstId; } } diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index 4281412d00ff..4765cb0f0b29 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -247,7 +247,7 @@ static auto GetPhase(const SemIR::ConstantValueStore& constant_values, SemIR::ConstantId constant_id) -> Phase { if (!constant_id.is_constant()) { return Phase::Runtime; - } else if (constant_id == SemIR::ErrorInst::SingletonConstantId) { + } else if (constant_id == SemIR::ErrorInst::ConstantId) { return Phase::UnknownDueToError; } switch (constant_values.GetDependence(constant_id)) { @@ -285,7 +285,7 @@ static auto MakeConstantResult(Context& context, SemIR::Inst inst, Phase phase) return context.constants().GetOrAdd(inst, SemIR::ConstantDependence::Template); case Phase::UnknownDueToError: - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; case Phase::Runtime: return SemIR::ConstantId::NotConstant; } @@ -293,9 +293,8 @@ static auto MakeConstantResult(Context& context, SemIR::Inst inst, Phase phase) // Forms a `constant_id` describing why an evaluation was not constant. static auto MakeNonConstantResult(Phase phase) -> SemIR::ConstantId { - return phase == Phase::UnknownDueToError - ? SemIR::ErrorInst::SingletonConstantId - : SemIR::ConstantId::NotConstant; + return phase == Phase::UnknownDueToError ? SemIR::ErrorInst::ConstantId + : SemIR::ConstantId::NotConstant; } // Converts a bool value into a ConstantId. @@ -334,11 +333,10 @@ static auto MakeFacetTypeResult(Context& context, const SemIR::FacetTypeInfo& info, Phase phase) -> SemIR::ConstantId { SemIR::FacetTypeId facet_type_id = context.facet_types().Add(info); - return MakeConstantResult( - context, - SemIR::FacetType{.type_id = SemIR::TypeType::SingletonTypeId, - .facet_type_id = facet_type_id}, - phase); + return MakeConstantResult(context, + SemIR::FacetType{.type_id = SemIR::TypeType::TypeId, + .facet_type_id = facet_type_id}, + phase); } // `GetConstantValue` checks to see whether the provided ID describes a value @@ -797,7 +795,7 @@ static auto PerformArrayIndex(EvalContext& eval_context, SemIR::ArrayIndex inst) eval_context.emitter().Emit( eval_context.GetDiagnosticLoc(inst.index_id), ArrayIndexOutOfBounds, {.type = index->type_id, .value = index_val}, aggregate_type_id); - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } } } @@ -824,11 +822,11 @@ static auto MakeIntTypeResult(Context& context, SemIR::LocId loc_id, SemIR::IntKind int_kind, SemIR::InstId width_id, Phase phase) -> SemIR::ConstantId { auto result = SemIR::IntType{ - .type_id = GetSingletonType(context, SemIR::TypeType::SingletonInstId), + .type_id = GetSingletonType(context, SemIR::TypeType::InstId), .int_kind = int_kind, .bit_width_id = width_id}; if (!ValidateIntType(context, loc_id, result)) { - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } return MakeConstantResult(context, result, phase); } @@ -1101,7 +1099,7 @@ static auto PerformBuiltinIntShiftOp(Context& context, SemIR::LocId loc_id, builtin_kind == SemIR::BuiltinFunctionKind::IntLeftShift, {.type = rhs.type_id, .value = rhs_orig_val}); // TODO: Is it useful to recover by returning 0 or -1? - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } if (rhs_orig_val.isNegative() && @@ -1115,7 +1113,7 @@ static auto PerformBuiltinIntShiftOp(Context& context, SemIR::LocId loc_id, builtin_kind == SemIR::BuiltinFunctionKind::IntLeftShift, {.type = rhs.type_id, .value = rhs_orig_val}); // TODO: Is it useful to recover by returning 0 or -1? - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } llvm::APInt result_val; @@ -1134,7 +1132,7 @@ static auto PerformBuiltinIntShiftOp(Context& context, SemIR::LocId loc_id, context.emitter().Emit(loc_id, CompileTimeUnsizedShiftOutOfRange, {.type = rhs.type_id, .value = rhs_orig_val}, IntStore::MaxIntWidth); - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } lhs_val = lhs_val.sext( IntStore::CanonicalBitWidth(lhs_val.getSignificantBits() + *width)); @@ -1178,7 +1176,7 @@ static auto PerformBuiltinBinaryIntOp(Context& context, SemIR::LocId loc_id, case SemIR::BuiltinFunctionKind::IntUMod: if (rhs_val.isZero()) { DiagnoseDivisionByZero(context, loc_id); - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } break; default: @@ -1423,7 +1421,7 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context, // Allow errors to be diagnosed for both sides of the operator before // returning here if any error occurred on either side. if (!lhs_facet_type_id.has_value() || !rhs_facet_type_id.has_value()) { - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } // Reuse one of the argument instructions if nothing has changed. if (lhs_facet_type_id == rhs_facet_type_id) { @@ -1438,8 +1436,7 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context, } case SemIR::BuiltinFunctionKind::IntLiteralMakeType: { - return context.constant_values().Get( - SemIR::IntLiteralType::SingletonInstId); + return context.constant_values().Get(SemIR::IntLiteralType::InstId); } case SemIR::BuiltinFunctionKind::IntMakeTypeSigned: { @@ -1458,14 +1455,13 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context, break; } if (!ValidateFloatBitWidth(context, loc_id, arg_ids[0])) { - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } - return context.constant_values().Get( - SemIR::LegacyFloatType::SingletonInstId); + return context.constant_values().Get(SemIR::LegacyFloatType::InstId); } case SemIR::BuiltinFunctionKind::BoolMakeType: { - return context.constant_values().Get(SemIR::BoolType::SingletonInstId); + return context.constant_values().Get(SemIR::BoolType::InstId); } // Integer conversions. @@ -1598,7 +1594,7 @@ static auto MakeConstantForCall(EvalContext& eval_context, SemIR::LocId loc_id, // // TODO: Use a better representation for this. if (call.args_id == SemIR::InstBlockId::None) { - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } // Find the constant value of the callee. @@ -1631,7 +1627,7 @@ static auto MakeConstantForCall(EvalContext& eval_context, SemIR::LocId loc_id, ReplaceFieldWithConstantValue(eval_context, &call, &SemIR::Call::args_id, &phase); if (phase == Phase::UnknownDueToError) { - return SemIR::ErrorInst::SingletonConstantId; + return SemIR::ErrorInst::ConstantId; } // If any operand of the call is non-constant, the call is non-constant. @@ -1743,7 +1739,7 @@ static auto TryEvalTypedInst(EvalContext& eval_context, SemIR::InstId inst_id, // The result is an instruction. return MakeConstantResult( eval_context.context(), - SemIR::InstValue{.type_id = SemIR::InstType::SingletonTypeId, + SemIR::InstValue{.type_id = SemIR::InstType::TypeId, .inst_id = result_inst_id}, Phase::Concrete); } @@ -1880,10 +1876,10 @@ auto TryEvalTypedInst(EvalContext& eval_context, if (auto facet_type = base_facet_inst.TryAs()) { info = GetConstantFacetTypeInfo(eval_context, facet_type->facet_type_id, &phase); - } else if (base_facet_type_id == SemIR::ErrorInst::SingletonTypeId) { - return SemIR::ErrorInst::SingletonConstantId; + } else if (base_facet_type_id == SemIR::ErrorInst::TypeId) { + return SemIR::ErrorInst::ConstantId; } else { - CARBON_CHECK(base_facet_type_id == SemIR::TypeType::SingletonTypeId, + CARBON_CHECK(base_facet_type_id == SemIR::TypeType::TypeId, "Unexpected type_id: {0}, inst: {1}", base_facet_type_id, base_facet_inst); } @@ -1906,10 +1902,10 @@ auto TryEvalTypedInst(EvalContext& eval_context, inst_id)) { SemIR::ConstantId lhs = eval_context.GetConstantValue(impls->lhs_id); SemIR::ConstantId rhs = eval_context.GetConstantValue(impls->rhs_id); - if (rhs != SemIR::ErrorInst::SingletonConstantId && + if (rhs != SemIR::ErrorInst::ConstantId && IsPeriodSelf(eval_context, lhs)) { auto rhs_inst_id = eval_context.constant_values().GetInstId(rhs); - if (rhs_inst_id == SemIR::TypeType::SingletonInstId) { + if (rhs_inst_id == SemIR::TypeType::InstId) { // `.Self impls type` -> nothing to do. } else { auto facet_type = diff --git a/toolchain/check/eval_inst.cpp b/toolchain/check/eval_inst.cpp index 1eb2919cc98d..b7c88fbb6490 100644 --- a/toolchain/check/eval_inst.cpp +++ b/toolchain/check/eval_inst.cpp @@ -124,7 +124,7 @@ auto EvalConstantInst(Context& context, SemIR::ClassDecl inst) // A non-generic class declaration evaluates to the class type. return ConstantEvalResult::NewSamePhase( - SemIR::ClassType{.type_id = SemIR::TypeType::SingletonTypeId, + SemIR::ClassType{.type_id = SemIR::TypeType::TypeId, .class_id = inst.class_id, .specific_id = SemIR::SpecificId::None}); } @@ -311,8 +311,7 @@ auto EvalConstantInst(Context& context, SemIR::NameRef inst) auto EvalConstantInst(Context& context, SemIR::InstId inst_id, SemIR::RequireCompleteType inst) -> ConstantEvalResult { - auto witness_type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId); + auto witness_type_id = GetSingletonType(context, SemIR::WitnessType::InstId); // If the type is a concrete constant, require it to be complete now. auto complete_type_id = diff --git a/toolchain/check/eval_inst.h b/toolchain/check/eval_inst.h index 7648bdf68f36..3718c88ea5cb 100644 --- a/toolchain/check/eval_inst.h +++ b/toolchain/check/eval_inst.h @@ -87,7 +87,7 @@ class ConstantEvalResult { }; constexpr ConstantEvalResult ConstantEvalResult::Error = - Existing(SemIR::ErrorInst::SingletonConstantId); + Existing(SemIR::ErrorInst::ConstantId); constexpr ConstantEvalResult ConstantEvalResult::NotConstant = ConstantEvalResult(SemIR::ConstantId::NotConstant); diff --git a/toolchain/check/facet_type.cpp b/toolchain/check/facet_type.cpp index 1f31b8d4ef71..96fc2560ec42 100644 --- a/toolchain/check/facet_type.cpp +++ b/toolchain/check/facet_type.cpp @@ -19,8 +19,7 @@ auto FacetTypeFromInterface(Context& context, SemIR::InterfaceId interface_id, SemIR::FacetTypeId facet_type_id = context.facet_types().Add( SemIR::FacetTypeInfo{.extend_constraints = {{interface_id, specific_id}}, .other_requirements = false}); - return {.type_id = SemIR::TypeType::SingletonTypeId, - .facet_type_id = facet_type_id}; + return {.type_id = SemIR::TypeType::TypeId, .facet_type_id = facet_type_id}; } // Returns `true` if the `FacetAccessWitness` of `witness_id` matches @@ -69,7 +68,7 @@ auto InitialFacetTypeImplWitness( auto facet_type_id = context.types().GetTypeIdForTypeInstId(facet_type_inst_id); - CARBON_CHECK(facet_type_id != SemIR::ErrorInst::SingletonTypeId); + CARBON_CHECK(facet_type_id != SemIR::ErrorInst::TypeId); auto facet_type = context.types().GetAs(facet_type_id); // TODO: This is currently a copy because I'm not sure whether anything could // cause the facet type store to resize before we are done with it. @@ -82,8 +81,7 @@ auto InitialFacetTypeImplWitness( .impl_id = SemIR::ImplId::None}); return AddInst( context, witness_loc_id, - {.type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::WitnessType::InstId), .witness_table_id = witness_table_inst_id, .specific_id = self_specific_id}); } @@ -94,7 +92,7 @@ auto InitialFacetTypeImplWitness( context, witness_loc_id, facet_type_inst_id, is_definition); })) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } const auto& interface = @@ -115,7 +113,7 @@ auto InitialFacetTypeImplWitness( context.inst_blocks().AddUninitialized(assoc_entities.size()); table = context.inst_blocks().GetMutable(elements_id); for (auto& uninit : table) { - uninit = SemIR::ImplWitnessTablePlaceholder::SingletonInstId; + uninit = SemIR::ImplWitnessTablePlaceholder::InstId; } auto witness_table_inst_id = AddInst( @@ -124,8 +122,7 @@ auto InitialFacetTypeImplWitness( witness_inst_id = AddInst( context, witness_loc_id, - {.type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::WitnessType::InstId), .witness_table_id = witness_table_inst_id, .specific_id = self_specific_id}); } @@ -138,23 +135,23 @@ auto InitialFacetTypeImplWitness( continue; } auto& table_entry = table[access.index.index]; - if (table_entry == SemIR::ErrorInst::SingletonInstId) { + if (table_entry == SemIR::ErrorInst::InstId) { // Don't overwrite an error value. This prioritizes not generating // multiple errors for one associated constant over picking a value // for it to use to attempt recovery. continue; } auto rewrite_inst_id = rewrite.rhs_id; - if (rewrite_inst_id == SemIR::ErrorInst::SingletonInstId) { - table_entry = SemIR::ErrorInst::SingletonInstId; + if (rewrite_inst_id == SemIR::ErrorInst::InstId) { + table_entry = SemIR::ErrorInst::InstId; continue; } auto decl_id = context.constant_values().GetConstantInstId( assoc_entities[access.index.index]); CARBON_CHECK(decl_id.has_value(), "Non-constant associated entity"); - if (decl_id == SemIR::ErrorInst::SingletonInstId) { - table_entry = SemIR::ErrorInst::SingletonInstId; + if (decl_id == SemIR::ErrorInst::InstId) { + table_entry = SemIR::ErrorInst::InstId; continue; } @@ -170,11 +167,11 @@ auto InitialFacetTypeImplWitness( SemIR::NameId); context.emitter().Emit(facet_type_inst_id, RewriteForAssociatedFunction, fn.name_id); - table_entry = SemIR::ErrorInst::SingletonInstId; + table_entry = SemIR::ErrorInst::InstId; continue; } - if (table_entry != SemIR::ImplWitnessTablePlaceholder::SingletonInstId) { + if (table_entry != SemIR::ImplWitnessTablePlaceholder::InstId) { if (table_entry != rewrite_inst_id) { // TODO: Figure out how to print the two different values // `const_id` & `rewrite_inst_id` in the diagnostic @@ -189,7 +186,7 @@ auto InitialFacetTypeImplWitness( facet_type_inst_id, AssociatedConstantWithDifferentValues, assoc_const.name_id, table_entry, rewrite_inst_id); } - table_entry = SemIR::ErrorInst::SingletonInstId; + table_entry = SemIR::ErrorInst::InstId; continue; } @@ -227,7 +224,7 @@ auto InitialFacetTypeImplWitness( context.emitter().Emit( facet_type_inst_id, AssociatedConstantNotConstantAfterConversion, assoc_const.name_id, rewrite_inst_id, assoc_const_type_id); - rewrite_inst_id = SemIR::ErrorInst::SingletonInstId; + rewrite_inst_id = SemIR::ErrorInst::InstId; } } @@ -268,8 +265,7 @@ auto AllocateFacetTypeImplWitness(Context& context, } llvm::SmallVector empty_table( - assoc_entities.size(), - SemIR::ImplWitnessTablePlaceholder::SingletonInstId); + assoc_entities.size(), SemIR::ImplWitnessTablePlaceholder::InstId); context.inst_blocks().ReplacePlaceholder(witness_id, empty_table); } diff --git a/toolchain/check/function.cpp b/toolchain/check/function.cpp index 8af6e7ba36c1..d9b7421c1a7c 100644 --- a/toolchain/check/function.cpp +++ b/toolchain/check/function.cpp @@ -33,8 +33,8 @@ auto CheckFunctionTypeMatches(Context& context, new_function.GetDeclaredReturnType(context.sem_ir()); auto prev_return_type_id = prev_function.GetDeclaredReturnType(context.sem_ir(), prev_specific_id); - if (new_return_type_id == SemIR::ErrorInst::SingletonTypeId || - prev_return_type_id == SemIR::ErrorInst::SingletonTypeId) { + if (new_return_type_id == SemIR::ErrorInst::TypeId || + prev_return_type_id == SemIR::ErrorInst::TypeId) { return false; } if (!context.types().AreEqualAcrossDeclarations(new_return_type_id, diff --git a/toolchain/check/generic.cpp b/toolchain/check/generic.cpp index 6300e3e86296..af09b794c148 100644 --- a/toolchain/check/generic.cpp +++ b/toolchain/check/generic.cpp @@ -344,7 +344,7 @@ static auto MakeGenericEvalBlock(Context& context, SemIR::GenericId generic_id, context, generic_id, region, context.insts().GetLocId(inst_id), constants_in_generic, inside_redeclaration, inst.type_id()); // If the generic declaration is invalid, it can result in an error. - if (type_id == SemIR::ErrorInst::SingletonTypeId) { + if (type_id == SemIR::ErrorInst::TypeId) { break; } // TODO: Eventually, completeness requirements should be modeled as diff --git a/toolchain/check/handle_alias.cpp b/toolchain/check/handle_alias.cpp index 20d2cca90a65..994fea53f3cf 100644 --- a/toolchain/check/handle_alias.cpp +++ b/toolchain/check/handle_alias.cpp @@ -56,8 +56,8 @@ auto HandleParseNode(Context& context, Parse::AliasId /*node_id*/) -> bool { CARBON_DIAGNOSTIC(AliasRequiresNameRef, Error, "alias initializer must be a name reference"); context.emitter().Emit(expr_node, AliasRequiresNameRef); - alias_type_id = SemIR::ErrorInst::SingletonTypeId; - alias_value_id = SemIR::ErrorInst::SingletonInstId; + alias_type_id = SemIR::ErrorInst::TypeId; + alias_value_id = SemIR::ErrorInst::InstId; } auto alias_id = AddInst(context, name_context.loc_id, {.type_id = alias_type_id, diff --git a/toolchain/check/handle_array.cpp b/toolchain/check/handle_array.cpp index 444f1e3ea592..30ec24fe00cb 100644 --- a/toolchain/check/handle_array.cpp +++ b/toolchain/check/handle_array.cpp @@ -43,16 +43,16 @@ auto HandleParseNode(Context& context, Parse::ArrayExprId node_id) -> bool { if (!context.constant_values().Get(bound_inst_id).is_constant()) { CARBON_DIAGNOSTIC(InvalidArrayExpr, Error, "array bound is not a constant"); context.emitter().Emit(bound_inst_id, InvalidArrayExpr); - context.node_stack().Push(node_id, SemIR::ErrorInst::SingletonInstId); + context.node_stack().Push(node_id, SemIR::ErrorInst::InstId); return true; } bound_inst_id = ConvertToValueOfType( context, context.insts().GetLocId(bound_inst_id), bound_inst_id, - GetSingletonType(context, SemIR::IntLiteralType::SingletonInstId)); + GetSingletonType(context, SemIR::IntLiteralType::InstId)); AddInstAndPush( context, node_id, - {.type_id = SemIR::TypeType::SingletonTypeId, + {.type_id = SemIR::TypeType::TypeId, .bound_id = bound_inst_id, .element_type_inst_id = element_type.inst_id}); return true; diff --git a/toolchain/check/handle_binding_pattern.cpp b/toolchain/check/handle_binding_pattern.cpp index 7958eab46dc9..5c921015f4fd 100644 --- a/toolchain/check/handle_binding_pattern.cpp +++ b/toolchain/check/handle_binding_pattern.cpp @@ -142,8 +142,8 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id, return context.emitter().Build(type_node, AbstractTypeInFieldDecl, cast_type_id); }); - if (cast_type_id == SemIR::ErrorInst::SingletonTypeId) { - cast_type_inst_id = SemIR::ErrorInst::SingletonTypeInstId; + if (cast_type_id == SemIR::ErrorInst::TypeId) { + cast_type_inst_id = SemIR::ErrorInst::TypeInstId; } auto binding_id = context.parse_tree().As(node_id); @@ -266,11 +266,11 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id, auto result_inst_id = SemIR::InstId::None; if (had_error) { if (name_id != SemIR::NameId::Underscore) { - AddNameToLookup(context, name_id, SemIR::ErrorInst::SingletonInstId); + AddNameToLookup(context, name_id, SemIR::ErrorInst::InstId); } // Replace the parameter with `ErrorInst` so that we don't try // constructing a generic based on it. - result_inst_id = SemIR::ErrorInst::SingletonInstId; + result_inst_id = SemIR::ErrorInst::InstId; } else { result_inst_id = make_binding_pattern(); if (node_kind == Parse::NodeKind::LetBindingPattern) { @@ -381,8 +381,7 @@ auto HandleParseNode(Context& context, Parse::AddrId node_id) -> bool { if (pointer_type) { auto addr_pattern_id = AddPatternInst( context, node_id, - {.type_id = SemIR::AutoType::SingletonTypeId, - .inner_id = param_pattern_id}); + {.type_id = SemIR::AutoType::TypeId, .inner_id = param_pattern_id}); context.node_stack().Push(node_id, addr_pattern_id); } else { CARBON_DIAGNOSTIC( diff --git a/toolchain/check/handle_choice.cpp b/toolchain/check/handle_choice.cpp index 97223a7406bc..3bc2ed4221aa 100644 --- a/toolchain/check/handle_choice.cpp +++ b/toolchain/check/handle_choice.cpp @@ -50,10 +50,9 @@ auto HandleParseNode(Context& context, Parse::ChoiceDefinitionStartId node_id) // Choices create a ClassId, since they ultimately turn into a class with // methods and some builtin impls. - auto class_decl = - SemIR::ClassDecl{.type_id = SemIR::TypeType::SingletonTypeId, - .class_id = SemIR::ClassId::None, - .decl_block_id = decl_block_id}; + auto class_decl = SemIR::ClassDecl{.type_id = SemIR::TypeType::TypeId, + .class_id = SemIR::ClassId::None, + .decl_block_id = decl_block_id}; auto class_decl_id = AddPlaceholderInst(context, node_id, class_decl); context.decl_name_stack().AddNameOrDiagnose(name_context, class_decl_id, @@ -281,8 +280,7 @@ auto HandleParseNode(Context& context, Parse::ChoiceDefinitionId node_id) auto choice_witness_id = AddInst( context, node_id, SemIR::CompleteTypeWitness{ - .type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + .type_id = GetSingletonType(context, SemIR::WitnessType::InstId), .object_repr_type_inst_id = context.types().GetInstId(GetStructType(context, fields_id))}); // Note: avoid storing a reference to the returned Class, since it may be diff --git a/toolchain/check/handle_class.cpp b/toolchain/check/handle_class.cpp index 478a168183cb..98ce2ea50ea5 100644 --- a/toolchain/check/handle_class.cpp +++ b/toolchain/check/handle_class.cpp @@ -208,10 +208,9 @@ static auto BuildClassDecl(Context& context, Parse::AnyClassDeclId node_id, auto decl_block_id = context.inst_block_stack().Pop(); // Add the class declaration. - auto class_decl = - SemIR::ClassDecl{.type_id = SemIR::TypeType::SingletonTypeId, - .class_id = SemIR::ClassId::None, - .decl_block_id = decl_block_id}; + auto class_decl = SemIR::ClassDecl{.type_id = SemIR::TypeType::TypeId, + .class_id = SemIR::ClassId::None, + .decl_block_id = decl_block_id}; auto class_decl_id = AddPlaceholderInst(context, node_id, class_decl); // TODO: Store state regarding is_extern. @@ -388,8 +387,8 @@ auto HandleParseNode(Context& context, Parse::AdaptDeclId node_id) -> bool { return context.emitter().Build(node_id, AbstractTypeInAdaptDecl, adapted_type_inst_id); }); - if (adapted_type_id == SemIR::ErrorInst::SingletonTypeId) { - adapted_type_inst_id = SemIR::ErrorInst::SingletonTypeInstId; + if (adapted_type_id == SemIR::ErrorInst::TypeId) { + adapted_type_inst_id = SemIR::ErrorInst::TypeInstId; } // Build a SemIR representation for the declaration. @@ -425,10 +424,9 @@ struct BaseInfo { SemIR::NameScopeId scope_id; SemIR::TypeInstId inst_id; }; -constexpr BaseInfo BaseInfo::Error = { - .type_id = SemIR::ErrorInst::SingletonTypeId, - .scope_id = SemIR::NameScopeId::None, - .inst_id = SemIR::ErrorInst::SingletonTypeInstId}; +constexpr BaseInfo BaseInfo::Error = {.type_id = SemIR::ErrorInst::TypeId, + .scope_id = SemIR::NameScopeId::None, + .inst_id = SemIR::ErrorInst::TypeInstId}; } // namespace // Diagnoses an attempt to derive from a final type. @@ -453,7 +451,7 @@ static auto CheckBaseType(Context& context, Parse::NodeId node_id, base_type_inst_id); }); - if (base_type_id == SemIR::ErrorInst::SingletonTypeId) { + if (base_type_id == SemIR::ErrorInst::TypeId) { return BaseInfo::Error; } @@ -530,7 +528,7 @@ auto HandleParseNode(Context& context, Parse::BaseDeclId node_id) -> bool { .base_type_inst_id = base_info.inst_id, .index = SemIR::ElementIndex::None}); - if (base_info.type_id != SemIR::ErrorInst::SingletonTypeId) { + if (base_info.type_id != SemIR::ErrorInst::TypeId) { auto base_class_info = context.classes().Get( context.types().GetAs(base_info.type_id).class_id); class_info.is_dynamic |= base_class_info.is_dynamic; diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index cef48efa88e7..d2ddccfaf5b8 100644 --- a/toolchain/check/handle_function.cpp +++ b/toolchain/check/handle_function.cpp @@ -560,7 +560,7 @@ static auto CheckFunctionDefinitionSignature(Context& context, // Check the parameter types are complete. for (auto param_ref_id : params_to_complete) { - if (param_ref_id == SemIR::ErrorInst::SingletonInstId) { + if (param_ref_id == SemIR::ErrorInst::InstId) { continue; } diff --git a/toolchain/check/handle_if_expr.cpp b/toolchain/check/handle_if_expr.cpp index 1c319ed57889..c511928c1936 100644 --- a/toolchain/check/handle_if_expr.cpp +++ b/toolchain/check/handle_if_expr.cpp @@ -38,7 +38,7 @@ static auto DecayIntLiteralToSizedInt(Context& context, Parse::NodeId node_id, SemIR::InstId operand_id) -> SemIR::InstId { if (context.types().GetInstId(context.insts().Get(operand_id).type_id()) == - SemIR::IntLiteralType::SingletonInstId) { + SemIR::IntLiteralType::InstId) { operand_id = ConvertToValueOfType( context, node_id, operand_id, MakeIntType(context, node_id, SemIR::IntKind::Signed, diff --git a/toolchain/check/handle_impl.cpp b/toolchain/check/handle_impl.cpp index b19f943f5244..587b56519851 100644 --- a/toolchain/check/handle_impl.cpp +++ b/toolchain/check/handle_impl.cpp @@ -100,7 +100,7 @@ auto HandleParseNode(Context& context, Parse::DefaultSelfImplAsId node_id) CARBON_DIAGNOSTIC(ImplAsOutsideClass, Error, "`impl as` can only be used in a class"); context.emitter().Emit(node_id, ImplAsOutsideClass); - self_type_id = SemIR::ErrorInst::SingletonTypeId; + self_type_id = SemIR::ErrorInst::TypeId; } // Build the implicit access to the enclosing `Self`. @@ -111,7 +111,7 @@ auto HandleParseNode(Context& context, Parse::DefaultSelfImplAsId node_id) // handling of the `Self` expression. auto self_inst_id = AddTypeInst( context, node_id, - SemIR::NameRef{.type_id = SemIR::TypeType::SingletonTypeId, + SemIR::NameRef{.type_id = SemIR::TypeType::TypeId, .name_id = SemIR::NameId::SelfType, .value_id = context.types().GetInstId(self_type_id)}); @@ -184,7 +184,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node, } const auto& impl = context.impls().Get(impl_id); - if (impl.witness_id == SemIR::ErrorInst::SingletonInstId) { + if (impl.witness_id == SemIR::ErrorInst::InstId) { parent_scope.set_has_error(); } else { bool is_complete = RequireCompleteType( @@ -227,8 +227,7 @@ static auto PopImplIntroducerAndParamsAsNameComponent( CARBON_CHECK(call_params_id == SemIR::InstBlockId::Empty || llvm::all_of(context.inst_blocks().Get(call_params_id), [](SemIR::InstId inst_id) { - return inst_id == - SemIR::ErrorInst::SingletonInstId; + return inst_id == SemIR::ErrorInst::InstId; })); } @@ -321,7 +320,7 @@ static auto CheckConstraintIsInterface(Context& context, SemIR::TypeInstId constraint_id) -> SemIR::SpecificInterface { auto facet_type_id = context.types().GetTypeIdForTypeInstId(constraint_id); - if (facet_type_id == SemIR::ErrorInst::SingletonTypeId) { + if (facet_type_id == SemIR::ErrorInst::TypeId) { return SemIR::SpecificInterface::None; } auto facet_type = context.types().TryGetAs(facet_type_id); @@ -415,7 +414,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id, impl_info.witness_id = ImplWitnessForDeclaration(context, impl_info, is_definition); } else { - impl_info.witness_id = SemIR::ErrorInst::SingletonInstId; + impl_info.witness_id = SemIR::ErrorInst::InstId; // TODO: We might also want to mark that the name scope for the impl has // an error -- at least once we start making name lookups within the impl // also look into the facet (eg, so you can name associated constants from @@ -435,14 +434,14 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id, if (name.implicit_param_patterns_id.has_value()) { for (auto inst_id : context.inst_blocks().Get(name.implicit_param_patterns_id)) { - if (inst_id == SemIR::ErrorInst::SingletonInstId) { + if (inst_id == SemIR::ErrorInst::InstId) { has_error_in_implicit_pattern = true; break; } } } if (impl_info.generic_id.has_value() && !has_error_in_implicit_pattern && - impl_info.witness_id != SemIR::ErrorInst::SingletonInstId) { + impl_info.witness_id != SemIR::ErrorInst::InstId) { context.inst_block_stack().Push(); auto deduced_specific_id = DeduceImplArguments( context, node_id, @@ -471,7 +470,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id, // diagnostics. FillImplWitnessWithErrors(context, impl_info); context.impls().Get(impl_decl.impl_id).witness_id = - SemIR::ErrorInst::SingletonInstId; + SemIR::ErrorInst::InstId; } } } else { @@ -484,13 +483,13 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id, ReplaceInstBeforeConstantUse(context, impl_decl_id, impl_decl); // For an `extend impl` declaration, mark the impl as extending this `impl`. - if (self_type_id != SemIR::ErrorInst::SingletonTypeId && + if (self_type_id != SemIR::ErrorInst::TypeId && introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extend)) { auto extend_node = introducer.modifier_node_id(ModifierOrder::Decl); if (impl_info.generic_id.has_value()) { constraint_type_inst_id = AddTypeInst( context, context.insts().GetLocId(constraint_type_inst_id), - {.type_id = SemIR::TypeType::SingletonTypeId, + {.type_id = SemIR::TypeType::TypeId, .inst_id = constraint_type_inst_id, .specific_id = context.generics().GetSelfSpecific(impl_info.generic_id)}); @@ -501,7 +500,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id, // Don't allow the invalid impl to be used. FillImplWitnessWithErrors(context, impl_info); context.impls().Get(impl_decl.impl_id).witness_id = - SemIR::ErrorInst::SingletonInstId; + SemIR::ErrorInst::InstId; } } @@ -510,7 +509,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id, // there is an error that would prevent the impl from being legal to define. if (!is_definition && !invalid_redeclaration && context.impls().Get(impl_decl.impl_id).witness_id != - SemIR::ErrorInst::SingletonInstId) { + SemIR::ErrorInst::InstId) { context.definitions_required_by_decl().push_back(impl_decl_id); } diff --git a/toolchain/check/handle_index.cpp b/toolchain/check/handle_index.cpp index e7e8d009f110..b53c536c5af0 100644 --- a/toolchain/check/handle_index.cpp +++ b/toolchain/check/handle_index.cpp @@ -102,7 +102,7 @@ static auto PerformIndexWith(Context& context, Parse::NodeId node_id, CARBON_DIAGNOSTIC(TypeNotIndexable, Error, "type {0} does not support indexing", SemIR::TypeId); context.emitter().Emit(node_id, TypeNotIndexable, operand_type_id); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } Operator op{ @@ -171,8 +171,8 @@ auto HandleParseNode(Context& context, Parse::IndexExprId node_id) -> bool { } default: { - auto elem_id = SemIR::ErrorInst::SingletonInstId; - if (operand_type_id != SemIR::ErrorInst::SingletonTypeId) { + auto elem_id = SemIR::ErrorInst::InstId; + if (operand_type_id != SemIR::ErrorInst::TypeId) { elem_id = PerformIndexWith(context, node_id, operand_inst_id, operand_type_id, index_inst_id); } diff --git a/toolchain/check/handle_interface.cpp b/toolchain/check/handle_interface.cpp index e281dfb60fb4..3b7701a73944 100644 --- a/toolchain/check/handle_interface.cpp +++ b/toolchain/check/handle_interface.cpp @@ -52,9 +52,8 @@ static auto BuildInterfaceDecl(Context& context, auto decl_block_id = context.inst_block_stack().Pop(); // Add the interface declaration. - auto interface_decl = - SemIR::InterfaceDecl{SemIR::TypeType::SingletonTypeId, - SemIR::InterfaceId::None, decl_block_id}; + auto interface_decl = SemIR::InterfaceDecl{ + SemIR::TypeType::TypeId, SemIR::InterfaceId::None, decl_block_id}; auto interface_decl_id = AddPlaceholderInst(context, node_id, interface_decl); SemIR::Interface interface_info = {name_context.MakeEntityWithParamsBase( diff --git a/toolchain/check/handle_let_and_var.cpp b/toolchain/check/handle_let_and_var.cpp index 5a277d7d69d5..ffd002e6a66a 100644 --- a/toolchain/check/handle_let_and_var.cpp +++ b/toolchain/check/handle_let_and_var.cpp @@ -281,7 +281,7 @@ static auto FinishAssociatedConstant(Context& context, Parse::LetDeclId node_id, auto decl = context.insts().TryGetAs( decl_info.pattern_id); if (!decl) { - if (decl_info.pattern_id != SemIR::ErrorInst::SingletonInstId) { + if (decl_info.pattern_id != SemIR::ErrorInst::InstId) { CARBON_DIAGNOSTIC(ExpectedSymbolicBindingInAssociatedConstant, Error, "pattern in associated constant declaration must be a " "single `:!` binding"); diff --git a/toolchain/check/handle_literal.cpp b/toolchain/check/handle_literal.cpp index 6a8af3f228b8..4ecba66285ea 100644 --- a/toolchain/check/handle_literal.cpp +++ b/toolchain/check/handle_literal.cpp @@ -18,7 +18,7 @@ auto HandleParseNode(Context& context, Parse::BoolLiteralFalseId node_id) -> bool { AddInstAndPush( context, node_id, - {.type_id = GetSingletonType(context, SemIR::BoolType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::BoolType::InstId), .value = SemIR::BoolValue::False}); return true; } @@ -27,7 +27,7 @@ auto HandleParseNode(Context& context, Parse::BoolLiteralTrueId node_id) -> bool { AddInstAndPush( context, node_id, - {.type_id = GetSingletonType(context, SemIR::BoolType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::BoolType::InstId), .value = SemIR::BoolValue::True}); return true; } @@ -58,7 +58,7 @@ auto HandleParseNode(Context& context, Parse::RealLiteralId node_id) -> bool { llvm::APSInt); context.emitter().Emit(node_id, RealMantissaTooLargeForI64, llvm::APSInt(real_value.mantissa, true)); - context.node_stack().Push(node_id, SemIR::ErrorInst::SingletonInstId); + context.node_stack().Push(node_id, SemIR::ErrorInst::InstId); return true; } @@ -68,7 +68,7 @@ auto HandleParseNode(Context& context, Parse::RealLiteralId node_id) -> bool { llvm::APSInt); context.emitter().Emit(node_id, RealExponentTooLargeForI64, llvm::APSInt(real_value.exponent, false)); - context.node_stack().Push(node_id, SemIR::ErrorInst::SingletonInstId); + context.node_stack().Push(node_id, SemIR::ErrorInst::InstId); return true; } @@ -79,8 +79,7 @@ auto HandleParseNode(Context& context, Parse::RealLiteralId node_id) -> bool { auto float_id = context.sem_ir().floats().Add(llvm::APFloat(double_val)); AddInstAndPush( context, node_id, - {.type_id = - GetSingletonType(context, SemIR::LegacyFloatType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::LegacyFloatType::InstId), .float_id = float_id}); return true; } @@ -88,7 +87,7 @@ auto HandleParseNode(Context& context, Parse::RealLiteralId node_id) -> bool { auto HandleParseNode(Context& context, Parse::StringLiteralId node_id) -> bool { AddInstAndPush( context, node_id, - {.type_id = GetSingletonType(context, SemIR::StringType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::StringType::InstId), .string_literal_id = context.tokens().GetStringLiteralValue( context.parse_tree().node_token(node_id))}); return true; @@ -155,13 +154,13 @@ auto HandleParseNode(Context& context, Parse::FloatTypeLiteralId node_id) auto HandleParseNode(Context& context, Parse::StringTypeLiteralId node_id) -> bool { - context.node_stack().Push(node_id, SemIR::StringType::SingletonInstId); + context.node_stack().Push(node_id, SemIR::StringType::InstId); return true; } auto HandleParseNode(Context& context, Parse::TypeTypeLiteralId node_id) -> bool { - context.node_stack().Push(node_id, SemIR::TypeType::SingletonInstId); + context.node_stack().Push(node_id, SemIR::TypeType::InstId); return true; } diff --git a/toolchain/check/handle_name.cpp b/toolchain/check/handle_name.cpp index 06d1abaa6e74..33e1ec68beef 100644 --- a/toolchain/check/handle_name.cpp +++ b/toolchain/check/handle_name.cpp @@ -286,8 +286,7 @@ auto HandleParseNode(Context& context, Parse::DesignatorExprId node_id) auto HandleParseNode(Context& context, Parse::PackageExprId node_id) -> bool { AddInstAndPush( context, node_id, - {.type_id = - GetSingletonType(context, SemIR::NamespaceType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::NamespaceType::InstId), .name_id = SemIR::NameId::PackageNamespace, .value_id = SemIR::Namespace::PackageInstId}); return true; diff --git a/toolchain/check/handle_namespace.cpp b/toolchain/check/handle_namespace.cpp index 32dc9394e942..9aa89bed7623 100644 --- a/toolchain/check/handle_namespace.cpp +++ b/toolchain/check/handle_namespace.cpp @@ -39,9 +39,9 @@ auto HandleParseNode(Context& context, Parse::NamespaceId node_id) -> bool { context.decl_introducer_state_stack().Pop(); LimitModifiersOnDecl(context, introducer, KeywordModifierSet::None); - auto namespace_inst = SemIR::Namespace{ - GetSingletonType(context, SemIR::NamespaceType::SingletonInstId), - SemIR::NameScopeId::None, SemIR::InstId::None}; + auto namespace_inst = + SemIR::Namespace{GetSingletonType(context, SemIR::NamespaceType::InstId), + SemIR::NameScopeId::None, SemIR::InstId::None}; auto namespace_id = AddPlaceholderInst(context, node_id, namespace_inst); SemIR::ScopeLookupResult lookup_result = diff --git a/toolchain/check/handle_operator.cpp b/toolchain/check/handle_operator.cpp index 8d1ca9ef9026..31974d004c15 100644 --- a/toolchain/check/handle_operator.cpp +++ b/toolchain/check/handle_operator.cpp @@ -221,8 +221,7 @@ auto HandleParseNode(Context& context, Parse::PostfixOperatorStarId node_id) auto inner_type = ExprAsType(context, node_id, value_id); AddInstAndPush( context, node_id, - {.type_id = SemIR::TypeType::SingletonTypeId, - .pointee_id = inner_type.inst_id}); + {.type_id = SemIR::TypeType::TypeId, .pointee_id = inner_type.inst_id}); return true; } @@ -239,13 +238,13 @@ auto HandleParseNode(Context& context, Parse::PrefixOperatorAmpId node_id) CARBON_DIAGNOSTIC(AddrOfEphemeralRef, Error, "cannot take the address of a temporary object"); context.emitter().Emit(TokenOnly(node_id), AddrOfEphemeralRef); - value_id = SemIR::ErrorInst::SingletonInstId; + value_id = SemIR::ErrorInst::InstId; break; default: CARBON_DIAGNOSTIC(AddrOfNonRef, Error, "cannot take the address of non-reference expression"); context.emitter().Emit(TokenOnly(node_id), AddrOfNonRef); - value_id = SemIR::ErrorInst::SingletonInstId; + value_id = SemIR::ErrorInst::InstId; break; } // TODO: Preserve spelling of type of operand where possible. @@ -276,9 +275,9 @@ auto HandleParseNode(Context& context, Parse::PrefixOperatorConstId node_id) context.emitter().Emit(node_id, RepeatedConst); } auto inner_type = ExprAsType(context, node_id, value_id); - AddInstAndPush(context, node_id, - {.type_id = SemIR::TypeType::SingletonTypeId, - .inner_id = inner_type.inst_id}); + AddInstAndPush( + context, node_id, + {.type_id = SemIR::TypeType::TypeId, .inner_id = inner_type.inst_id}); return true; } @@ -330,7 +329,7 @@ auto HandleParseNode(Context& context, Parse::PrefixOperatorStarId node_id) TokenOnly(node_id), DerefOfNonPointer, not_pointer_type_id); // TODO: Check for any facet here, rather than only a type. - if (not_pointer_type_id == SemIR::TypeType::SingletonTypeId) { + if (not_pointer_type_id == SemIR::TypeType::TypeId) { CARBON_DIAGNOSTIC( DerefOfType, Note, "to form a pointer type, write the `*` after the pointee type"); diff --git a/toolchain/check/handle_struct.cpp b/toolchain/check/handle_struct.cpp index ce8c83509e19..1e3f3947f5e1 100644 --- a/toolchain/check/handle_struct.cpp +++ b/toolchain/check/handle_struct.cpp @@ -142,7 +142,7 @@ auto HandleParseNode(Context& context, Parse::StructLiteralId node_id) -> bool { if (DiagnoseDuplicateNames(context, field_name_nodes, fields, /*is_struct_type_literal=*/false)) { - context.node_stack().Push(node_id, SemIR::ErrorInst::SingletonInstId); + context.node_stack().Push(node_id, SemIR::ErrorInst::InstId); } else { auto type_id = GetStructType( context, context.struct_type_fields().AddCanonical(fields)); @@ -168,12 +168,12 @@ auto HandleParseNode(Context& context, Parse::StructTypeLiteralId node_id) if (DiagnoseDuplicateNames(context, field_name_nodes, fields, /*is_struct_type_literal=*/true)) { - context.node_stack().Push(node_id, SemIR::ErrorInst::SingletonInstId); + context.node_stack().Push(node_id, SemIR::ErrorInst::InstId); } else { auto fields_id = context.struct_type_fields().AddCanonical(fields); AddInstAndPush( context, node_id, - {.type_id = SemIR::TypeType::SingletonTypeId, .fields_id = fields_id}); + {.type_id = SemIR::TypeType::TypeId, .fields_id = fields_id}); } context.struct_type_fields_stack().PopArray(); diff --git a/toolchain/check/handle_where.cpp b/toolchain/check/handle_where.cpp index 6666313da8ce..676f14c99591 100644 --- a/toolchain/check/handle_where.cpp +++ b/toolchain/check/handle_where.cpp @@ -17,12 +17,12 @@ auto HandleParseNode(Context& context, Parse::WhereOperandId node_id) -> bool { auto [self_node, self_id] = context.node_stack().PopExprWithNodeId(); auto self_type_id = ExprAsType(context, self_node, self_id).type_id; // Only facet types may have `where` restrictions. - if (self_type_id != SemIR::ErrorInst::SingletonTypeId && + if (self_type_id != SemIR::ErrorInst::TypeId && !context.types().IsFacetType(self_type_id)) { CARBON_DIAGNOSTIC(WhereOnNonFacetType, Error, "left argument of `where` operator must be a facet type"); context.emitter().Emit(self_node, WhereOnNonFacetType); - self_type_id = SemIR::ErrorInst::SingletonTypeId; + self_type_id = SemIR::ErrorInst::TypeId; } // Introduce a name scope so that we can remove the `.Self` entry we are @@ -105,13 +105,13 @@ auto HandleParseNode(Context& context, Parse::RequirementImplsId node_id) // Check lhs is a facet and rhs is a facet type. auto lhs_as_type = ExprAsType(context, lhs_node, lhs_id); auto rhs_as_type = ExprAsType(context, rhs_node, rhs_id); - if (rhs_as_type.type_id != SemIR::ErrorInst::SingletonTypeId && + if (rhs_as_type.type_id != SemIR::ErrorInst::TypeId && !context.types().IsFacetType(rhs_as_type.type_id)) { CARBON_DIAGNOSTIC( ImplsOnNonFacetType, Error, "right argument of `impls` requirement must be a facet type"); context.emitter().Emit(rhs_node, ImplsOnNonFacetType); - rhs_as_type.inst_id = SemIR::ErrorInst::SingletonTypeInstId; + rhs_as_type.inst_id = SemIR::ErrorInst::TypeInstId; } // TODO: Require that at least one side uses a designator. // TODO: For things like `HashSet(.T) as type`, add an implied constraint @@ -139,7 +139,7 @@ auto HandleParseNode(Context& context, Parse::WhereExprId node_id) -> bool { context.node_stack().Pop(); SemIR::InstBlockId requirements_id = context.args_type_info_stack().Pop(); AddInstAndPush(context, node_id, - {.type_id = SemIR::TypeType::SingletonTypeId, + {.type_id = SemIR::TypeType::TypeId, .period_self_id = period_self_id, .requirements_id = requirements_id}); return true; diff --git a/toolchain/check/impl.cpp b/toolchain/check/impl.cpp index c3b58d906c26..46c43f32e554 100644 --- a/toolchain/check/impl.cpp +++ b/toolchain/check/impl.cpp @@ -56,7 +56,7 @@ static auto CheckAssociatedFunctionImplementation( interface_function_type.function_id); builder.Emit(); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto impl_enclosing_specific_id = @@ -80,7 +80,7 @@ static auto CheckAssociatedFunctionImplementation( context.functions().Get(interface_function_type.function_id), interface_function_specific_id, /*check_syntax=*/false, /*check_self=*/true)) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } return impl_decl_id; } @@ -91,9 +91,9 @@ auto ImplWitnessForDeclaration(Context& context, const SemIR::Impl& impl, CARBON_CHECK(!impl.has_definition_started()); auto self_type_id = context.types().GetTypeIdForTypeInstId(impl.self_id); - if (self_type_id == SemIR::ErrorInst::SingletonTypeId) { + if (self_type_id == SemIR::ErrorInst::TypeId) { // When 'impl as' is invalid, the self type is an error. - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } return InitialFacetTypeImplWitness( @@ -105,7 +105,7 @@ auto ImplWitnessForDeclaration(Context& context, const SemIR::Impl& impl, auto ImplWitnessStartDefinition(Context& context, SemIR::Impl& impl) -> void { CARBON_CHECK(impl.is_being_defined()); CARBON_CHECK(impl.witness_id.has_value()); - if (impl.witness_id == SemIR::ErrorInst::SingletonInstId) { + if (impl.witness_id == SemIR::ErrorInst::InstId) { return; } auto witness = context.insts().GetAs(impl.witness_id); @@ -143,8 +143,7 @@ auto ImplWitnessStartDefinition(Context& context, SemIR::Impl& impl) -> void { CARBON_CHECK(decl_id.has_value(), "Non-constant associated entity"); if (auto decl = context.insts().TryGetAs(decl_id)) { - if (witness_value == - SemIR::ImplWitnessTablePlaceholder::SingletonInstId) { + if (witness_value == SemIR::ImplWitnessTablePlaceholder::InstId) { CARBON_DIAGNOSTIC(ImplAssociatedConstantNeedsValue, Error, "associated constant {0} not given a value in impl " "of interface {1}", @@ -160,7 +159,7 @@ auto ImplWitnessStartDefinition(Context& context, SemIR::Impl& impl) -> void { .Note(assoc_entity, AssociatedConstantHere) .Emit(); - witness_value = SemIR::ErrorInst::SingletonInstId; + witness_value = SemIR::ErrorInst::InstId; } } } @@ -171,7 +170,7 @@ auto ImplWitnessStartDefinition(Context& context, SemIR::Impl& impl) -> void { auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void { CARBON_CHECK(impl.is_being_defined()); CARBON_CHECK(impl.witness_id.has_value()); - if (impl.witness_id == SemIR::ErrorInst::SingletonInstId) { + if (impl.witness_id == SemIR::ErrorInst::InstId) { return; } auto witness = context.insts().GetAs(impl.witness_id); @@ -195,8 +194,8 @@ auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void { auto decl = context.insts().Get(decl_id); CARBON_KIND_SWITCH(decl) { case CARBON_KIND(SemIR::StructValue struct_value): { - if (struct_value.type_id == SemIR::ErrorInst::SingletonTypeId) { - witness_value = SemIR::ErrorInst::SingletonInstId; + if (struct_value.type_id == SemIR::ErrorInst::TypeId) { + witness_value = SemIR::ErrorInst::InstId; break; } auto type_inst = context.types().GetAsInst(struct_value.type_id); @@ -224,7 +223,7 @@ auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void { NoteAssociatedFunction(context, builder, fn_type->function_id); builder.Emit(); - witness_value = SemIR::ErrorInst::SingletonInstId; + witness_value = SemIR::ErrorInst::InstId; } break; } @@ -233,9 +232,9 @@ auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void { break; } default: - CARBON_CHECK(decl_id == SemIR::ErrorInst::SingletonInstId, + CARBON_CHECK(decl_id == SemIR::ErrorInst::InstId, "Unexpected kind of associated entity {0}", decl); - witness_value = SemIR::ErrorInst::SingletonInstId; + witness_value = SemIR::ErrorInst::InstId; break; } } @@ -245,15 +244,15 @@ auto FinishImplWitness(Context& context, SemIR::Impl& impl) -> void { auto FillImplWitnessWithErrors(Context& context, SemIR::Impl& impl) -> void { if (impl.witness_id.has_value() && - impl.witness_id != SemIR::ErrorInst::SingletonInstId) { + impl.witness_id != SemIR::ErrorInst::InstId) { auto witness = context.insts().GetAs(impl.witness_id); auto witness_table = context.insts().GetAs( witness.witness_table_id); auto witness_block = context.inst_blocks().GetMutable(witness_table.elements_id); for (auto& elem : witness_block) { - if (elem == SemIR::ImplWitnessTablePlaceholder::SingletonInstId) { - elem = SemIR::ErrorInst::SingletonInstId; + if (elem == SemIR::ImplWitnessTablePlaceholder::InstId) { + elem = SemIR::ErrorInst::InstId; } } } @@ -261,7 +260,7 @@ auto FillImplWitnessWithErrors(Context& context, SemIR::Impl& impl) -> void { auto AssignImplIdInWitness(Context& context, SemIR::ImplId impl_id, SemIR::InstId witness_id) -> void { - if (witness_id == SemIR::ErrorInst::SingletonInstId) { + if (witness_id == SemIR::ErrorInst::InstId) { return; } auto witness = context.insts().GetAs(witness_id); diff --git a/toolchain/check/impl_lookup.cpp b/toolchain/check/impl_lookup.cpp index dadc463d71cb..ea55b3a0fa12 100644 --- a/toolchain/check/impl_lookup.cpp +++ b/toolchain/check/impl_lookup.cpp @@ -264,7 +264,7 @@ static auto GetWitnessIdForImpl(Context& context, SemIR::LocId loc_id, auto deduced_constraint_id = context.constant_values().GetInstId(SemIR::GetConstantValueInSpecific( context.sem_ir(), specific_id, impl.constraint_id)); - if (deduced_constraint_id == SemIR::ErrorInst::SingletonInstId) { + if (deduced_constraint_id == SemIR::ErrorInst::InstId) { return EvalImplLookupResult::MakeNone(); } @@ -329,13 +329,12 @@ static auto FindWitnessInFacet( for (auto [index, interface] : llvm::enumerate(identified.required_interfaces())) { if (interface == specific_interface) { - auto witness_id = - GetOrAddInst(context, loc_id, - SemIR::FacetAccessWitness{ - .type_id = GetSingletonType( - context, SemIR::WitnessType::SingletonInstId), - .facet_value_inst_id = facet_inst_id, - .index = SemIR::ElementIndex(index)}); + auto witness_id = GetOrAddInst( + context, loc_id, + SemIR::FacetAccessWitness{.type_id = GetSingletonType( + context, SemIR::WitnessType::InstId), + .facet_value_inst_id = facet_inst_id, + .index = SemIR::ElementIndex(index)}); return witness_id; } } @@ -356,8 +355,7 @@ static auto GetOrAddLookupImplWitness(Context& context, SemIR::LocId loc_id, auto witness_const_id = EvalOrAddInst( context, loc_id.ToImplicit(), SemIR::LookupImplWitness{ - .type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + .type_id = GetSingletonType(context, SemIR::WitnessType::InstId), .query_self_inst_id = context.constant_values().GetInstId(query_self_const_id), .query_specific_interface_id = @@ -375,8 +373,8 @@ auto LookupImplWitness(Context& context, SemIR::LocId loc_id, SemIR::ConstantId query_self_const_id, SemIR::ConstantId query_facet_type_const_id) -> SemIR::InstBlockIdOrError { - if (query_self_const_id == SemIR::ErrorInst::SingletonConstantId || - query_facet_type_const_id == SemIR::ErrorInst::SingletonConstantId) { + if (query_self_const_id == SemIR::ErrorInst::ConstantId || + query_facet_type_const_id == SemIR::ErrorInst::ConstantId) { return SemIR::InstBlockIdOrError::MakeError(); } @@ -544,7 +542,7 @@ static auto CollectCandidateImplsForQuery( // This check comes first to avoid deduction with an invalid impl. We use // an error value to indicate an error during creation of the impl, such // as a recursive impl which will cause deduction to recurse infinitely. - if (impl.witness_id == SemIR::ErrorInst::SingletonInstId) { + if (impl.witness_id == SemIR::ErrorInst::InstId) { continue; } CARBON_CHECK(impl.witness_id.has_value()); diff --git a/toolchain/check/import.cpp b/toolchain/check/import.cpp index 515a76a02618..e5c20647909d 100644 --- a/toolchain/check/import.cpp +++ b/toolchain/check/import.cpp @@ -596,7 +596,7 @@ static auto AddNamespaceFromOtherPackage(Context& context, SemIR::NameId name_id) -> SemIR::InstId { auto namespace_type_id = - GetSingletonType(context, SemIR::NamespaceType::SingletonInstId); + GetSingletonType(context, SemIR::NamespaceType::InstId); AddImportNamespaceToScopeResult result = CopySingleNameScopeFromImportIR( context, namespace_type_id, /*copied_namespaces=*/nullptr, import_ir_id, import_inst_id, import_ns.name_scope_id, parent_scope_id, name_id); diff --git a/toolchain/check/import_cpp.cpp b/toolchain/check/import_cpp.cpp index 535f31914967..bb88ac1e4f52 100644 --- a/toolchain/check/import_cpp.cpp +++ b/toolchain/check/import_cpp.cpp @@ -171,8 +171,7 @@ static auto AddNamespace(Context& context, PackageNameId cpp_package_id, } return AddImportNamespaceToScope( - context, - GetSingletonType(context, SemIR::NamespaceType::SingletonInstId), + context, GetSingletonType(context, SemIR::NamespaceType::InstId), SemIR::NameId::ForPackageName(cpp_package_id), SemIR::NameScopeId::Package, /*diagnose_duplicate_namespace=*/false, @@ -273,8 +272,8 @@ static auto MapType(Context& context, clang::QualType type) -> TypeExpr { context.ast_context().getTypeSize(type) == 32) { return MakeIntType(context, context.ints().Add(32)); } - return {.inst_id = SemIR::ErrorInst::SingletonTypeInstId, - .type_id = SemIR::ErrorInst::SingletonTypeId}; + return {.inst_id = SemIR::ErrorInst::TypeInstId, + .type_id = SemIR::ErrorInst::TypeId}; } // Returns a block id for the explicit parameters of the given function @@ -293,7 +292,7 @@ static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id, for (const clang::ParmVarDecl* param : clang_decl.parameters()) { clang::QualType param_type = param->getType().getCanonicalType(); SemIR::TypeId type_id = MapType(context, param_type).type_id; - if (type_id == SemIR::ErrorInst::SingletonTypeId) { + if (type_id == SemIR::ErrorInst::TypeId) { context.TODO(loc_id, llvm::formatv("Unsupported: parameter type: {0}", param_type.getAsString())); return SemIR::InstBlockId::None; @@ -336,10 +335,10 @@ static auto GetReturnType(Context& context, SemIR::LocId loc_id, return SemIR::InstId::None; } auto [type_inst_id, type_id] = MapType(context, ret_type); - if (type_id == SemIR::ErrorInst::SingletonTypeId) { + if (type_id == SemIR::ErrorInst::TypeId) { context.TODO(loc_id, llvm::formatv("Unsupported: return type: {0}", ret_type.getAsString())); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } SemIR::InstId return_slot_pattern_id = AddInstInNoBlock( // TODO: Fill in a location for the return type once available. @@ -363,24 +362,24 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id, -> SemIR::InstId { if (clang_decl->isVariadic()) { context.TODO(loc_id, "Unsupported: Variadic function"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (!clang_decl->isGlobal()) { context.TODO(loc_id, "Unsupported: Non-global function"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (clang_decl->getTemplatedKind() != clang::FunctionDecl::TK_NonTemplate) { context.TODO(loc_id, "Unsupported: Template function"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto param_patterns_id = MakeParamPatternsBlockId(context, loc_id, *clang_decl); if (!param_patterns_id.has_value()) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto return_slot_pattern_id = GetReturnType(context, loc_id, clang_decl); - if (SemIR::ErrorInst::SingletonInstId == return_slot_pattern_id) { - return SemIR::ErrorInst::SingletonInstId; + if (SemIR::ErrorInst::InstId == return_slot_pattern_id) { + return SemIR::ErrorInst::InstId; } auto function_decl = SemIR::FunctionDecl{ @@ -426,8 +425,8 @@ static auto ImportNamespaceDecl(Context& context, clang::NamespaceDecl* clang_decl) -> SemIR::InstId { auto result = AddImportNamespace( - context, GetSingletonType(context, SemIR::NamespaceType::SingletonInstId), - name_id, parent_scope_id, /*import_id=*/SemIR::InstId::None); + context, GetSingletonType(context, SemIR::NamespaceType::InstId), name_id, + parent_scope_id, /*import_id=*/SemIR::InstId::None); context.name_scopes() .Get(result.name_scope_id) .set_cpp_decl_context(clang_decl); @@ -440,10 +439,9 @@ static auto BuildClassDecl(Context& context, SemIR::NameScopeId parent_scope_id, SemIR::NameId name_id) -> std::tuple { // Add the class declaration. - auto class_decl = - SemIR::ClassDecl{.type_id = SemIR::TypeType::SingletonTypeId, - .class_id = SemIR::ClassId::None, - .decl_block_id = SemIR::InstBlockId::None}; + auto class_decl = SemIR::ClassDecl{.type_id = SemIR::TypeType::TypeId, + .class_id = SemIR::ClassId::None, + .decl_block_id = SemIR::InstBlockId::None}; // TODO: Consider setting a proper location. auto class_decl_id = AddPlaceholderInst(context, SemIR::LocIdAndInst::NoLoc(class_decl)); @@ -511,12 +509,12 @@ static auto ImportCXXRecordDecl(Context& context, SemIR::LocId loc_id, if (!clang_def) { context.TODO(loc_id, "Unsupported: Record declarations without a definition"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } if (clang_def->isDynamicClass()) { context.TODO(loc_id, "Unsupported: Dynamic Class"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto [class_id, class_def_id] = @@ -584,7 +582,7 @@ auto ImportNameFromCpp(Context& context, SemIR::LocId loc_id, "find a single result; LookupResultKind: {0}", lookup->getResultKind()) .str()); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } return ImportNameDecl(context, loc_id, scope_id, name_id, diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index 0a5680ce756a..0fcd535ebd5d 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -1245,7 +1245,7 @@ static auto GetLocalNameScopeId(ImportRefResolver& resolver, break; } default: { - if (const_inst_id == SemIR::ErrorInst::SingletonInstId) { + if (const_inst_id == SemIR::ErrorInst::InstId) { return SemIR::NameScopeId::None; } break; @@ -1410,7 +1410,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } auto adapted_type_inst_id = resolver.local_ir().types().GetAsTypeInstId( - AddLoadedImportRef(resolver, SemIR::TypeType::SingletonTypeId, + AddLoadedImportRef(resolver, SemIR::TypeType::TypeId, inst.adapted_type_inst_id, adapted_type_const_id)); // Create a corresponding instruction to represent the declaration. @@ -1425,7 +1425,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::ArrayType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto element_type_inst_id = GetLocalTypeInstId(resolver, inst.element_type_inst_id); auto bound_id = GetLocalConstantInstId(resolver, inst.bound_id); @@ -1434,7 +1434,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .bound_id = bound_id, .element_type_inst_id = element_type_inst_id}); } @@ -1542,7 +1542,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::AssociatedEntityType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto data = GetLocalSpecificInterfaceData(resolver, inst.GetSpecificInterface()); @@ -1553,7 +1553,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, auto specific_interface = GetLocalSpecificInterface(resolver, inst.GetSpecificInterface(), data); return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .interface_id = specific_interface.interface_id, .interface_specific_id = specific_interface.specific_id}); } @@ -1569,7 +1569,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } auto base_type_inst_id = resolver.local_ir().types().GetAsTypeInstId( - AddLoadedImportRef(resolver, SemIR::TypeType::SingletonTypeId, + AddLoadedImportRef(resolver, SemIR::TypeType::TypeId, inst.base_type_inst_id, base_type_const_id)); // Create a corresponding instruction to represent the declaration. @@ -1659,7 +1659,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::BoundMethod inst) -> ResolveResult { CARBON_CHECK(resolver.import_types().GetInstId(inst.type_id) == - SemIR::BoundMethodType::SingletonInstId); + SemIR::BoundMethodType::InstId); auto object_id = GetLocalConstantInstId(resolver, inst.object_id); auto function_decl_id = GetLocalConstantInstId(resolver, inst.function_decl_id); @@ -1669,11 +1669,10 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, - {.type_id = GetSingletonType(resolver.local_context(), - SemIR::BoundMethodType::SingletonInstId), - .object_id = object_id, - .function_decl_id = function_decl_id}); + resolver, {.type_id = GetSingletonType(resolver.local_context(), + SemIR::BoundMethodType::InstId), + .object_id = object_id, + .function_decl_id = function_decl_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::Call inst) @@ -1701,7 +1700,7 @@ static auto MakeIncompleteClass(ImportContext& context, const SemIR::Class& import_class, SemIR::SpecificId enclosing_specific_id) -> std::pair { - SemIR::ClassDecl class_decl = {.type_id = SemIR::TypeType::SingletonTypeId, + SemIR::ClassDecl class_decl = {.type_id = SemIR::TypeType::TypeId, .class_id = SemIR::ClassId::None, .decl_block_id = SemIR::InstBlockId::Empty}; auto class_decl_id = AddPlaceholderInstInNoBlock( @@ -1850,8 +1849,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, if (import_class.is_complete()) { auto complete_type_witness_id = AddLoadedImportRef( resolver, - GetSingletonType(resolver.local_context(), - SemIR::WitnessType::SingletonInstId), + GetSingletonType(resolver.local_context(), SemIR::WitnessType::InstId), import_class.complete_type_witness_id, complete_type_witness_const_id); AddClassDefinition(resolver, import_class, new_class, complete_type_witness_id, base_id, adapt_id, vtable_id); @@ -1862,7 +1860,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::ClassType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto class_const_id = GetLocalConstantId( resolver, resolver.import_classes().Get(inst.class_id).first_owning_decl_id); @@ -1884,10 +1882,10 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, class_const_inst.type_id()); auto specific_id = GetOrAddLocalSpecific(resolver, inst.specific_id, specific_data); - return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, - .class_id = generic_class_type.class_id, - .specific_id = specific_id}); + return ResolveAs(resolver, + {.type_id = SemIR::TypeType::TypeId, + .class_id = generic_class_type.class_id, + .specific_id = specific_id}); } } @@ -1895,29 +1893,27 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::CompleteTypeWitness inst) -> ResolveResult { CARBON_CHECK(resolver.import_types().GetInstId(inst.type_id) == - SemIR::WitnessType::SingletonInstId); + SemIR::WitnessType::InstId); auto object_repr_type_inst_id = GetLocalTypeInstId(resolver, inst.object_repr_type_inst_id); if (resolver.HasNewWork()) { return ResolveResult::Retry(); } return ResolveAs( - resolver, - {.type_id = GetSingletonType(resolver.local_context(), - SemIR::WitnessType::SingletonInstId), - .object_repr_type_inst_id = object_repr_type_inst_id}); + resolver, {.type_id = GetSingletonType(resolver.local_context(), + SemIR::WitnessType::InstId), + .object_repr_type_inst_id = object_repr_type_inst_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::ConstType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto inner_id = GetLocalTypeInstId(resolver, inst.inner_id); if (resolver.HasNewWork()) { return ResolveResult::Retry(); } return ResolveAs( - resolver, - {.type_id = SemIR::TypeType::SingletonTypeId, .inner_id = inner_id}); + resolver, {.type_id = SemIR::TypeType::TypeId, .inner_id = inner_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, @@ -2056,7 +2052,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::FunctionType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto fn_val_id = GetLocalConstantInstId( resolver, resolver.import_functions().Get(inst.function_id).first_decl_id()); @@ -2066,7 +2062,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } auto fn_type_id = resolver.local_insts().Get(fn_val_id).type_id(); return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .function_id = resolver.local_types() .GetAs(fn_type_id) .function_id, @@ -2077,7 +2073,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::FunctionTypeWithSelfType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto interface_function_type_id = GetLocalTypeInstId(resolver, inst.interface_function_type_id); auto self_id = GetLocalConstantInstId(resolver, inst.self_id); @@ -2086,14 +2082,14 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .interface_function_type_id = interface_function_type_id, .self_id = self_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::GenericClassType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto class_val_id = GetLocalConstantInstId( resolver, resolver.import_classes().Get(inst.class_id).first_owning_decl_id); @@ -2110,7 +2106,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::GenericInterfaceType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto interface_val_id = GetLocalConstantInstId( resolver, resolver.import_interfaces().Get(inst.interface_id).first_owning_decl_id); @@ -2236,10 +2232,10 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, // Create instructions for self and constraint to hold the symbolic constant // value for a generic impl. new_impl.self_id = resolver.local_ir().types().GetAsTypeInstId( - AddLoadedImportRef(resolver, SemIR::TypeType::SingletonTypeId, - import_impl.self_id, self_const_id)); + AddLoadedImportRef(resolver, SemIR::TypeType::TypeId, import_impl.self_id, + self_const_id)); new_impl.constraint_id = resolver.local_ir().types().GetAsTypeInstId( - AddLoadedImportRef(resolver, SemIR::TypeType::SingletonTypeId, + AddLoadedImportRef(resolver, SemIR::TypeType::TypeId, import_impl.constraint_id, constraint_const_id)); new_impl.interface = GetLocalSpecificInterface( resolver, import_impl.interface, specific_interface_data); @@ -2282,7 +2278,7 @@ static auto MakeInterfaceDecl(ImportContext& context, SemIR::SpecificId enclosing_specific_id) -> std::pair { SemIR::InterfaceDecl interface_decl = { - .type_id = SemIR::TypeType::SingletonTypeId, + .type_id = SemIR::TypeType::TypeId, .interface_id = SemIR::InterfaceId::None, .decl_block_id = SemIR::InstBlockId::Empty}; auto interface_decl_id = AddPlaceholderInstInNoBlock( @@ -2429,7 +2425,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .facet_value_inst_id = facet_value_inst_id}); } @@ -2443,16 +2439,15 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, - {.type_id = GetSingletonType(resolver.local_context(), - SemIR::WitnessType::SingletonInstId), - .facet_value_inst_id = facet_value_inst_id, - .index = inst.index}); + resolver, {.type_id = GetSingletonType(resolver.local_context(), + SemIR::WitnessType::InstId), + .facet_value_inst_id = facet_value_inst_id, + .index = inst.index}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::FacetType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); const SemIR::FacetTypeInfo& import_facet_type_info = resolver.import_facet_types().Get(inst.facet_type_id); @@ -2501,8 +2496,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::FacetTypeId facet_type_id = resolver.local_facet_types().Add(std::move(local_facet_type_info)); return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, - .facet_type_id = facet_type_id}); + resolver, + {.type_id = SemIR::TypeType::TypeId, .facet_type_id = facet_type_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, @@ -2527,7 +2522,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::LookupImplWitness inst) -> ResolveResult { CARBON_CHECK(resolver.import_types().GetInstId(inst.type_id) == - SemIR::WitnessType::SingletonInstId); + SemIR::WitnessType::InstId); auto query_self_inst_id = GetLocalConstantInstId(resolver, inst.query_self_inst_id); @@ -2547,17 +2542,16 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, auto query_specific_interface_id = resolver.local_specific_interfaces().Add(specific_interface); return ResolveAs( - resolver, - {.type_id = GetSingletonType(resolver.local_context(), - SemIR::WitnessType::SingletonInstId), - .query_self_inst_id = query_self_inst_id, - .query_specific_interface_id = query_specific_interface_id}); + resolver, {.type_id = GetSingletonType(resolver.local_context(), + SemIR::WitnessType::InstId), + .query_self_inst_id = query_self_inst_id, + .query_specific_interface_id = query_specific_interface_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::ImplWitness inst) -> ResolveResult { CARBON_CHECK(resolver.import_types().GetInstId(inst.type_id) == - SemIR::WitnessType::SingletonInstId); + SemIR::WitnessType::InstId); auto specific_data = GetLocalSpecificData(resolver, inst.specific_id); auto witness_table_id = @@ -2569,11 +2563,10 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, auto specific_id = GetOrAddLocalSpecific(resolver, inst.specific_id, specific_data); return ResolveAs( - resolver, - {.type_id = GetSingletonType(resolver.local_context(), - SemIR::WitnessType::SingletonInstId), - .witness_table_id = witness_table_id, - .specific_id = specific_id}); + resolver, {.type_id = GetSingletonType(resolver.local_context(), + SemIR::WitnessType::InstId), + .witness_table_id = witness_table_id, + .specific_id = specific_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, @@ -2634,14 +2627,14 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::IntType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto bit_width_id = GetLocalConstantInstId(resolver, inst.bit_width_id); if (resolver.HasNewWork()) { return ResolveResult::Retry(); } return ResolveAs(resolver, - {.type_id = SemIR::TypeType::SingletonTypeId, + {.type_id = SemIR::TypeType::TypeId, .int_kind = inst.int_kind, .bit_width_id = bit_width_id}); } @@ -2662,8 +2655,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, return ResolveResult::Retry(); } - auto namespace_type_id = GetSingletonType( - resolver.local_context(), SemIR::NamespaceType::SingletonInstId); + auto namespace_type_id = + GetSingletonType(resolver.local_context(), SemIR::NamespaceType::InstId); auto namespace_decl = SemIR::Namespace{.type_id = namespace_type_id, .name_scope_id = SemIR::NameScopeId::None, @@ -2689,22 +2682,21 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::PointerType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto pointee_id = GetLocalTypeInstId(resolver, inst.pointee_id); if (resolver.HasNewWork()) { return ResolveResult::Retry(); } return ResolveAs( - resolver, - {.type_id = SemIR::TypeType::SingletonTypeId, .pointee_id = pointee_id}); + resolver, {.type_id = SemIR::TypeType::TypeId, .pointee_id = pointee_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::RequireCompleteType inst) -> ResolveResult { CARBON_CHECK(resolver.import_types().GetInstId(inst.type_id) == - SemIR::WitnessType::SingletonInstId); + SemIR::WitnessType::InstId); auto complete_type_inst_id = GetLocalTypeInstId(resolver, inst.complete_type_inst_id); @@ -2713,10 +2705,9 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, - {.type_id = GetSingletonType(resolver.local_context(), - SemIR::WitnessType::SingletonInstId), - .complete_type_inst_id = complete_type_inst_id}); + resolver, {.type_id = GetSingletonType(resolver.local_context(), + SemIR::WitnessType::InstId), + .complete_type_inst_id = complete_type_inst_id}); } static auto TryResolveTypedInst(ImportRefResolver& resolver, @@ -2747,7 +2738,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } auto type_id = GetSingletonType(resolver.local_context(), - SemIR::SpecificFunctionType::SingletonInstId); + SemIR::SpecificFunctionType::InstId); auto specific_id = GetOrAddLocalSpecific(resolver, inst.specific_id, specific_data); return ResolveAs( @@ -2757,7 +2748,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::StructType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto orig_fields = resolver.import_struct_type_fields().Get(inst.fields_id); llvm::SmallVector field_type_inst_ids; field_type_inst_ids.reserve(orig_fields.size()); @@ -2780,7 +2771,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .fields_id = resolver.local_struct_type_fields().AddCanonical( new_fields)}); } @@ -2803,7 +2794,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::TupleType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto orig_type_inst_ids = resolver.import_inst_blocks().Get(inst.type_elements_id); @@ -2820,7 +2811,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .type_elements_id = GetLocalCanonicalInstBlockId( resolver, inst.type_elements_id, type_inst_ids)}); } @@ -2844,7 +2835,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::UnboundElementType inst) -> ResolveResult { - CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId); + CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId); auto class_const_inst_id = GetLocalTypeInstId(resolver, inst.class_type_inst_id); auto elem_const_inst_id = @@ -2854,7 +2845,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, } return ResolveAs( - resolver, {.type_id = SemIR::TypeType::SingletonTypeId, + resolver, {.type_id = SemIR::TypeType::TypeId, .class_type_inst_id = class_const_inst_id, .element_type_inst_id = elem_const_inst_id}); } diff --git a/toolchain/check/interface.cpp b/toolchain/check/interface.cpp index ea8519c1e736..49663ae9a2fa 100644 --- a/toolchain/check/interface.cpp +++ b/toolchain/check/interface.cpp @@ -22,7 +22,7 @@ auto BuildAssociatedEntity(Context& context, SemIR::InterfaceId interface_id, // This should only happen if the interface is erroneously defined more than // once. // TODO: Find a way to CHECK this. - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // This associated entity is being declared as a member of the self specific diff --git a/toolchain/check/literal.cpp b/toolchain/check/literal.cpp index afc928abd4be..c107c26a7b19 100644 --- a/toolchain/check/literal.cpp +++ b/toolchain/check/literal.cpp @@ -16,8 +16,7 @@ auto MakeIntLiteral(Context& context, Parse::NodeId node_id, IntId int_id) -> SemIR::InstId { return AddInst( context, node_id, - {.type_id = - GetSingletonType(context, SemIR::IntLiteralType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::IntLiteralType::InstId), .int_id = int_id}); } diff --git a/toolchain/check/member_access.cpp b/toolchain/check/member_access.cpp index 9c1c4187bc8d..51b6dfc4995e 100644 --- a/toolchain/check/member_access.cpp +++ b/toolchain/check/member_access.cpp @@ -150,17 +150,17 @@ static auto AccessMemberOfImplWitness(Context& context, SemIR::LocId loc_id, -> SemIR::InstId { auto member_value_id = context.constant_values().GetConstantInstId(member_id); if (!member_value_id.has_value()) { - if (member_value_id != SemIR::ErrorInst::SingletonInstId) { + if (member_value_id != SemIR::ErrorInst::InstId) { context.TODO(member_id, "non-constant associated entity"); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto assoc_entity = context.insts().TryGetAs(member_value_id); if (!assoc_entity) { context.TODO(member_id, "unexpected value for associated entity"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // Substitute the interface specific and `Self` type into the type of the @@ -188,7 +188,7 @@ static auto GetWitnessFromSingleImplLookupResult( -> SemIR::InstId { auto witness_id = SemIR::InstId::None; if (lookup_result.has_error_value()) { - witness_id = SemIR::ErrorInst::SingletonInstId; + witness_id = SemIR::ErrorInst::InstId; } else { auto witnesses = context.inst_blocks().Get(lookup_result.inst_block_id()); CARBON_CHECK(witnesses.size() == 1); @@ -228,7 +228,7 @@ static auto PerformImplLookup( context.emitter().Emit(loc_id, MissingImplInMemberAccess, interface_type_id, self_type_id); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto witness_id = @@ -256,7 +256,7 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id, context, loc_id, name_id, lookup_scopes, required, access_info); if (!result.scope_result.is_found()) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // TODO: This duplicates the work that HandleNameAsExpr does. Factor this out. @@ -358,13 +358,13 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id, llvm::enumerate(identified.required_interfaces())) { // Get the witness that `T` implements `base_type_id`. if (base_interface == assoc_interface) { - witness_inst_id = GetOrAddInst( - context, loc_id, - SemIR::FacetAccessWitness{ - .type_id = GetSingletonType( - context, SemIR::WitnessType::SingletonInstId), - .facet_value_inst_id = base_id, - .index = SemIR::ElementIndex(index)}); + witness_inst_id = + GetOrAddInst(context, loc_id, + SemIR::FacetAccessWitness{ + .type_id = GetSingletonType( + context, SemIR::WitnessType::InstId), + .facet_value_inst_id = base_id, + .index = SemIR::ElementIndex(index)}); break; } } @@ -375,7 +375,7 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id, context.TODO(member_id, "associated entity not found in facet type, need to do " "impl lookup"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } member_id = AccessMemberOfImplWitness( @@ -417,8 +417,7 @@ static auto PerformInstanceBinding(Context& context, SemIR::LocId loc_id, return GetOrAddInst( context, loc_id, - {.type_id = - GetSingletonType(context, SemIR::BoundMethodType::SingletonInstId), + {.type_id = GetSingletonType(context, SemIR::BoundMethodType::InstId), .object_id = base_id, .function_decl_id = member_id}); } @@ -493,13 +492,13 @@ auto PerformMemberAccess(Context& context, SemIR::LocId loc_id, if (required) { return HandleAction( context, loc_id, - {.type_id = SemIR::InstType::SingletonTypeId, + {.type_id = SemIR::InstType::TypeId, .base_id = base_id, .name_id = name_id}); } else { return HandleAction( context, loc_id, - {.type_id = SemIR::InstType::SingletonTypeId, + {.type_id = SemIR::InstType::TypeId, .base_id = base_id, .name_id = name_id}); } @@ -532,7 +531,7 @@ static auto PerformActionHelper(Context& context, SemIR::LocId loc_id, return context.emitter().Build(base_id, IncompleteTypeInMemberAccess, base_id); })) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // Materialize a temporary for the base expression if necessary. @@ -567,19 +566,19 @@ static auto PerformActionHelper(Context& context, SemIR::LocId loc_id, SemIR::NameId); context.emitter().Emit(loc_id, QualifiedExprNameNotFound, base_id, name_id); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } else { return SemIR::InstId::None; } } - if (base_type_id != SemIR::ErrorInst::SingletonTypeId) { + if (base_type_id != SemIR::ErrorInst::TypeId) { CARBON_DIAGNOSTIC(QualifiedExprUnsupported, Error, "type {0} does not support qualified expressions", TypeOfInstId); context.emitter().Emit(loc_id, QualifiedExprUnsupported, base_id); } - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // Perform lookup into the base type. @@ -625,32 +624,30 @@ static auto GetAssociatedValueImpl(Context& context, SemIR::LocId loc_id, GetInterfaceType(context, interface.interface_id, interface.specific_id); auto facet_inst_id = ConvertToValueOfType(context, loc_id, base_id, interface_type_id); - if (facet_inst_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (facet_inst_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } // That facet value has both the self type we need below and the witness // we are going to use to look up the value of the associated member. auto self_type_const_id = TryEvalInst( - context, - SemIR::FacetAccessType{.type_id = SemIR::TypeType::SingletonTypeId, - .facet_value_inst_id = facet_inst_id}); + context, SemIR::FacetAccessType{.type_id = SemIR::TypeType::TypeId, + .facet_value_inst_id = facet_inst_id}); // TODO: We should be able to lookup constant associated values from runtime // facet values by using their FacetType only, but we assume constant values // for impl lookup at the moment. if (!self_type_const_id.is_constant()) { context.TODO(loc_id, "associated value lookup on runtime facet value"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto self_type_id = context.types().GetTypeIdForTypeConstantId(self_type_const_id); - auto witness_id = - GetOrAddInst(context, loc_id, - SemIR::FacetAccessWitness{ - .type_id = GetSingletonType( - context, SemIR::WitnessType::SingletonInstId), - .facet_value_inst_id = facet_inst_id, - // There's only one interface in this facet type. - .index = SemIR::ElementIndex(0)}); + auto witness_id = GetOrAddInst( + context, loc_id, + SemIR::FacetAccessWitness{ + .type_id = GetSingletonType(context, SemIR::WitnessType::InstId), + .facet_value_inst_id = facet_inst_id, + // There's only one interface in this facet type. + .index = SemIR::ElementIndex(0)}); // Before we can access the element of the witness, we need to figure out // the type of that element. It depends on the self type and the specific // interface. @@ -709,7 +706,7 @@ auto PerformCompoundMemberAccess(Context& context, SemIR::LocId loc_id, // > evaluation is required to succeed [...] if (!value_inst_id.has_value()) { context.TODO(loc_id, "Non-constant associated entity value"); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto assoc_entity = context.insts().GetAs(value_inst_id); @@ -743,7 +740,7 @@ auto PerformCompoundMemberAccess(Context& context, SemIR::LocId loc_id, // If we didn't perform impl lookup or instance binding, that's an error // because the base expression is not used for anything. if (member_id == member_expr_id && - member.type_id() != SemIR::ErrorInst::SingletonTypeId) { + member.type_id() != SemIR::ErrorInst::TypeId) { CARBON_DIAGNOSTIC(CompoundMemberAccessDoesNotUseBase, Error, "member name of type {0} in compound member access is " "not an instance member or an interface member", @@ -768,7 +765,7 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id, "tuples can be indexed that way", TypeOfInstId); context.emitter().Emit(loc_id, TupleIndexOnANonTupleType, tuple_inst_id); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto diag_non_constant_index = [&] { @@ -776,7 +773,7 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id, CARBON_DIAGNOSTIC(TupleIndexNotConstant, Error, "tuple index must be a constant"); context.emitter().Emit(loc_id, TupleIndexNotConstant); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; }; // Diagnose a non-constant index prior to conversion to IntLiteral, because // the conversion will fail if the index is not constant. @@ -784,14 +781,14 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id, return diag_non_constant_index(); } - SemIR::TypeId element_type_id = SemIR::ErrorInst::SingletonTypeId; + SemIR::TypeId element_type_id = SemIR::ErrorInst::TypeId; auto index_node_id = context.insts().GetLocId(index_inst_id); index_inst_id = ConvertToValueOfType( context, index_node_id, index_inst_id, - GetSingletonType(context, SemIR::IntLiteralType::SingletonInstId)); + GetSingletonType(context, SemIR::IntLiteralType::InstId)); auto index_const_id = context.constant_values().Get(index_inst_id); - if (index_const_id == SemIR::ErrorInst::SingletonConstantId) { - return SemIR::ErrorInst::SingletonInstId; + if (index_const_id == SemIR::ErrorInst::ConstantId) { + return SemIR::ErrorInst::InstId; } else if (!index_const_id.is_concrete()) { return diag_non_constant_index(); } @@ -802,7 +799,7 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id, std::optional index_val = ValidateTupleIndex( context, loc_id, tuple_inst_id, index_literal, type_block.size()); if (!index_val) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // TODO: Handle the case when `index_val->getZExtValue()` has too many bits. diff --git a/toolchain/check/merge.cpp b/toolchain/check/merge.cpp index 4a27abf8802a..6d2f84392076 100644 --- a/toolchain/check/merge.cpp +++ b/toolchain/check/merge.cpp @@ -190,7 +190,7 @@ static auto EntityHasParamError(Context& context, const DeclParams& info) param_patterns_id != SemIR::InstBlockId::Empty) { for (auto param_id : context.inst_blocks().Get(param_patterns_id)) { if (context.insts().Get(param_id).type_id() == - SemIR::ErrorInst::SingletonTypeId) { + SemIR::ErrorInst::TypeId) { return true; } } diff --git a/toolchain/check/name_lookup.cpp b/toolchain/check/name_lookup.cpp index b3e015cbfdfb..620f1aa43e0b 100644 --- a/toolchain/check/name_lookup.cpp +++ b/toolchain/check/name_lookup.cpp @@ -334,7 +334,7 @@ auto AppendLookupScopesForConstant(Context& context, SemIR::LocId loc_id, } return true; } - if (base_const_id == SemIR::ErrorInst::SingletonConstantId) { + if (base_const_id == SemIR::ErrorInst::ConstantId) { // Lookup into this scope should fail without producing an error. scopes->push_back(LookupScope{.name_scope_id = SemIR::NameScopeId::None, .specific_id = SemIR::SpecificId::None}); @@ -523,7 +523,7 @@ auto LookupNameInCore(Context& context, SemIR::LocId loc_id, llvm::StringRef name) -> SemIR::InstId { auto core_package_id = GetCorePackage(context, loc_id, name); if (!core_package_id.has_value()) { - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } auto name_id = SemIR::NameId::ForIdentifier(context.identifiers().Add(name)); @@ -536,7 +536,7 @@ auto LookupNameInCore(Context& context, SemIR::LocId loc_id, "name `Core.{0}` implicitly referenced here, but not found", SemIR::NameId); context.emitter().Emit(loc_id, CoreNameNotFound, name_id); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } // Look through import_refs and aliases. diff --git a/toolchain/check/operator.cpp b/toolchain/check/operator.cpp index fb15f5f2eeb2..f974dd1f0a12 100644 --- a/toolchain/check/operator.cpp +++ b/toolchain/check/operator.cpp @@ -40,8 +40,8 @@ auto BuildUnaryOperator(Context& context, SemIR::LocId loc_id, Operator op, // Form `operand.(Op)`. auto bound_op_id = PerformCompoundMemberAccess(context, loc_id, operand_id, op_fn, missing_impl_diagnoser); - if (bound_op_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (bound_op_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } // Form `bound_op()`. @@ -58,8 +58,8 @@ auto BuildBinaryOperator(Context& context, SemIR::LocId loc_id, Operator op, // Form `lhs.(Op)`. auto bound_op_id = PerformCompoundMemberAccess(context, loc_id, lhs_id, op_fn, missing_impl_diagnoser); - if (bound_op_id == SemIR::ErrorInst::SingletonInstId) { - return SemIR::ErrorInst::SingletonInstId; + if (bound_op_id == SemIR::ErrorInst::InstId) { + return SemIR::ErrorInst::InstId; } // Form `bound_op(rhs)`. diff --git a/toolchain/check/pattern_match.cpp b/toolchain/check/pattern_match.cpp index 2194028f0757..54040e54b808 100644 --- a/toolchain/check/pattern_match.cpp +++ b/toolchain/check/pattern_match.cpp @@ -182,7 +182,7 @@ static auto InsertHere(Context& context, SemIR::ExprRegionId region_id) context.TODO(loc_id, "Control flow expressions are currently only supported inside " "functions."); - return SemIR::ErrorInst::SingletonInstId; + return SemIR::ErrorInst::InstId; } AddInst(context, SemIR::LocIdAndInst::NoLoc( {.target_id = region.block_ids.front()})); @@ -291,8 +291,8 @@ auto MatchContext::DoEmitPatternMatch(Context& context, "Parameters out of order; expecting {0} but got {1}", results_.size(), param_pattern.index.index); CARBON_CHECK(entry.scrutinee_id.has_value()); - if (entry.scrutinee_id == SemIR::ErrorInst::SingletonInstId) { - results_.push_back(SemIR::ErrorInst::SingletonInstId); + if (entry.scrutinee_id == SemIR::ErrorInst::InstId) { + results_.push_back(SemIR::ErrorInst::InstId); } else { results_.push_back(ConvertToValueOfType( context, context.insts().GetLocId(entry.scrutinee_id), @@ -479,7 +479,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context, SemIR::TuplePattern tuple_pattern, SemIR::InstId pattern_inst_id, WorkItem entry) -> void { - if (tuple_pattern.type_id == SemIR::ErrorInst::SingletonTypeId) { + if (tuple_pattern.type_id == SemIR::ErrorInst::TypeId) { return; } auto subpattern_ids = context.inst_blocks().Get(tuple_pattern.elements_id); @@ -544,7 +544,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context, auto MatchContext::EmitPatternMatch(Context& context, MatchContext::WorkItem entry) -> void { - if (entry.pattern_id == SemIR::ErrorInst::SingletonInstId) { + if (entry.pattern_id == SemIR::ErrorInst::InstId) { return; } Diagnostics::AnnotationScope annotate_diagnostics( diff --git a/toolchain/check/pointer_dereference.cpp b/toolchain/check/pointer_dereference.cpp index d5c5c4acb2ab..4c2ff82d64a8 100644 --- a/toolchain/check/pointer_dereference.cpp +++ b/toolchain/check/pointer_dereference.cpp @@ -26,12 +26,12 @@ auto PerformPointerDereference( base_id = ConvertToValueExpr(context, base_id); auto type_id = context.types().GetUnqualifiedType( context.insts().Get(base_id).type_id()); - auto result_type_id = SemIR::ErrorInst::SingletonTypeId; + auto result_type_id = SemIR::ErrorInst::TypeId; if (auto pointer_type = context.types().TryGetAs(type_id)) { result_type_id = context.types().GetTypeIdForTypeInstId(pointer_type->pointee_id); - } else if (type_id != SemIR::ErrorInst::SingletonTypeId) { + } else if (type_id != SemIR::ErrorInst::TypeId) { diagnose_not_pointer(type_id); } return AddInst( diff --git a/toolchain/check/return.cpp b/toolchain/check/return.cpp index f96e5a150f1c..128b9486f094 100644 --- a/toolchain/check/return.cpp +++ b/toolchain/check/return.cpp @@ -145,7 +145,7 @@ auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId node_id, auto diag = context.emitter().Build(node_id, ReturnStatementDisallowExpr); NoteNoReturnTypeProvided(diag, function); diag.Emit(); - expr_id = SemIR::ErrorInst::SingletonInstId; + expr_id = SemIR::ErrorInst::InstId; } else if (returned_var_id.has_value()) { CARBON_DIAGNOSTIC( ReturnExprWithReturnedVar, Error, @@ -153,11 +153,11 @@ auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId node_id, auto diag = context.emitter().Build(node_id, ReturnExprWithReturnedVar); NoteReturnedVar(diag, returned_var_id); diag.Emit(); - expr_id = SemIR::ErrorInst::SingletonInstId; + expr_id = SemIR::ErrorInst::InstId; } else if (!return_info.is_valid()) { // We already diagnosed that the return type is invalid. Don't try to // convert to it. - expr_id = SemIR::ErrorInst::SingletonInstId; + expr_id = SemIR::ErrorInst::InstId; } else if (return_info.has_return_slot()) { return_slot_id = GetCurrentReturnSlot(context); CARBON_CHECK(return_slot_id.has_value()); @@ -181,7 +181,7 @@ auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id) CARBON_DIAGNOSTIC(ReturnVarWithNoReturnedVar, Error, "`return var;` with no `returned var` in scope"); context.emitter().Emit(node_id, ReturnVarWithNoReturnedVar); - returned_var_id = SemIR::ErrorInst::SingletonInstId; + returned_var_id = SemIR::ErrorInst::InstId; } auto return_slot_id = GetCurrentReturnSlot(context); diff --git a/toolchain/check/scope_stack.cpp b/toolchain/check/scope_stack.cpp index f49f78e38beb..5b5903f56cc7 100644 --- a/toolchain/check/scope_stack.cpp +++ b/toolchain/check/scope_stack.cpp @@ -138,7 +138,7 @@ auto ScopeStack::LookupInLexicalScopes(SemIR::NameId name_id) // If we have no lexical results, check all non-lexical scopes. if (lexical_results.empty()) { - return {LexicalLookupHasLoadError() ? SemIR::ErrorInst::SingletonInstId + return {LexicalLookupHasLoadError() ? SemIR::ErrorInst::InstId : SemIR::InstId::None, non_lexical_scope_stack_}; } diff --git a/toolchain/check/type.cpp b/toolchain/check/type.cpp index ceb8d88d97b8..2b6e070bcd04 100644 --- a/toolchain/check/type.cpp +++ b/toolchain/check/type.cpp @@ -72,7 +72,7 @@ auto ValidateFloatType(Context& context, SemIR::LocId loc_id, template static auto GetTypeImpl(Context& context, EachArgT... each_arg) -> SemIR::TypeId { - InstT inst = {SemIR::TypeType::SingletonTypeId, each_arg...}; + InstT inst = {SemIR::TypeType::TypeId, each_arg...}; return context.types().GetTypeIdForTypeConstantId(TryEvalInst(context, inst)); } diff --git a/toolchain/check/type_completion.cpp b/toolchain/check/type_completion.cpp index b16336528b50..af1cfddaf106 100644 --- a/toolchain/check/type_completion.cpp +++ b/toolchain/check/type_completion.cpp @@ -227,7 +227,7 @@ auto TypeCompleter::ProcessStep() -> bool { } // For a pointer representation, the pointee also needs to be complete. if (info.value_repr.kind == SemIR::ValueRepr::Pointer) { - if (info.value_repr.type_id == SemIR::ErrorInst::SingletonTypeId) { + if (info.value_repr.type_id == SemIR::ErrorInst::TypeId) { break; } auto pointee_type_id = @@ -561,8 +561,7 @@ auto RequireCompleteType(Context& context, SemIR::TypeId type_id, AddInstInNoBlock( context, loc_id, SemIR::RequireCompleteType{ - .type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId), + .type_id = GetSingletonType(context, SemIR::WitnessType::InstId), .complete_type_inst_id = context.types().GetInstId(type_id)}); } @@ -645,7 +644,7 @@ auto AsCompleteType(Context& context, SemIR::TypeId type_id, -> SemIR::TypeId { return RequireCompleteType(context, type_id, loc_id, diagnoser) ? type_id - : SemIR::ErrorInst::SingletonTypeId; + : SemIR::ErrorInst::TypeId; } // Returns the type `type_id` if it is a concrete type, or produces an @@ -658,7 +657,7 @@ auto AsConcreteType(Context& context, SemIR::TypeId type_id, return RequireConcreteType(context, type_id, loc_id, diagnoser, abstract_diagnoser) ? type_id - : SemIR::ErrorInst::SingletonTypeId; + : SemIR::ErrorInst::TypeId; } auto NoteIncompleteClass(Context& context, SemIR::ClassId class_id, diff --git a/toolchain/check/type_structure.cpp b/toolchain/check/type_structure.cpp index b1fd6c81c8eb..ae12604f0af0 100644 --- a/toolchain/check/type_structure.cpp +++ b/toolchain/check/type_structure.cpp @@ -354,7 +354,7 @@ class TypeStructureBuilder { return SymbolicType(); } // Non-type values are concrete, only types are symbolic. - if (type_id_of_inst_id != SemIR::TypeType::SingletonTypeId) { + if (type_id_of_inst_id != SemIR::TypeType::TypeId) { return SemIR::TypeId::None; } return context_->types().GetTypeIdForTypeInstId(inst_id); diff --git a/toolchain/docs/adding_features.md b/toolchain/docs/adding_features.md index 787f4e94bf1c..79a4b3ceff61 100644 --- a/toolchain/docs/adding_features.md +++ b/toolchain/docs/adding_features.md @@ -282,12 +282,12 @@ If the resulting SemIR needs a new instruction: - Set `.is_type = InstIsType::Always` in its `Kind` definition. - When constructing instructions of this kind, pass - `SemIR::TypeType::SingletonTypeId` in as the value of the `type_id` - field, as in: + `SemIR::TypeType::TypeId` in as the value of the `type_id` field, as + in: ``` SemIR::InstId inst_id = AddInst(context, - node_id, {.type_id = SemIR::TypeType::SingletonTypeId, ...}); + node_id, {.type_id = SemIR::TypeType::TypeId, ...}); ``` - Although most instructions have distinct types represented by @@ -299,11 +299,11 @@ If the resulting SemIR needs a new instruction: constructed as a special-case in [`File` construction](/toolchain/sem_ir/file.cpp). To get a type id for one of these builtin types, use something like - `GetSingletonType(context,SemIR::WitnessType::SingletonInstId)`, as in: + `GetSingletonType(context,SemIR::WitnessType::InstId)`, as in: ``` SemIR::TypeId witness_type_id = - GetSingletonType(context, SemIR::WitnessType::SingletonInstId); + GetSingletonType(context, SemIR::WitnessType::InstId); SemIR::InstId inst_id = AddInst( context, node_id, {.type_id = witness_type_id, ...}); ``` diff --git a/toolchain/lower/handle.cpp b/toolchain/lower/handle.cpp index b21cc8434800..6906e99a85e2 100644 --- a/toolchain/lower/handle.cpp +++ b/toolchain/lower/handle.cpp @@ -36,7 +36,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id, llvm::Value* index; if (context.sem_ir().types().GetInstId( context.sem_ir().insts().Get(inst.index_id).type_id()) == - SemIR::IntLiteralType::SingletonInstId) { + SemIR::IntLiteralType::InstId) { auto value = context.sem_ir().insts().GetAs( context.sem_ir().constant_values().GetConstantInstId(inst.index_id)); index = llvm::ConstantInt::get(context.llvm_context(), @@ -73,7 +73,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId /*inst_id*/, auto HandleInst(FunctionContext& context, SemIR::InstId inst_id, SemIR::BindAlias inst) -> void { auto type_inst_id = context.sem_ir().types().GetInstId(inst.type_id); - if (type_inst_id == SemIR::NamespaceType::SingletonInstId) { + if (type_inst_id == SemIR::NamespaceType::InstId) { return; } @@ -83,7 +83,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id, auto HandleInst(FunctionContext& context, SemIR::InstId inst_id, SemIR::ExportDecl inst) -> void { auto type_inst_id = context.sem_ir().types().GetInstId(inst.type_id); - if (type_inst_id == SemIR::NamespaceType::SingletonInstId) { + if (type_inst_id == SemIR::NamespaceType::InstId) { return; } @@ -191,7 +191,7 @@ auto HandleInst(FunctionContext& /*context*/, SemIR::InstId /*inst_id*/, auto HandleInst(FunctionContext& context, SemIR::InstId inst_id, SemIR::NameRef inst) -> void { auto type_inst_id = context.sem_ir().types().GetInstId(inst.type_id); - if (type_inst_id == SemIR::NamespaceType::SingletonInstId) { + if (type_inst_id == SemIR::NamespaceType::InstId) { return; } diff --git a/toolchain/sem_ir/builtin_function_kind.cpp b/toolchain/sem_ir/builtin_function_kind.cpp index d40d95d34f65..93c3056d1b9a 100644 --- a/toolchain/sem_ir/builtin_function_kind.cpp +++ b/toolchain/sem_ir/builtin_function_kind.cpp @@ -77,7 +77,7 @@ struct NoReturn { }; // Constraint that a type is `bool`. -using Bool = BuiltinType; +using Bool = BuiltinType; // Constraint that requires the type to be a sized integer type. struct AnySizedInt { @@ -92,8 +92,7 @@ struct AnyInt { static auto Check(const File& sem_ir, ValidateState& state, TypeId type_id) -> bool { return AnySizedInt::Check(sem_ir, state, type_id) || - BuiltinType::Check(sem_ir, state, - type_id); + BuiltinType::Check(sem_ir, state, type_id); } }; @@ -101,8 +100,7 @@ struct AnyInt { struct AnyFloat { static auto Check(const File& sem_ir, ValidateState& state, TypeId type_id) -> bool { - if (BuiltinType::Check(sem_ir, state, - type_id)) { + if (BuiltinType::Check(sem_ir, state, type_id)) { return true; } return sem_ir.types().Is(type_id); @@ -110,18 +108,17 @@ struct AnyFloat { }; // Constraint that requires the type to be the type type. -using Type = BuiltinType; +using Type = BuiltinType; // Constraint that requires the type to be a type value, whose type is type // type. Also accepts symbolic constant value types. struct AnyType { static auto Check(const File& sem_ir, ValidateState& state, TypeId type_id) -> bool { - if (BuiltinType::Check(sem_ir, state, type_id)) { + if (BuiltinType::Check(sem_ir, state, type_id)) { return true; } - return sem_ir.types().GetAsInst(type_id).type_id() == - TypeType::SingletonTypeId; + return sem_ir.types().GetAsInst(type_id).type_id() == TypeType::TypeId; } }; diff --git a/toolchain/sem_ir/class.cpp b/toolchain/sem_ir/class.cpp index 1bb31427fc56..aed7198731d8 100644 --- a/toolchain/sem_ir/class.cpp +++ b/toolchain/sem_ir/class.cpp @@ -16,8 +16,8 @@ static auto GetFoundationType(const File& file, SpecificId specific_id, if (!inst_id.has_value()) { return TypeId::None; } - if (inst_id == SemIR::ErrorInst::SingletonInstId) { - return ErrorInst::SingletonTypeId; + if (inst_id == SemIR::ErrorInst::InstId) { + return ErrorInst::TypeId; } return TypeId::ForTypeConstant(GetConstantValueInSpecific( file, specific_id, @@ -41,8 +41,8 @@ auto Class::GetObjectRepr(const File& file, SpecificId specific_id) const } auto witness_id = GetConstantValueInSpecific(file, specific_id, complete_type_witness_id); - if (witness_id == ErrorInst::SingletonConstantId) { - return ErrorInst::SingletonTypeId; + if (witness_id == ErrorInst::ConstantId) { + return ErrorInst::TypeId; } return file.types().GetTypeIdForTypeInstId( file.insts() diff --git a/toolchain/sem_ir/file.cpp b/toolchain/sem_ir/file.cpp index 923e2c0c1285..1d57897bde61 100644 --- a/toolchain/sem_ir/file.cpp +++ b/toolchain/sem_ir/file.cpp @@ -35,12 +35,12 @@ File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id, inst_blocks_(allocator_), constants_(this) { // `type` and the error type are both complete & concrete types. - types_.SetComplete(TypeType::SingletonTypeId, - {.value_repr = {.kind = ValueRepr::Copy, - .type_id = TypeType::SingletonTypeId}}); - types_.SetComplete(ErrorInst::SingletonTypeId, - {.value_repr = {.kind = ValueRepr::Copy, - .type_id = ErrorInst::SingletonTypeId}}); + types_.SetComplete( + TypeType::TypeId, + {.value_repr = {.kind = ValueRepr::Copy, .type_id = TypeType::TypeId}}); + types_.SetComplete( + ErrorInst::TypeId, + {.value_repr = {.kind = ValueRepr::Copy, .type_id = ErrorInst::TypeId}}); insts_.Reserve(SingletonInstKinds.size()); for (auto kind : SingletonInstKinds) { diff --git a/toolchain/sem_ir/ids.cpp b/toolchain/sem_ir/ids.cpp index cdc9502b2def..87517323dab8 100644 --- a/toolchain/sem_ir/ids.cpp +++ b/toolchain/sem_ir/ids.cpp @@ -132,11 +132,11 @@ auto InstBlockId::Print(llvm::raw_ostream& out) const -> void { auto TypeId::Print(llvm::raw_ostream& out) const -> void { out << Label << "("; - if (*this == TypeType::SingletonTypeId) { + if (*this == TypeType::TypeId) { out << "TypeType"; - } else if (*this == AutoType::SingletonTypeId) { + } else if (*this == AutoType::TypeId) { out << "AutoType"; - } else if (*this == ErrorInst::SingletonTypeId) { + } else if (*this == ErrorInst::TypeId) { out << "Error"; } else { AsConstantId().Print(out, /*disambiguate=*/false); diff --git a/toolchain/sem_ir/inst.h b/toolchain/sem_ir/inst.h index d536a2373ed9..d443869df97d 100644 --- a/toolchain/sem_ir/inst.h +++ b/toolchain/sem_ir/inst.h @@ -164,8 +164,8 @@ class Inst : public Printable { // Error uses a self-referential type so that it's not accidentally treated // as a normal type. Every other builtin is a type, including the // self-referential TypeType. - auto type_id = kind == InstKind::ErrorInst ? ErrorInst::SingletonTypeId - : TypeType::SingletonTypeId; + auto type_id = + kind == InstKind::ErrorInst ? ErrorInst::TypeId : TypeType::TypeId; return Inst(kind, type_id, InstId::NoneIndex, InstId::NoneIndex); } diff --git a/toolchain/sem_ir/inst_fingerprinter.cpp b/toolchain/sem_ir/inst_fingerprinter.cpp index a7442fb2ff54..57dc3338d0ac 100644 --- a/toolchain/sem_ir/inst_fingerprinter.cpp +++ b/toolchain/sem_ir/inst_fingerprinter.cpp @@ -404,8 +404,8 @@ struct Worklist { // Don't include the type if it's `type` or ``, because those types // are self-referential. - if (inst.type_id() != TypeType::SingletonTypeId && - inst.type_id() != ErrorInst::SingletonTypeId) { + if (inst.type_id() != TypeType::TypeId && + inst.type_id() != ErrorInst::TypeId) { Add(inst.type_id()); } diff --git a/toolchain/sem_ir/name_scope.h b/toolchain/sem_ir/name_scope.h index 1a044c4df536..34a771d1ff96 100644 --- a/toolchain/sem_ir/name_scope.h +++ b/toolchain/sem_ir/name_scope.h @@ -35,7 +35,7 @@ enum class AccessKind : int8_t { // - Represent that an error has occurred during lookup. This is still // considered found and the error `InstId` is considered existing. Can be // constructed using `MakeError()` or using `MakeWrappedLookupResult()` with -// `ErrorInst::SingletonInstId`. +// `ErrorInst::InstId`. class ScopeLookupResult { public: static auto MakeFound(InstId target_inst_id, AccessKind access_kind) @@ -53,7 +53,7 @@ class ScopeLookupResult { } static auto MakeError() -> ScopeLookupResult { - return MakeFound(ErrorInst::SingletonInstId, AccessKind::Public); + return MakeFound(ErrorInst::InstId, AccessKind::Public); } static auto MakeWrappedLookupResult(InstId target_inst_id, diff --git a/toolchain/sem_ir/name_scope_test.cpp b/toolchain/sem_ir/name_scope_test.cpp index 204eb0e0554d..cebc72c1378d 100644 --- a/toolchain/sem_ir/name_scope_test.cpp +++ b/toolchain/sem_ir/name_scope_test.cpp @@ -39,12 +39,12 @@ TEST(ScopeLookupResult, MakeWrappedLookupResultUsingNoneInstId) { } TEST(ScopeLookupResult, MakeWrappedLookupResultUsingErrorInst) { - auto result = ScopeLookupResult::MakeWrappedLookupResult( - ErrorInst::SingletonInstId, AccessKind::Private); + auto result = ScopeLookupResult::MakeWrappedLookupResult(ErrorInst::InstId, + AccessKind::Private); EXPECT_FALSE(result.is_poisoned()); EXPECT_TRUE(result.is_found()); - EXPECT_EQ(result.target_inst_id(), ErrorInst::SingletonInstId); + EXPECT_EQ(result.target_inst_id(), ErrorInst::InstId); EXPECT_DEATH(result.poisoning_loc_id(), "is_poisoned"); EXPECT_EQ(result.access_kind(), AccessKind::Private); EXPECT_TRUE(result == result); @@ -96,7 +96,7 @@ TEST(ScopeLookupResult, MakeError) { EXPECT_FALSE(result.is_poisoned()); EXPECT_TRUE(result.is_found()); - EXPECT_EQ(result.target_inst_id(), ErrorInst::SingletonInstId); + EXPECT_EQ(result.target_inst_id(), ErrorInst::InstId); EXPECT_DEATH(result.poisoning_loc_id(), "is_poisoned"); EXPECT_EQ(result.access_kind(), AccessKind::Public); EXPECT_TRUE(result == result); diff --git a/toolchain/sem_ir/singleton_insts.h b/toolchain/sem_ir/singleton_insts.h index fec05850ac04..30f6eb32cbd9 100644 --- a/toolchain/sem_ir/singleton_insts.h +++ b/toolchain/sem_ir/singleton_insts.h @@ -33,7 +33,7 @@ static constexpr std::array SingletonInstKinds = { constexpr auto IsSingletonInstKind(InstKind kind) -> bool; // Provides the InstId for singleton instructions. These are exposed as -// `InstT::SingletonInstId` in `typed_insts.h`. +// `InstT::InstId` in `typed_insts.h`. template requires(IsSingletonInstKind(InstKind::Make(Kind))) constexpr auto MakeSingletonInstId() -> TypeInstId; diff --git a/toolchain/sem_ir/stringify.cpp b/toolchain/sem_ir/stringify.cpp index 28be48bdf141..bbbe580140f4 100644 --- a/toolchain/sem_ir/stringify.cpp +++ b/toolchain/sem_ir/stringify.cpp @@ -706,10 +706,9 @@ auto StringifySpecific(const File& sem_ir, SpecificId specific_id) // TODO: This duplicates work done in StringifyInst for ClassType. const auto& class_info = sem_ir.classes().Get(class_decl.class_id); if (auto literal_info = NumericTypeLiteralInfo::ForType( - sem_ir, - SemIR::ClassType{.type_id = SemIR::TypeType::SingletonTypeId, - .class_id = class_decl.class_id, - .specific_id = specific_id}); + sem_ir, SemIR::ClassType{.type_id = SemIR::TypeType::TypeId, + .class_id = class_decl.class_id, + .specific_id = specific_id}); literal_info.is_valid()) { RawStringOstream out; literal_info.PrintLiteral(sem_ir, out); diff --git a/toolchain/sem_ir/type.cpp b/toolchain/sem_ir/type.cpp index 9ae6de37fe3b..8b95785b0129 100644 --- a/toolchain/sem_ir/type.cpp +++ b/toolchain/sem_ir/type.cpp @@ -14,10 +14,10 @@ static void CheckTypeOfConstantIsTypeType(File& file, ConstantId constant_id) { "Canonicalizing non-constant type: {0}", constant_id); auto type_id = file.insts().Get(file.constant_values().GetInstId(constant_id)).type_id(); - CARBON_CHECK(type_id == TypeType::SingletonTypeId || - constant_id == ErrorInst::SingletonConstantId, - "Forming type ID for non-type constant of type {0}", - file.types().GetAsInst(type_id)); + CARBON_CHECK( + type_id == TypeType::TypeId || constant_id == ErrorInst::ConstantId, + "Forming type ID for non-type constant of type {0}", + file.types().GetAsInst(type_id)); } auto TypeStore::GetTypeIdForTypeConstantId(ConstantId constant_id) const @@ -80,7 +80,7 @@ static auto TryGetIntTypeInfo(const File& file, TypeId type_id) return std::nullopt; } auto inst_id = file.types().GetInstId(object_repr_id); - if (inst_id == IntLiteralType::SingletonInstId) { + if (inst_id == IntLiteralType::InstId) { // `Core.IntLiteral` has an unknown bit-width. return TypeStore::IntTypeInfo{.is_signed = true, .bit_width = IntId::None}; } diff --git a/toolchain/sem_ir/type.h b/toolchain/sem_ir/type.h index 4ea54174539d..6773b6e0a33e 100644 --- a/toolchain/sem_ir/type.h +++ b/toolchain/sem_ir/type.h @@ -167,8 +167,7 @@ class TypeStore : public Yaml::Printable { // Returns whether `type_id` represents a facet type. auto IsFacetType(SemIR::TypeId type_id) const -> bool { - return type_id == SemIR::TypeType::SingletonTypeId || - Is(type_id); + return type_id == SemIR::TypeType::TypeId || Is(type_id); } // Returns a list of types that were completed in this file, in the order in diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index e3d77e607ac8..5ee088626362 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -17,8 +17,9 @@ // // - Either a `Kind` constant, or a `Kinds` constant and an `InstKind kind;` // member. These are described below. -// - Optionally, a `SingletonInstId` if it is a singleton instruction. -// Similarly, there may be `SingletonConstantId` and `SingletonTypeId`. +// - Optionally, a `InstId` if it is a singleton instruction. Similarly, there +// may be `ConstantId` and `TypeId`. +// - These are named based on the `Id` types they represent. // - Optionally, a `TypeId type_id;` member, for instructions that produce a // value. This includes instructions that produce an abstract value, such as a // `Namespace`, for which a placeholder type should be used. @@ -272,11 +273,11 @@ struct AutoType { {.ir_name = "auto", .is_type = InstIsType::Always, .constant_kind = InstConstantKind::Always}); - static constexpr auto SingletonInstId = MakeSingletonInstId(); - static constexpr auto SingletonTypeId = - TypeId::ForTypeConstant(ConstantId::ForConcreteConstant(SingletonInstId)); + static constexpr auto InstId = MakeSingletonInstId(); + static constexpr auto TypeId = + TypeId::ForTypeConstant(ConstantId::ForConcreteConstant(InstId)); - TypeId type_id; + SemIR::TypeId type_id; }; // A base in a class, of the form `base: base_type;`. A base class is an @@ -427,7 +428,7 @@ struct BoolType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -458,7 +459,7 @@ struct BoundMethodType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -660,15 +661,12 @@ struct ErrorInst { {.ir_name = "", .is_type = InstIsType::Always, .constant_kind = InstConstantKind::Always}); - static constexpr InstId SingletonInstId = MakeSingletonInstId(); - static constexpr auto SingletonConstantId = - ConstantId::ForConcreteConstant(SingletonInstId); - static constexpr auto SingletonTypeId = - TypeId::ForTypeConstant(SingletonConstantId); - static constexpr auto SingletonTypeInstId = - TypeInstId::UnsafeMake(SingletonInstId); + static constexpr SemIR::InstId InstId = MakeSingletonInstId(); + static constexpr auto ConstantId = ConstantId::ForConcreteConstant(InstId); + static constexpr auto TypeId = TypeId::ForTypeConstant(ConstantId); + static constexpr auto TypeInstId = TypeInstId::UnsafeMake(InstId); - TypeId type_id; + SemIR::TypeId type_id; }; // An `export bind_name` declaration. @@ -795,7 +793,7 @@ struct LegacyFloatType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1001,7 +999,7 @@ struct ImplWitnessTablePlaceholder { {.ir_name = "impl_witness_table_placeholder", .constant_kind = InstConstantKind::Unique, .is_lowered = false}); - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1080,11 +1078,11 @@ struct InstType { {.ir_name = "", .is_type = InstIsType::Always, .constant_kind = InstConstantKind::Always}); - static constexpr auto SingletonInstId = MakeSingletonInstId(); - static constexpr auto SingletonTypeId = - TypeId::ForTypeConstant(ConstantId::ForConcreteConstant(SingletonInstId)); + static constexpr auto InstId = MakeSingletonInstId(); + static constexpr auto TypeId = + TypeId::ForTypeConstant(ConstantId::ForConcreteConstant(InstId)); - TypeId type_id; + SemIR::TypeId type_id; }; // A value of type `InstType` that refers to an instruction. This is used to @@ -1135,7 +1133,7 @@ struct IntLiteralType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1235,7 +1233,7 @@ struct NamespaceType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1540,7 +1538,7 @@ struct SpecificFunctionType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1615,7 +1613,7 @@ struct StringType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1792,11 +1790,11 @@ struct TypeType { {.ir_name = "type", .is_type = InstIsType::Always, .constant_kind = InstConstantKind::Always}); - static constexpr auto SingletonInstId = MakeSingletonInstId(); - static constexpr auto SingletonTypeId = - TypeId::ForTypeConstant(ConstantId::ForConcreteConstant(SingletonInstId)); + static constexpr auto InstId = MakeSingletonInstId(); + static constexpr auto TypeId = + TypeId::ForTypeConstant(ConstantId::ForConcreteConstant(InstId)); - TypeId type_id; + SemIR::TypeId type_id; }; // The `not` operator, such as `not operand`. @@ -1887,7 +1885,7 @@ struct VtableType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; }; @@ -1936,7 +1934,7 @@ struct WitnessType { .constant_kind = InstConstantKind::Always}); // This is a singleton instruction. However, it may still evolve into a more // standard type and be removed. - static constexpr auto SingletonInstId = MakeSingletonInstId(); + static constexpr auto InstId = MakeSingletonInstId(); TypeId type_id; };