Skip to content

Commit

Permalink
Expose InstKind::FromInt for Inst instead of InstKind::Make
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danakj committed Dec 2, 2024
1 parent 831dd2c commit 180a55c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions toolchain/sem_ir/inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ class Inst : public Printable<Inst> {
}
}

auto kind() const -> InstKind {
return InstKind::Make(static_cast<InstKind::RawEnumType>(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_; }
Expand Down
2 changes: 1 addition & 1 deletion toolchain/sem_ir/inst_kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class InstKind : public CARBON_ENUM_BASE(InstKind) {
constexpr auto Define(DefinitionInfo info) const -> Definition<TypedNodeId>;

using EnumBase::AsInt;
using EnumBase::Make;
using EnumBase::FromInt;

// Returns true if the kind matches any of the provided instructions' kinds.
template <typename... InstT>
Expand Down

0 comments on commit 180a55c

Please sign in to comment.