From f9ca2ea2d6ac641c58ab8c9f5c69924b95278ac4 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 2 Dec 2024 15:13:03 -0500 Subject: [PATCH] Expose InstKind::FromInt for Inst instead of InstKind::Make (#4611) The Inst type will type erase a specific typed instruction by storing the kind as an integer. It does this by calling InstKind::AsInt on a runtime or compile-time InstKind. Then it returns the kind as InstKind by reconstituting it from the integer. Currently it does a cast to a raw enumerator and then calls InstKind::Make. However Make is designed to be more of an internal detail. The more clearly paired inverse operation is InstKind::FromInt, which is documented as being intended to be exposed by derived classes like InstKind. --- toolchain/sem_ir/inst.h | 4 +--- toolchain/sem_ir/inst_kind.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/toolchain/sem_ir/inst.h b/toolchain/sem_ir/inst.h index f2f3554b8979..ae43afc861af 100644 --- a/toolchain/sem_ir/inst.h +++ b/toolchain/sem_ir/inst.h @@ -208,9 +208,7 @@ class Inst : public Printable { } } - auto kind() const -> InstKind { - return InstKind::Make(static_cast(kind_)); - } + auto kind() const -> InstKind { return InstKind::FromInt(kind_); } // Gets the type of the value produced by evaluating this instruction. auto type_id() const -> TypeId { return type_id_; } diff --git a/toolchain/sem_ir/inst_kind.h b/toolchain/sem_ir/inst_kind.h index 541d9289d0f2..671c90cc0ac9 100644 --- a/toolchain/sem_ir/inst_kind.h +++ b/toolchain/sem_ir/inst_kind.h @@ -103,7 +103,7 @@ class InstKind : public CARBON_ENUM_BASE(InstKind) { constexpr auto Define(DefinitionInfo info) const -> Definition; using EnumBase::AsInt; - using EnumBase::Make; + using EnumBase::FromInt; // Returns true if the kind matches any of the provided instructions' kinds. template