Class OpDef#
Defined in File op.h
Class Documentation#
-
class OpDef#
Noncopyable temporary builder for a canonical Op; see Op for the example.
Public Functions
-
explicit OpDef(const ffi::String &name)#
Get or create the named Op without changing its documentation.
- Parameters:
name – The canonical operator name.
-
OpDef(const ffi::String &name, const ffi::String &doc)#
Get or create the named Op and set its documentation.
- Parameters:
name – The canonical operator name.
doc – Operator documentation, replacing any existing documentation.
-
inline Op op() const#
Get the canonical operator.
- Returns:
A copied handle, safe after this builder dies.
-
inline void expose() const#
Request API exposure after this operator’s signature and attributes are complete.
Note
Does nothing if the optional receiver was absent on Op::Expose’s first call.
-
OpDef &add_arg(const ffi::String &name, const ffi::String &doc)#
Append a required value-argument descriptor.
- Parameters:
name – Argument name.
doc – Argument documentation.
- Returns:
This builder. Without a variadic descriptor, this is part of the complete list.
-
template<typename AttrsType>
inline OpDef &attrs_type()# Set the attribute object type key and runtime index together.
- Template Parameters:
AttrsType – The attribute object node type.
- Returns:
This builder.
-
OpDef &add_ty_arg(const ffi::String &name, const ffi::String &doc)#
Append a descriptor for a type argument in Call.ty_args.
- Parameters:
name – Type-argument name.
doc – Type-argument documentation.
- Returns:
This builder. Inference retains responsibility for type-argument counts.
-
template<typename ...Specs>
inline OpDef &signature(const Specs&... specs)# Register a complete typed Call signature and its validator.
Fixed descriptors require exactly one value/type argument each. A variadic tail accepts zero or more trailing arguments of its category. Validation throws on arity or class mismatch; it does not infer types or mutate the Call. Call::Validate invokes the validator separately from construction. Without call_attrs<T>, Call.attrs is unconstrained. Repeated registration replaces metadata but retains any existing validator, including a generated one. Replace the callback explicitly if its executable checks must change.
OpDef("example.op") .signature( sig::arg("value"), sig::arg<PrimExpr>("index"), sig::var_args<PrimExpr>("rest"), sig::ty_arg("T"), sig::var_ty_args("Ts"), sig::call_attrs<DictAttrsObj>());
-
template<typename ValueType>
inline OpDef &set_attr(const ffi::String &attr_name, const ValueType &value, bool override = false)# Register an extensible attribute, rejecting duplicates unless overridden.
- Template Parameters:
ValueType – The attribute value type.
- Parameters:
attr_name – Attribute column name.
value – Non-null attribute value.
override – Whether to replace an existing value; no prior value is retained.
- Returns:
This builder. Existing cached maps observe the new value.
-
template<typename ValueType, typename Value, std::enable_if_t<(std::is_convertible_v<Value&&, ValueType> && ((!std::is_same_v<std::decay_t<Value>, ffi::Any> && !std::is_same_v<std::decay_t<Value>, ffi::AnyView>) || std::is_same_v<ValueType, ffi::Any> || std::is_same_v<ValueType, ffi::AnyView>)), int> = 0>
inline OpDef &set_attr(ffi::reflection::AttrKey<ValueType> key, Value &&value, bool override = false)# Register a value using the key’s declared type.
- Parameters:
key – Attribute column key.
value – Value convertible to the key’s type; erased values require explicit extraction.
override – Whether to replace an existing value.
- Returns:
This builder. Stored callbacks retain their packed function owner.
-
template<auto Fn, typename ValueType>
inline OpDef &set_native_fn_attr(ffi::reflection::AttrKey<ValueType> key, bool override = false)# Register a native callback using the key’s declared adapter.
- Template Parameters:
Fn – The native callback.
- Parameters:
key – Attribute column key.
override – Whether to replace an existing value.
- Returns:
This builder.
-
inline OpDef &set_validator(ffi::reflection::NativeFunctionView<void(const CallObj*)> validator, bool override = false)#
Register a validator that checks a Call with this operator.
The callback accepts a
const CallObj*and reports invalid input by throwing or returning anExpected<void>error. A native function pointer can be bound with NativeFunctionView::FromNative. A borrowed packed function may also be passed while it remains alive for this call. The setter retains an owning copy, so the original packed function may then be destroyed. Call::Validate invokes it explicitly; Relax normalization and well-formedness also validate when inputs are ready. A signature installs its generated validator only if none is registered, so a custom validator registered first takes precedence. Replacing a generated or custom validator requires override; duplicate registration without override raises ValueError. NativeFunctionView cannot be null.- Parameters:
validator – Callback to install.
override – Whether to replace the current validator.
- Returns:
This builder.
-
explicit OpDef(const ffi::String &name)#