Template Class EnumDef#

Inheritance Relationships#

Base Type#

  • public ReflectionDefBase

Class Documentation#

template<typename EnumClsObj, typename = std::enable_if_t<std::is_base_of_v<EnumObj, EnumClsObj>>>
class EnumDef : public ReflectionDefBase#

Builder that registers a single enum instance on EnumClsObj.

Each EnumDef<EnumClsObj>("Name") call allocates a fresh dense ordinal (= len(existing entries)), constructs a variant with _value and _name populated, and writes it into the per-class registry stored in the type_attr::kEnumEntries TypeAttr column. Subsequent .set_attr(...) calls write extensible attributes — per-variant metadata attached outside the variant’s declared fields — into the per-class type_attr::kEnumAttrs column. Python bindings of the same type_key see every C++-registered variant and every extensible attribute through the matching Enum.def_attr surface.

namespace refl = ::tvm::ffi::reflection;
refl::EnumDef<OpObj>("Add").set_attr("has_side_effects", false);
refl::EnumDef<OpObj>("Mul").set_attr("has_side_effects", false);

Template Parameters:

EnumClsObj – An Object subclass deriving from EnumObj.

Public Functions

inline explicit EnumDef(const char *instance_name)#

Register a new instance named instance_name on EnumClsObj.

Parameters:

instance_name – The instance’s string name (e.g., "Add").

template<typename T>
inline EnumDef &set_attr(const char *attr_name, T value)#

Write an extensible attribute for this enum variant.

Writes land in the per-class type_attr::kEnumAttrs column and are visible to every binder of the same type_key — including Python readers via Enum.def_attr / Enum.attr_dict. Distinct from declared fields on EnumClsObj: declared fields are part of the variant’s schema and set during construction, whereas extensible attributes live outside the variant object and may be attached by any consumer at any time.

Template Parameters:

T – The value type.

Parameters:
  • attr_name – The extensible-attribute name (e.g., "has_side_effects").

  • value – The value to store for this variant’s ordinal.

Returns:

Reference to this builder for chaining.

inline Enum instance() const#

Return the registered instance (for tests / advanced callers).

inline int64_t ordinal() const#

Return the ordinal assigned to this instance.