Преглед изворни кода

Rename Builtin to BuiltinInst, particularly to get BuiltinInstKind (#4115)

I'm trying to increase the distinction between BuiltinKind and
BuiltinFunctionKind. BuiltinKind is for instructions,
BuiltinFunctionKind is for function definitions. To get to this point,
I'm doing a few changes:

- BuiltinKind -> BuiltinInstKind
    - builtin_kind.* -> builtin_inst_kind.*: filename consistency
- Builtin -> BuiltinInst: mainly for consistency with the above
- Builtin::builtin_kind -> BuiltinInst::builtin_inst_kind: somewhat
repetitive but seems like a consistent edit
- Function::builtin_kind -> Function::builtin_function_kind: seems a
useful distinction

I'm leaving alone things like (and mentioning in case there's a desire
for more renames):

- InstId::BuiltinError, InstId::ForBuiltin: these I think are more
apparent because they're directly associated with Inst.
- GetBuiltinICmpPredicate in lowering: maybe builtin function handling
should be in its own file, but these local names don't feel problematic
to me.
- GetBuiltinType, BuildBuiltinValueRepr, PerformBuiltinIntComparison:
similar to the above, names don't feel too problematic
Jon Ross-Perkins пре 1 година
родитељ
комит
a81d67c629

+ 1 - 1
toolchain/check/BUILD

@@ -67,7 +67,7 @@ cc_library(
         "//toolchain/parse:node_kind",
         "//toolchain/parse:tree",
         "//toolchain/parse:tree_node_diagnostic_converter",
-        "//toolchain/sem_ir:builtin_kind",
+        "//toolchain/sem_ir:builtin_inst_kind",
         "//toolchain/sem_ir:file",
         "//toolchain/sem_ir:ids",
         "//toolchain/sem_ir:inst",

+ 1 - 1
toolchain/check/check.cpp

@@ -330,7 +330,7 @@ static auto InitPackageScopeAndImports(Context& context, UnitInfo& unit_info,
 
   // Importing makes many namespaces, so only canonicalize the type once.
   auto namespace_type_id =
-      context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType);
+      context.GetBuiltinType(SemIR::BuiltinInstKind::NamespaceType);
 
   // Define the package scope, with an instruction for `package` expressions to
   // reference.

+ 17 - 16
toolchain/check/context.cpp

@@ -21,7 +21,7 @@
 #include "toolchain/lex/tokenized_buffer.h"
 #include "toolchain/parse/node_ids.h"
 #include "toolchain/parse/node_kind.h"
-#include "toolchain/sem_ir/builtin_kind.h"
+#include "toolchain/sem_ir/builtin_inst_kind.h"
 #include "toolchain/sem_ir/file.h"
 #include "toolchain/sem_ir/ids.h"
 #include "toolchain/sem_ir/import_ir.h"
@@ -857,20 +857,21 @@ class TypeCompleter {
   }
 
   auto BuildBuiltinValueRepr(SemIR::TypeId type_id,
-                             SemIR::Builtin builtin) const -> SemIR::ValueRepr {
-    switch (builtin.builtin_kind) {
-      case SemIR::BuiltinKind::TypeType:
-      case SemIR::BuiltinKind::Error:
-      case SemIR::BuiltinKind::Invalid:
-      case SemIR::BuiltinKind::BoolType:
-      case SemIR::BuiltinKind::IntType:
-      case SemIR::BuiltinKind::FloatType:
-      case SemIR::BuiltinKind::NamespaceType:
-      case SemIR::BuiltinKind::BoundMethodType:
-      case SemIR::BuiltinKind::WitnessType:
+                             SemIR::BuiltinInst builtin) const
+      -> SemIR::ValueRepr {
+    switch (builtin.builtin_inst_kind) {
+      case SemIR::BuiltinInstKind::TypeType:
+      case SemIR::BuiltinInstKind::Error:
+      case SemIR::BuiltinInstKind::Invalid:
+      case SemIR::BuiltinInstKind::BoolType:
+      case SemIR::BuiltinInstKind::IntType:
+      case SemIR::BuiltinInstKind::FloatType:
+      case SemIR::BuiltinInstKind::NamespaceType:
+      case SemIR::BuiltinInstKind::BoundMethodType:
+      case SemIR::BuiltinInstKind::WitnessType:
         return MakeCopyValueRepr(type_id);
 
-      case SemIR::BuiltinKind::StringType:
+      case SemIR::BuiltinInstKind::StringType:
         // TODO: Decide on string value semantics. This should probably be a
         // custom value representation carrying a pointer and size or
         // similar.
@@ -1016,7 +1017,7 @@ class TypeCompleter {
         // - For an unbound element, we could use an index or offset.
         return MakeEmptyValueRepr();
       }
-      case CARBON_KIND(SemIR::Builtin builtin): {
+      case CARBON_KIND(SemIR::BuiltinInst builtin): {
         return BuildBuiltinValueRepr(type_id, builtin);
       }
 
@@ -1136,8 +1137,8 @@ auto Context::GetAssociatedEntityType(SemIR::InterfaceId interface_id,
                                                   entity_type_id);
 }
 
-auto Context::GetBuiltinType(SemIR::BuiltinKind kind) -> SemIR::TypeId {
-  CARBON_CHECK(kind != SemIR::BuiltinKind::Invalid);
+auto Context::GetBuiltinType(SemIR::BuiltinInstKind kind) -> SemIR::TypeId {
+  CARBON_CHECK(kind != SemIR::BuiltinInstKind::Invalid);
   auto type_id = GetTypeIdForTypeInst(SemIR::InstId::ForBuiltin(kind));
   // To keep client code simpler, complete builtin types before returning them.
   bool complete = TryToCompleteType(type_id);

+ 1 - 1
toolchain/check/context.h

@@ -285,7 +285,7 @@ class Context {
                                SemIR::TypeId entity_type_id) -> SemIR::TypeId;
 
   // Gets a builtin type. The returned type will be complete.
-  auto GetBuiltinType(SemIR::BuiltinKind kind) -> SemIR::TypeId;
+  auto GetBuiltinType(SemIR::BuiltinInstKind kind) -> SemIR::TypeId;
 
   // Gets a function type. The returned type will be complete.
   auto GetFunctionType(SemIR::FunctionId fn_id) -> SemIR::TypeId;

+ 4 - 3
toolchain/check/convert.cpp

@@ -148,8 +148,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<SemIR::IntLiteral>(
-        loc_id, {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::IntType),
-                 .int_id = context.ints().Add(llvm::APInt(32, i))});
+        loc_id,
+        {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::IntType),
+         .int_id = context.ints().Add(llvm::APInt(32, i))});
     return block.template AddInst<AccessInstT>(
         loc_id, {elem_type_id, aggregate_id, index_id});
   } else {
@@ -1101,7 +1102,7 @@ auto ConvertToBoolValue(Context& context, SemIR::LocId loc_id,
                         SemIR::InstId value_id) -> SemIR::InstId {
   return ConvertToValueOfType(
       context, loc_id, value_id,
-      context.GetBuiltinType(SemIR::BuiltinKind::BoolType));
+      context.GetBuiltinType(SemIR::BuiltinInstKind::BoolType));
 }
 
 auto ConvertForExplicitAs(Context& context, Parse::NodeId as_node,

+ 5 - 4
toolchain/check/eval.cpp

@@ -400,7 +400,7 @@ auto MakeIntTypeResult(Context& context, SemIRLoc loc, SemIR::IntKind int_kind,
                        SemIR::InstId width_id, Phase phase)
     -> SemIR::ConstantId {
   auto result = SemIR::IntType{
-      .type_id = context.GetBuiltinType(SemIR::BuiltinKind::TypeType),
+      .type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::TypeType),
       .int_kind = int_kind,
       .bit_width_id = width_id};
   if (!ValidateIntType(context, loc, result)) {
@@ -889,8 +889,9 @@ static auto MakeConstantForCall(Context& context, SemIRLoc loc,
   auto builtin_kind = SemIR::BuiltinFunctionKind::None;
   if (callee_function.function_id.is_valid()) {
     // Calls to builtins might be constant.
-    builtin_kind =
-        context.functions().Get(callee_function.function_id).builtin_kind;
+    builtin_kind = context.functions()
+                       .Get(callee_function.function_id)
+                       .builtin_function_kind;
     if (builtin_kind == SemIR::BuiltinFunctionKind::None) {
       // TODO: Eventually we'll want to treat some kinds of non-builtin
       // functions as producing constants.
@@ -1068,7 +1069,7 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
       return RebuildInitAsValue(context, inst, SemIR::TupleValue::Kind);
 
     case SemIR::AssociatedEntity::Kind:
-    case SemIR::Builtin::Kind:
+    case SemIR::BuiltinInst::Kind:
     case SemIR::FunctionType::Kind:
     case SemIR::GenericClassType::Kind:
     case SemIR::GenericInterfaceType::Kind:

+ 3 - 3
toolchain/check/handle_function.cpp

@@ -313,7 +313,7 @@ static auto BuildFunctionDecl(Context& context,
         !context.inst_blocks().Get(function_info.param_refs_id).empty() ||
         (return_type_id.is_valid() &&
          return_type_id !=
-             context.GetBuiltinType(SemIR::BuiltinKind::IntType) &&
+             context.GetBuiltinType(SemIR::BuiltinInstKind::IntType) &&
          return_type_id != context.GetTupleType({}))) {
       CARBON_DIAGNOSTIC(InvalidMainRunSignature, Error,
                         "Invalid signature for `Main.Run` function. Expected "
@@ -474,7 +474,7 @@ static auto LookupBuiltinFunctionKind(Context& context,
 }
 
 // Returns whether `function` is a valid declaration of the builtin
-// `builtin_kind`.
+// `builtin_inst_kind`.
 static auto IsValidBuiltinDeclaration(Context& context,
                                       const SemIR::Function& function,
                                       SemIR::BuiltinFunctionKind builtin_kind)
@@ -514,7 +514,7 @@ auto HandleBuiltinFunctionDefinition(
   if (builtin_kind != SemIR::BuiltinFunctionKind::None) {
     auto& function = context.functions().Get(function_id);
     if (IsValidBuiltinDeclaration(context, function, builtin_kind)) {
-      function.builtin_kind = builtin_kind;
+      function.builtin_function_kind = builtin_kind;
     } else {
       CARBON_DIAGNOSTIC(InvalidBuiltinSignature, Error,
                         "Invalid signature for builtin function \"{0}\".",

+ 2 - 2
toolchain/check/handle_index.cpp

@@ -47,7 +47,7 @@ auto HandleIndexExpr(Context& context, Parse::IndexExprId node_id) -> bool {
       auto index_node_id = context.insts().GetLocId(index_inst_id);
       auto cast_index_id = ConvertToValueOfType(
           context, index_node_id, index_inst_id,
-          context.GetBuiltinType(SemIR::BuiltinKind::IntType));
+          context.GetBuiltinType(SemIR::BuiltinInstKind::IntType));
       auto array_cat =
           SemIR::GetExprCategory(context.sem_ir(), operand_inst_id);
       if (array_cat == SemIR::ExprCategory::Value) {
@@ -77,7 +77,7 @@ auto HandleIndexExpr(Context& context, Parse::IndexExprId node_id) -> bool {
       auto index_node_id = context.insts().GetLocId(index_inst_id);
       index_inst_id = ConvertToValueOfType(
           context, index_node_id, index_inst_id,
-          context.GetBuiltinType(SemIR::BuiltinKind::IntType));
+          context.GetBuiltinType(SemIR::BuiltinInstKind::IntType));
       auto index_const_id = context.constant_values().Get(index_inst_id);
       if (index_const_id == SemIR::ConstantId::Error) {
         index_inst_id = SemIR::InstId::BuiltinError;

+ 11 - 8
toolchain/check/handle_literal.cpp

@@ -12,16 +12,18 @@ namespace Carbon::Check {
 auto HandleBoolLiteralFalse(Context& context, Parse::BoolLiteralFalseId node_id)
     -> bool {
   context.AddInstAndPush<SemIR::BoolLiteral>(
-      node_id, {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::BoolType),
-                .value = SemIR::BoolValue::False});
+      node_id,
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::BoolType),
+       .value = SemIR::BoolValue::False});
   return true;
 }
 
 auto HandleBoolLiteralTrue(Context& context, Parse::BoolLiteralTrueId node_id)
     -> bool {
   context.AddInstAndPush<SemIR::BoolLiteral>(
-      node_id, {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::BoolType),
-                .value = SemIR::BoolValue::True});
+      node_id,
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::BoolType),
+       .value = SemIR::BoolValue::True});
   return true;
 }
 
@@ -41,8 +43,9 @@ static auto MakeI32Literal(Context& context, Parse::NodeId node_id,
   // Literals are always represented as unsigned, so zero-extend if needed.
   auto i32_val = val.zextOrTrunc(32);
   return context.AddInst<SemIR::IntLiteral>(
-      node_id, {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::IntType),
-                .int_id = context.ints().Add(i32_val)});
+      node_id,
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::IntType),
+       .int_id = context.ints().Add(i32_val)});
 }
 
 auto HandleIntLiteral(Context& context, Parse::IntLiteralId node_id) -> bool {
@@ -94,7 +97,7 @@ auto HandleRealLiteral(Context& context, Parse::RealLiteralId node_id) -> bool {
   auto float_id = context.sem_ir().floats().Add(llvm::APFloat(double_val));
   context.AddInstAndPush<SemIR::FloatLiteral>(
       node_id,
-      {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::FloatType),
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::FloatType),
        .float_id = float_id});
   return true;
 }
@@ -103,7 +106,7 @@ auto HandleStringLiteral(Context& context, Parse::StringLiteralId node_id)
     -> bool {
   context.AddInstAndPush<SemIR::StringLiteral>(
       node_id,
-      {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::StringType),
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::StringType),
        .string_literal_id = context.tokens().GetStringLiteralValue(
            context.parse_tree().node_token(node_id))});
   return true;

+ 1 - 1
toolchain/check/handle_name.cpp

@@ -142,7 +142,7 @@ auto HandleNameQualifier(Context& context, Parse::NameQualifierId /*node_id*/)
 auto HandlePackageExpr(Context& context, Parse::PackageExprId node_id) -> bool {
   context.AddInstAndPush<SemIR::NameRef>(
       node_id,
-      {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType),
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::NamespaceType),
        .name_id = SemIR::NameId::PackageNamespace,
        .value_id = SemIR::InstId::PackageNamespace});
   return true;

+ 1 - 1
toolchain/check/handle_namespace.cpp

@@ -30,7 +30,7 @@ auto HandleNamespace(Context& context, Parse::NamespaceId node_id) -> bool {
   LimitModifiersOnDecl(context, introducer, KeywordModifierSet::None);
 
   auto namespace_inst = SemIR::Namespace{
-      context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType),
+      context.GetBuiltinType(SemIR::BuiltinInstKind::NamespaceType),
       SemIR::NameScopeId::Invalid, SemIR::InstId::Invalid};
   auto namespace_id =
       context.AddPlaceholderInst(SemIR::LocIdAndInst(node_id, namespace_inst));

+ 1 - 1
toolchain/check/impl.cpp

@@ -139,7 +139,7 @@ static auto BuildInterfaceWitness(
 
   auto table_id = context.inst_blocks().Add(table);
   return context.AddInst(SemIR::LocIdAndInst::NoLoc<SemIR::InterfaceWitness>(
-      {.type_id = context.GetBuiltinType(SemIR::BuiltinKind::WitnessType),
+      {.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::WitnessType),
        .elements_id = table_id}));
 }
 

+ 4 - 3
toolchain/check/import_ref.cpp

@@ -220,7 +220,7 @@ class ImportRefResolver {
 
     if (import_type_inst_id.is_builtin()) {
       // Builtins don't require constant resolution; we can use them directly.
-      return context_.GetBuiltinType(import_type_inst_id.builtin_kind());
+      return context_.GetBuiltinType(import_type_inst_id.builtin_inst_kind());
     } else {
       return context_.GetTypeIdForTypeConstant(Resolve(import_type_inst_id));
     }
@@ -1150,7 +1150,7 @@ class ImportRefResolver {
          .return_storage_id = new_return_storage,
          .is_extern = function.is_extern,
          .return_slot = function.return_slot,
-         .builtin_kind = function.builtin_kind,
+         .builtin_function_kind = function.builtin_function_kind,
          .definition_id = function.definition_id.is_valid()
                               ? function_decl_id
                               : SemIR::InstId::Invalid});
@@ -1387,7 +1387,8 @@ class ImportRefResolver {
 
     auto elements_id = GetLocalCanonicalInstBlockId(inst.elements_id, elements);
     return ResolveAs<SemIR::InterfaceWitness>(
-        {.type_id = context_.GetBuiltinType(SemIR::BuiltinKind::WitnessType),
+        {.type_id =
+             context_.GetBuiltinType(SemIR::BuiltinInstKind::WitnessType),
          .elements_id = elements_id});
   }
 

+ 1 - 1
toolchain/check/member_access.cpp

@@ -289,7 +289,7 @@ static auto PerformInstanceBinding(Context& context, Parse::NodeId node_id,
       if (IsInstanceMethod(context.sem_ir(), fn_type.function_id)) {
         return context.AddInst<SemIR::BoundMethod>(
             node_id, {.type_id = context.GetBuiltinType(
-                          SemIR::BuiltinKind::BoundMethodType),
+                          SemIR::BuiltinInstKind::BoundMethodType),
                       .object_id = base_id,
                       .function_id = member_id});
       }

+ 9 - 9
toolchain/check/testdata/basics/builtin_insts.carbon

@@ -27,15 +27,15 @@
 // CHECK:STDOUT:     type0:           {constant: template instNamespaceType, value_rep: {kind: copy, type: type0}}
 // CHECK:STDOUT:   type_blocks:     {}
 // CHECK:STDOUT:   insts:
-// CHECK:STDOUT:     instTypeType:    {kind: Builtin, arg0: TypeType, type: typeTypeType}
-// CHECK:STDOUT:     instError:       {kind: Builtin, arg0: Error, type: typeError}
-// CHECK:STDOUT:     instBoolType:    {kind: Builtin, arg0: BoolType, type: typeTypeType}
-// CHECK:STDOUT:     instIntType:     {kind: Builtin, arg0: IntType, type: typeTypeType}
-// CHECK:STDOUT:     instFloatType:   {kind: Builtin, arg0: FloatType, type: typeTypeType}
-// CHECK:STDOUT:     instStringType:  {kind: Builtin, arg0: StringType, type: typeTypeType}
-// CHECK:STDOUT:     instBoundMethodType: {kind: Builtin, arg0: BoundMethodType, type: typeTypeType}
-// CHECK:STDOUT:     instNamespaceType: {kind: Builtin, arg0: NamespaceType, type: typeTypeType}
-// CHECK:STDOUT:     instWitnessType: {kind: Builtin, arg0: WitnessType, type: typeTypeType}
+// CHECK:STDOUT:     instTypeType:    {kind: BuiltinInst, arg0: TypeType, type: typeTypeType}
+// CHECK:STDOUT:     instError:       {kind: BuiltinInst, arg0: Error, type: typeError}
+// CHECK:STDOUT:     instBoolType:    {kind: BuiltinInst, arg0: BoolType, type: typeTypeType}
+// CHECK:STDOUT:     instIntType:     {kind: BuiltinInst, arg0: IntType, type: typeTypeType}
+// CHECK:STDOUT:     instFloatType:   {kind: BuiltinInst, arg0: FloatType, type: typeTypeType}
+// CHECK:STDOUT:     instStringType:  {kind: BuiltinInst, arg0: StringType, type: typeTypeType}
+// CHECK:STDOUT:     instBoundMethodType: {kind: BuiltinInst, arg0: BoundMethodType, type: typeTypeType}
+// CHECK:STDOUT:     instNamespaceType: {kind: BuiltinInst, arg0: NamespaceType, type: typeTypeType}
+// CHECK:STDOUT:     instWitnessType: {kind: BuiltinInst, arg0: WitnessType, type: typeTypeType}
 // CHECK:STDOUT:     'inst+0':          {kind: Namespace, arg0: name_scope0, arg1: inst<invalid>, type: type0}
 // CHECK:STDOUT:   constant_values:
 // CHECK:STDOUT:     instTypeType:    template instTypeType

+ 13 - 13
toolchain/lower/file_context.cpp

@@ -130,7 +130,7 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id)
   }
 
   // Don't lower builtins.
-  if (function.builtin_kind != SemIR::BuiltinFunctionKind::None) {
+  if (function.builtin_function_kind != SemIR::BuiltinFunctionKind::None) {
     return nullptr;
   }
 
@@ -315,28 +315,28 @@ auto FileContext::BuildType(SemIR::InstId inst_id) -> llvm::Type* {
       return llvm::ArrayType::get(GetType(inst.element_type_id),
                                   sem_ir_->GetArrayBoundValue(inst.bound_id));
     }
-    case CARBON_KIND(SemIR::Builtin inst): {
-      switch (inst.builtin_kind) {
-        case SemIR::BuiltinKind::Invalid:
-        case SemIR::BuiltinKind::Error:
+    case CARBON_KIND(SemIR::BuiltinInst inst): {
+      switch (inst.builtin_inst_kind) {
+        case SemIR::BuiltinInstKind::Invalid:
+        case SemIR::BuiltinInstKind::Error:
           CARBON_FATAL() << "Unexpected builtin type in lowering.";
-        case SemIR::BuiltinKind::TypeType:
+        case SemIR::BuiltinInstKind::TypeType:
           return GetTypeType();
-        case SemIR::BuiltinKind::FloatType:
+        case SemIR::BuiltinInstKind::FloatType:
           return llvm::Type::getDoubleTy(*llvm_context_);
-        case SemIR::BuiltinKind::IntType:
+        case SemIR::BuiltinInstKind::IntType:
           return llvm::Type::getInt32Ty(*llvm_context_);
-        case SemIR::BuiltinKind::BoolType:
+        case SemIR::BuiltinInstKind::BoolType:
           // TODO: We may want to have different representations for `bool`
           // storage
           // (`i8`) versus for `bool` values (`i1`).
           return llvm::Type::getInt1Ty(*llvm_context_);
-        case SemIR::BuiltinKind::StringType:
+        case SemIR::BuiltinInstKind::StringType:
           // TODO: Decide how we want to represent `StringType`.
           return llvm::PointerType::get(*llvm_context_, 0);
-        case SemIR::BuiltinKind::BoundMethodType:
-        case SemIR::BuiltinKind::NamespaceType:
-        case SemIR::BuiltinKind::WitnessType:
+        case SemIR::BuiltinInstKind::BoundMethodType:
+        case SemIR::BuiltinInstKind::NamespaceType:
+        case SemIR::BuiltinInstKind::WitnessType:
           // Return an empty struct as a placeholder.
           return llvm::StructType::get(*llvm_context_);
       }

+ 1 - 1
toolchain/lower/handle_call.cpp

@@ -302,7 +302,7 @@ auto HandleCall(FunctionContext& context, SemIR::InstId inst_id,
   if (auto builtin_kind = context.sem_ir()
                               .functions()
                               .Get(callee_function.function_id)
-                              .builtin_kind;
+                              .builtin_function_kind;
       builtin_kind != SemIR::BuiltinFunctionKind::None) {
     HandleBuiltinCall(context, inst_id, builtin_kind, arg_ids);
     return;

+ 8 - 8
toolchain/sem_ir/BUILD

@@ -7,10 +7,10 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
 package(default_visibility = ["//visibility:public"])
 
 cc_library(
-    name = "builtin_kind",
-    srcs = ["builtin_kind.cpp"],
-    hdrs = ["builtin_kind.h"],
-    textual_hdrs = ["builtin_kind.def"],
+    name = "builtin_inst_kind",
+    srcs = ["builtin_inst_kind.cpp"],
+    hdrs = ["builtin_inst_kind.h"],
+    textual_hdrs = ["builtin_inst_kind.def"],
     deps = ["//common:enum_base"],
 )
 
@@ -39,7 +39,7 @@ cc_library(
         "//toolchain/base:value_store",
         "//toolchain/diagnostics:diagnostic_emitter",
         "//toolchain/parse:node_kind",
-        "//toolchain/sem_ir:builtin_kind",
+        "//toolchain/sem_ir:builtin_inst_kind",
     ],
 )
 
@@ -54,7 +54,7 @@ cc_library(
     deps = [
         "//common:enum_base",
         "//toolchain/parse:node_kind",
-        "//toolchain/sem_ir:builtin_kind",
+        "//toolchain/sem_ir:builtin_inst_kind",
         "//toolchain/sem_ir:ids",
         "@llvm-project//llvm:Support",
     ],
@@ -66,7 +66,7 @@ cc_library(
     hdrs = ["inst.h"],
     deps = [
         ":block_value_store",
-        ":builtin_kind",
+        ":builtin_inst_kind",
         ":ids",
         ":inst_kind",
         "//common:check",
@@ -109,7 +109,7 @@ cc_library(
     ],
     deps = [
         ":block_value_store",
-        ":builtin_kind",
+        ":builtin_inst_kind",
         ":ids",
         ":inst",
         ":inst_kind",

+ 7 - 7
toolchain/sem_ir/builtin_kind.cpp → toolchain/sem_ir/builtin_inst_kind.cpp

@@ -2,20 +2,20 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-#include "toolchain/sem_ir/builtin_kind.h"
+#include "toolchain/sem_ir/builtin_inst_kind.h"
 
 namespace Carbon::SemIR {
 
-CARBON_DEFINE_ENUM_CLASS_NAMES(BuiltinKind) = {
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) \
+CARBON_DEFINE_ENUM_CLASS_NAMES(BuiltinInstKind) = {
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name) \
   CARBON_ENUM_CLASS_NAME_STRING(Name)
-#include "toolchain/sem_ir/builtin_kind.def"
+#include "toolchain/sem_ir/builtin_inst_kind.def"
 };
 
-auto BuiltinKind::label() -> llvm::StringRef {
+auto BuiltinInstKind::label() -> llvm::StringRef {
   static constexpr llvm::StringLiteral Labels[] = {
-#define CARBON_SEM_IR_BUILTIN_KIND(Name, Label) Label,
-#include "toolchain/sem_ir/builtin_kind.def"
+#define CARBON_SEM_IR_BUILTIN_INST_KIND(Name, Label) Label,
+#include "toolchain/sem_ir/builtin_inst_kind.def"
   };
   return Labels[AsInt()];
 }

+ 25 - 25
toolchain/sem_ir/builtin_kind.def → toolchain/sem_ir/builtin_inst_kind.def

@@ -8,43 +8,43 @@
 // at the end of this file.
 //
 // Supported x-macros are:
-// - CARBON_SEM_IR_BUILTIN_KIND_NAME(Name)
+// - CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name)
 //   Used as a fallback if other macros are missing. Used directly by Invalid
 //   only, which is defined last.
-//   - CARBON_SEM_IR_BUILTIN_KIND(Name, Label)
+//   - CARBON_SEM_IR_BUILTIN_INST_KIND(Name, Label)
 //     Defines a non-Invalid builtin type. The label is used for stringifying
 //     types.
 //
 // This tree represents the subset relationship between these macros, where if a
 // specific x-macro isn't defined, it'll fall back to the parent macro.
 
-#if !(defined(CARBON_SEM_IR_BUILTIN_KIND_NAME) || \
-      defined(CARBON_SEM_IR_BUILTIN_KIND))
+#if !(defined(CARBON_SEM_IR_BUILTIN_INST_KIND_NAME) || \
+      defined(CARBON_SEM_IR_BUILTIN_INST_KIND))
 #error \
-    "Must define CARBON_SEM_IR_BUILTIN_KIND family x-macros to use this file."
+    "Must define CARBON_SEM_IR_BUILTIN_INST_KIND family x-macros to use this file."
 #endif
 
-// If CARBON_SEM_IR_BUILTIN_KIND_NAME is undefined, ignore calls.
-#ifndef CARBON_SEM_IR_BUILTIN_KIND_NAME
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name)
+// If CARBON_SEM_IR_BUILTIN_INST_KIND_NAME is undefined, ignore calls.
+#ifndef CARBON_SEM_IR_BUILTIN_INST_KIND_NAME
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name)
 #endif
 
-// If CARBON_SEM_IR_BUILTIN_KIND is undefined, delegate calls to
-// CARBON_SEM_IR_BUILTIN_KIND_NAME.
-#ifndef CARBON_SEM_IR_BUILTIN_KIND
-#define CARBON_SEM_IR_BUILTIN_KIND(Name, ...) \
-  CARBON_SEM_IR_BUILTIN_KIND_NAME(Name)
+// If CARBON_SEM_IR_BUILTIN_INST_KIND is undefined, delegate calls to
+// CARBON_SEM_IR_BUILTIN_INST_KIND_NAME.
+#ifndef CARBON_SEM_IR_BUILTIN_INST_KIND
+#define CARBON_SEM_IR_BUILTIN_INST_KIND(Name, ...) \
+  CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name)
 #endif
 
 // Tracks expressions which are valid as types.
 // This has a deliberately self-referential type.
-CARBON_SEM_IR_BUILTIN_KIND(TypeType, "type")
+CARBON_SEM_IR_BUILTIN_INST_KIND(TypeType, "type")
 
 // Used when a semantic error has been detected, and a SemIR InstId is still
 // required. For example, when there is a type checking issue, this will be used
 // in the type_id. It's typically used as a cue that semantic checking doesn't
 // need to issue further diagnostics.
-CARBON_SEM_IR_BUILTIN_KIND(Error, "<error>")
+CARBON_SEM_IR_BUILTIN_INST_KIND(Error, "<error>")
 
 // -----------------------------------------------------------------------------
 // TODO: Below types are all placeholders. While the above may last, the below
@@ -53,29 +53,29 @@ CARBON_SEM_IR_BUILTIN_KIND(Error, "<error>")
 // -----------------------------------------------------------------------------
 
 // The type of bool literals and branch conditions, bool.
-CARBON_SEM_IR_BUILTIN_KIND(BoolType, "bool")
+CARBON_SEM_IR_BUILTIN_INST_KIND(BoolType, "bool")
 
 // The type of integer values and integer literals, currently always i32.
-CARBON_SEM_IR_BUILTIN_KIND(IntType, "i32")
+CARBON_SEM_IR_BUILTIN_INST_KIND(IntType, "i32")
 
 // The type of floating point values and real literals, currently always f64.
-CARBON_SEM_IR_BUILTIN_KIND(FloatType, "f64")
+CARBON_SEM_IR_BUILTIN_INST_KIND(FloatType, "f64")
 
 // The type of string values and String literals.
-CARBON_SEM_IR_BUILTIN_KIND(StringType, "String")
+CARBON_SEM_IR_BUILTIN_INST_KIND(StringType, "String")
 
 // The type of bound method values.
-CARBON_SEM_IR_BUILTIN_KIND(BoundMethodType, "<bound method>")
+CARBON_SEM_IR_BUILTIN_INST_KIND(BoundMethodType, "<bound method>")
 
 // The type of namespace and imported package names.
-CARBON_SEM_IR_BUILTIN_KIND(NamespaceType, "<namespace>")
+CARBON_SEM_IR_BUILTIN_INST_KIND(NamespaceType, "<namespace>")
 
 // The type of witnesses.
-CARBON_SEM_IR_BUILTIN_KIND(WitnessType, "<witness>")
+CARBON_SEM_IR_BUILTIN_INST_KIND(WitnessType, "<witness>")
 
 // Keep invalid last, so that we can use values as array indices without needing
 // an invalid entry.
-CARBON_SEM_IR_BUILTIN_KIND_NAME(Invalid)
+CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Invalid)
 
-#undef CARBON_SEM_IR_BUILTIN_KIND_NAME
-#undef CARBON_SEM_IR_BUILTIN_KIND
+#undef CARBON_SEM_IR_BUILTIN_INST_KIND_NAME
+#undef CARBON_SEM_IR_BUILTIN_INST_KIND

+ 17 - 15
toolchain/sem_ir/builtin_kind.h → toolchain/sem_ir/builtin_inst_kind.h

@@ -2,8 +2,8 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-#ifndef CARBON_TOOLCHAIN_SEM_IR_BUILTIN_KIND_H_
-#define CARBON_TOOLCHAIN_SEM_IR_BUILTIN_KIND_H_
+#ifndef CARBON_TOOLCHAIN_SEM_IR_BUILTIN_INST_KIND_H_
+#define CARBON_TOOLCHAIN_SEM_IR_BUILTIN_INST_KIND_H_
 
 #include <cstdint>
 
@@ -11,15 +11,17 @@
 
 namespace Carbon::SemIR {
 
-CARBON_DEFINE_RAW_ENUM_CLASS(BuiltinKind, uint8_t) {
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) CARBON_RAW_ENUM_ENUMERATOR(Name)
-#include "toolchain/sem_ir/builtin_kind.def"
+CARBON_DEFINE_RAW_ENUM_CLASS(BuiltinInstKind, uint8_t) {
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name) \
+  CARBON_RAW_ENUM_ENUMERATOR(Name)
+#include "toolchain/sem_ir/builtin_inst_kind.def"
 };
 
-class BuiltinKind : public CARBON_ENUM_BASE(BuiltinKind) {
+class BuiltinInstKind : public CARBON_ENUM_BASE(BuiltinInstKind) {
  public:
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) CARBON_ENUM_CONSTANT_DECL(Name)
-#include "toolchain/sem_ir/builtin_kind.def"
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name) \
+  CARBON_ENUM_CONSTANT_DECL(Name)
+#include "toolchain/sem_ir/builtin_inst_kind.def"
 
   auto label() -> llvm::StringRef;
 
@@ -34,21 +36,21 @@ class BuiltinKind : public CARBON_ENUM_BASE(BuiltinKind) {
   using EnumBase::FromInt;
 };
 
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) \
-  CARBON_ENUM_CONSTANT_DEFINITION(BuiltinKind, Name)
-#include "toolchain/sem_ir/builtin_kind.def"
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name) \
+  CARBON_ENUM_CONSTANT_DEFINITION(BuiltinInstKind, Name)
+#include "toolchain/sem_ir/builtin_inst_kind.def"
 
-constexpr uint8_t BuiltinKind::ValidCount = Invalid.AsInt();
+constexpr uint8_t BuiltinInstKind::ValidCount = Invalid.AsInt();
 
 static_assert(
-    BuiltinKind::ValidCount != 0,
+    BuiltinInstKind::ValidCount != 0,
     "The above `constexpr` definition of `ValidCount` makes it available in "
     "a `constexpr` context despite being declared as merely `const`. We use it "
     "in a static assert here to ensure that.");
 
 // We expect the builtin kind to fit compactly into 8 bits.
-static_assert(sizeof(BuiltinKind) == 1, "Kind objects include padding!");
+static_assert(sizeof(BuiltinInstKind) == 1, "Kind objects include padding!");
 
 }  // namespace Carbon::SemIR
 
-#endif  // CARBON_TOOLCHAIN_SEM_IR_BUILTIN_KIND_H_
+#endif  // CARBON_TOOLCHAIN_SEM_IR_BUILTIN_INST_KIND_H_

+ 28 - 26
toolchain/sem_ir/file.cpp

@@ -11,7 +11,7 @@
 #include "toolchain/base/value_store.h"
 #include "toolchain/base/yaml.h"
 #include "toolchain/parse/node_ids.h"
-#include "toolchain/sem_ir/builtin_kind.h"
+#include "toolchain/sem_ir/builtin_inst_kind.h"
 #include "toolchain/sem_ir/ids.h"
 #include "toolchain/sem_ir/inst.h"
 #include "toolchain/sem_ir/inst_kind.h"
@@ -72,20 +72,21 @@ File::File(CheckIRId check_ir_id, SharedValueStores& value_stores,
       constant_values_(ConstantId::NotConstant),
       inst_blocks_(allocator_),
       constants_(*this, allocator_) {
-  insts_.Reserve(BuiltinKind::ValidCount);
+  insts_.Reserve(BuiltinInstKind::ValidCount);
 // 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.
-#define CARBON_SEM_IR_BUILTIN_KIND(Name, ...)                                 \
-  insts_.AddInNoBlock(LocIdAndInst::NoLoc<Builtin>(                           \
-      {.type_id = BuiltinKind::Name == BuiltinKind::Error ? TypeId::Error     \
-                                                          : TypeId::TypeType, \
-       .builtin_kind = BuiltinKind::Name}));
-#include "toolchain/sem_ir/builtin_kind.def"
-  CARBON_CHECK(insts_.size() == BuiltinKind::ValidCount)
-      << "Builtins should produce " << BuiltinKind::ValidCount
+#define CARBON_SEM_IR_BUILTIN_INST_KIND(Name, ...)                \
+  insts_.AddInNoBlock(LocIdAndInst::NoLoc<BuiltinInst>(           \
+      {.type_id = BuiltinInstKind::Name == BuiltinInstKind::Error \
+                      ? TypeId::Error                             \
+                      : TypeId::TypeType,                         \
+       .builtin_inst_kind = BuiltinInstKind::Name}));
+#include "toolchain/sem_ir/builtin_inst_kind.def"
+  CARBON_CHECK(insts_.size() == BuiltinInstKind::ValidCount)
+      << "Builtins should produce " << BuiltinInstKind::ValidCount
       << " insts, actual: " << insts_.size();
-  for (auto i : llvm::seq(BuiltinKind::ValidCount)) {
+  for (auto i : llvm::seq(BuiltinInstKind::ValidCount)) {
     auto builtin_id = SemIR::InstId(i);
     constant_values_.Set(builtin_id,
                          SemIR::ConstantId::ForTemplateConstant(builtin_id));
@@ -145,18 +146,19 @@ auto File::OutputYaml(bool include_builtins) const -> Yaml::OutputMapping {
           map.Add("generic_instances", generic_instances_.OutputYaml());
           map.Add("types", types_.OutputYaml());
           map.Add("type_blocks", type_blocks_.OutputYaml());
-          map.Add("insts",
-                  Yaml::OutputMapping([&](Yaml::OutputMapping::Map map) {
-                    int start = include_builtins ? 0 : BuiltinKind::ValidCount;
-                    for (int i : llvm::seq(start, insts_.size())) {
-                      auto id = InstId(i);
-                      map.Add(PrintToString(id),
-                              Yaml::OutputScalar(insts_.Get(id)));
-                    }
-                  }));
+          map.Add(
+              "insts", Yaml::OutputMapping([&](Yaml::OutputMapping::Map map) {
+                int start = include_builtins ? 0 : BuiltinInstKind::ValidCount;
+                for (int i : llvm::seq(start, insts_.size())) {
+                  auto id = InstId(i);
+                  map.Add(PrintToString(id),
+                          Yaml::OutputScalar(insts_.Get(id)));
+                }
+              }));
           map.Add("constant_values",
                   Yaml::OutputMapping([&](Yaml::OutputMapping::Map map) {
-                    int start = include_builtins ? 0 : BuiltinKind::ValidCount;
+                    int start =
+                        include_builtins ? 0 : BuiltinInstKind::ValidCount;
                     for (int i : llvm::seq(start, insts_.size())) {
                       auto id = InstId(i);
                       auto value = constant_values_.Get(id);
@@ -178,7 +180,7 @@ static auto GetTypePrecedence(InstKind kind) -> int {
     case ArrayType::Kind:
     case AssociatedEntityType::Kind:
     case BindSymbolicName::Kind:
-    case Builtin::Kind:
+    case BuiltinInst::Kind:
     case ClassType::Kind:
     case FloatType::Kind:
     case FunctionType::Kind:
@@ -235,7 +237,7 @@ static auto StringifyTypeExprImpl(const SemIR::File& outer_sem_ir,
 
     // Builtins have designated labels.
     if (step.inst_id.is_builtin()) {
-      out << step.inst_id.builtin_kind().label();
+      out << step.inst_id.builtin_inst_kind().label();
       continue;
     }
 
@@ -444,7 +446,7 @@ static auto StringifyTypeExprImpl(const SemIR::File& outer_sem_ir,
       case Branch::Kind:
       case BranchIf::Kind:
       case BranchWithArg::Kind:
-      case Builtin::Kind:
+      case BuiltinInst::Kind:
       case Call::Kind:
       case ClassDecl::Kind:
       case ClassElementAccess::Kind:
@@ -604,8 +606,8 @@ auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory {
       case ValueOfInitializer::Kind:
         return value_category;
 
-      case CARBON_KIND(Builtin inst): {
-        if (inst.builtin_kind == BuiltinKind::Error) {
+      case CARBON_KIND(BuiltinInst inst): {
+        if (inst.builtin_inst_kind == BuiltinInstKind::Error) {
           return ExprCategory::Error;
         }
         return value_category;

+ 2 - 2
toolchain/sem_ir/file.h

@@ -234,8 +234,8 @@ class File : public Printable<File> {
   // the data is provided by allocator_.
   BlockValueStore<TypeBlockId> type_blocks_;
 
-  // All instructions. The first entries will always be Builtin insts, at
-  // indices matching BuiltinKind ordering.
+  // All instructions. The first entries will always be BuiltinInsts, at
+  // indices matching BuiltinInstKind ordering.
   InstStore insts_;
 
   // Storage for name scopes.

+ 3 - 3
toolchain/sem_ir/formatter.cpp

@@ -286,9 +286,9 @@ class Formatter {
       FormatType(sem_ir_.insts().Get(fn.return_storage_id).type_id());
     }
 
-    if (fn.builtin_kind != BuiltinFunctionKind::None) {
+    if (fn.builtin_function_kind != BuiltinFunctionKind::None) {
       out_ << " = \"";
-      out_.write_escaped(fn.builtin_kind.name(),
+      out_.write_escaped(fn.builtin_function_kind.name(),
                          /*UseHexEscapes=*/true);
       out_ << "\"";
     }
@@ -742,7 +742,7 @@ class Formatter {
 
   auto FormatArg(BoolValue v) -> void { out_ << v; }
 
-  auto FormatArg(BuiltinKind kind) -> void { out_ << kind.label(); }
+  auto FormatArg(BuiltinInstKind kind) -> void { out_ << kind.label(); }
 
   auto FormatArg(BindNameId id) -> void {
     const auto& info = sem_ir_.bind_names().Get(id);

+ 1 - 1
toolchain/sem_ir/function.h

@@ -107,7 +107,7 @@ struct Function : public Printable<Function> {
   // The following members are set at the end of a builtin function definition.
 
   // If this is a builtin function, the corresponding builtin kind.
-  BuiltinFunctionKind builtin_kind = BuiltinFunctionKind::None;
+  BuiltinFunctionKind builtin_function_kind = BuiltinFunctionKind::None;
 
   // The following members are set at the `{` of the function definition.
 

+ 2 - 2
toolchain/sem_ir/id_kind.h

@@ -115,8 +115,8 @@ class TypeEnum {
 
 // An enum of all the ID types used as instruction operands.
 using IdKind = TypeEnum<
-    // From sem_ir/builtin_kind.h.
-    BuiltinKind,
+    // From sem_ir/builtin_inst_kind.h.
+    BuiltinInstKind,
     // From base/value_store.h.
     IntId, RealId, FloatId, StringLiteralValueId,
     // From sem_ir/id.h.

+ 17 - 16
toolchain/sem_ir/ids.h

@@ -11,7 +11,7 @@
 #include "toolchain/base/value_store.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
 #include "toolchain/parse/node_ids.h"
-#include "toolchain/sem_ir/builtin_kind.h"
+#include "toolchain/sem_ir/builtin_inst_kind.h"
 
 namespace Carbon::SemIR {
 
@@ -37,16 +37,17 @@ struct InstId : public IdBase, public Printable<InstId> {
   // An explicitly invalid ID.
   static const InstId Invalid;
 
-// Builtin instruction IDs.
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) static const InstId Builtin##Name;
-#include "toolchain/sem_ir/builtin_kind.def"
+// BuiltinInst IDs.
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name) \
+  static const InstId Builtin##Name;
+#include "toolchain/sem_ir/builtin_inst_kind.def"
 
   // The namespace for a `package` expression.
   static const InstId PackageNamespace;
 
   // Returns the instruction ID for a builtin. This relies on File guarantees
   // for builtin placement.
-  static constexpr auto ForBuiltin(BuiltinKind kind) -> InstId {
+  static constexpr auto ForBuiltin(BuiltinInstKind kind) -> InstId {
     return InstId(kind.AsInt());
   }
 
@@ -55,13 +56,13 @@ struct InstId : public IdBase, public Printable<InstId> {
   // Returns true if the instruction is a builtin. Requires is_valid.
   auto is_builtin() const -> bool {
     CARBON_CHECK(is_valid());
-    return index < BuiltinKind::ValidCount;
+    return index < BuiltinInstKind::ValidCount;
   }
 
-  // Returns the BuiltinKind. Requires is_builtin.
-  auto builtin_kind() const -> BuiltinKind {
+  // Returns the BuiltinInstKind. Requires is_builtin.
+  auto builtin_inst_kind() const -> BuiltinInstKind {
     CARBON_CHECK(is_builtin());
-    return BuiltinKind::FromInt(index);
+    return BuiltinInstKind::FromInt(index);
   }
 
   auto Print(llvm::raw_ostream& out) const -> void {
@@ -69,24 +70,24 @@ struct InstId : public IdBase, public Printable<InstId> {
     if (!is_valid()) {
       IdBase::Print(out);
     } else if (is_builtin()) {
-      out << builtin_kind();
+      out << builtin_inst_kind();
     } else {
       // Use the `+` as a small reminder that this is a delta, rather than an
       // absolute index.
-      out << "+" << index - BuiltinKind::ValidCount;
+      out << "+" << index - BuiltinInstKind::ValidCount;
     }
   }
 };
 
 constexpr InstId InstId::Invalid = InstId(InvalidIndex);
 
-#define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) \
-  constexpr InstId InstId::Builtin##Name =    \
-      InstId::ForBuiltin(BuiltinKind::Name);
-#include "toolchain/sem_ir/builtin_kind.def"
+#define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name) \
+  constexpr InstId InstId::Builtin##Name =         \
+      InstId::ForBuiltin(BuiltinInstKind::Name);
+#include "toolchain/sem_ir/builtin_inst_kind.def"
 
 // The package namespace will be the instruction after builtins.
-constexpr InstId InstId::PackageNamespace = InstId(BuiltinKind::ValidCount);
+constexpr InstId InstId::PackageNamespace = InstId(BuiltinInstKind::ValidCount);
 
 // The ID of a constant value of an expression. An expression is either:
 //

+ 4 - 4
toolchain/sem_ir/inst.h

@@ -14,7 +14,7 @@
 #include "common/struct_reflection.h"
 #include "toolchain/base/index_base.h"
 #include "toolchain/sem_ir/block_value_store.h"
-#include "toolchain/sem_ir/builtin_kind.h"
+#include "toolchain/sem_ir/builtin_inst_kind.h"
 #include "toolchain/sem_ir/id_kind.h"
 #include "toolchain/sem_ir/inst_kind.h"
 #include "toolchain/sem_ir/typed_insts.h"
@@ -264,7 +264,7 @@ class Inst : public Printable<Inst> {
 
   // Convert a field to its raw representation, used as `arg0_` / `arg1_`.
   static constexpr auto ToRaw(IdBase base) -> int32_t { return base.index; }
-  static constexpr auto ToRaw(BuiltinKind kind) -> int32_t {
+  static constexpr auto ToRaw(BuiltinInstKind kind) -> int32_t {
     return kind.AsInt();
   }
 
@@ -274,8 +274,8 @@ class Inst : public Printable<Inst> {
     return T(raw);
   }
   template <>
-  constexpr auto FromRaw<BuiltinKind>(int32_t raw) -> BuiltinKind {
-    return BuiltinKind::FromInt(raw);
+  constexpr auto FromRaw<BuiltinInstKind>(int32_t raw) -> BuiltinInstKind {
+    return BuiltinInstKind::FromInt(raw);
   }
 
   int32_t kind_;

+ 1 - 1
toolchain/sem_ir/inst_kind.def

@@ -96,7 +96,7 @@ CARBON_SEM_IR_INST_KIND_IMPL(BoundMethod, TYPE_NEVER, CONSTANT_CONDITIONAL)
 CARBON_SEM_IR_INST_KIND_IMPL(Branch, TYPE_NEVER, CONSTANT_NEVER)
 CARBON_SEM_IR_INST_KIND_IMPL(BranchIf, TYPE_NEVER, CONSTANT_NEVER)
 CARBON_SEM_IR_INST_KIND_IMPL(BranchWithArg, TYPE_NEVER, CONSTANT_NEVER)
-CARBON_SEM_IR_INST_KIND_IMPL(Builtin, TYPE_ALWAYS, CONSTANT_ALWAYS)
+CARBON_SEM_IR_INST_KIND_IMPL(BuiltinInst, TYPE_ALWAYS, CONSTANT_ALWAYS)
 CARBON_SEM_IR_INST_KIND_IMPL(Call, TYPE_NEVER, CONSTANT_NEVER)
 CARBON_SEM_IR_INST_KIND_IMPL(ClassDecl, TYPE_NEVER, CONSTANT_NEVER)
 CARBON_SEM_IR_INST_KIND_IMPL(ClassElementAccess, TYPE_NEVER, CONSTANT_NEVER)

+ 4 - 3
toolchain/sem_ir/inst_namer.cpp

@@ -141,7 +141,7 @@ auto InstNamer::GetNameFor(ScopeId scope_id, InstId inst_id) const
 
   // Check for a builtin.
   if (inst_id.is_builtin()) {
-    return inst_id.builtin_kind().label().str();
+    return inst_id.builtin_inst_kind().label().str();
   }
 
   if (inst_id == InstId::PackageNamespace) {
@@ -411,10 +411,11 @@ auto InstNamer::CollectNamesInBlock(ScopeId scope_id,
         const auto& function =
             sem_ir_.functions().Get(callee_function.function_id);
         // Name the call's result based on the callee.
-        if (function.builtin_kind != SemIR::BuiltinFunctionKind::None) {
+        if (function.builtin_function_kind !=
+            SemIR::BuiltinFunctionKind::None) {
           // For a builtin, use the builtin name. Otherwise, we'd typically pick
           // the name `Op` below, which is probably not very useful.
-          add_inst_name(function.builtin_kind.name().str());
+          add_inst_name(function.builtin_function_kind.name().str());
           continue;
         }
 

+ 1 - 1
toolchain/sem_ir/type.h

@@ -54,7 +54,7 @@ class TypeStore : public ValueStore<TypeId> {
   // to be a particular kind of instruction.
   template <typename InstT>
   auto GetAs(TypeId type_id) const -> InstT {
-    if constexpr (std::is_same_v<InstT, Builtin>) {
+    if constexpr (std::is_same_v<InstT, BuiltinInst>) {
       return GetAsInst(type_id).As<InstT>();
     } else {
       // The type is not a builtin, so no need to check for special values.

+ 5 - 5
toolchain/sem_ir/typed_insts.h

@@ -6,7 +6,7 @@
 #define CARBON_TOOLCHAIN_SEM_IR_TYPED_INSTS_H_
 
 #include "toolchain/parse/node_ids.h"
-#include "toolchain/sem_ir/builtin_kind.h"
+#include "toolchain/sem_ir/builtin_inst_kind.h"
 #include "toolchain/sem_ir/ids.h"
 #include "toolchain/sem_ir/inst_kind.h"
 
@@ -374,13 +374,13 @@ struct BranchWithArg {
 
 // A builtin instruction, corresponding to instructions like
 // InstId::BuiltinTypeType.
-struct Builtin {
-  // Builtins don't have a parse node associated with them.
+struct BuiltinInst {
+  // Builtin instructions don't have a parse node associated with them.
   static constexpr auto Kind =
-      InstKind::Builtin.Define<Parse::InvalidNodeId>("builtin");
+      InstKind::BuiltinInst.Define<Parse::InvalidNodeId>("builtin");
 
   TypeId type_id;
-  BuiltinKind builtin_kind;
+  BuiltinInstKind builtin_inst_kind;
 };
 
 // An abstract `callee(args)` call, where the callee may be a function, but