Template Function tvm::ffi::StructuralMutateExpected#
Defined in File structural_mutate.h
Function Documentation#
-
template<typename ...Callbacks>
Expected<Any> tvm::ffi::StructuralMutateExpected(Any root, Callbacks&&... callbacks) noexcept# Mutate a structured value with callbacks that own recursion.
A callback takes one of two forms, where
Ris a supported return type:R(const T& value, StructuralMutatorObj* mutator)R(const T& value, StructuralMutatorObj* mutator, InplaceMode inplace_mode)
A callback returns a replacement,
Unchanged, orExpected<Any>. The first argument selects by FFI type; callbacks are tried in declaration order and the first match owns mutation — it drives its own recursion through the mutator and sets any variable remapping. An unmatched value takes registered or reflected default mutation.Note
A two-argument callback descends with
MutateExpected(value), using the default copy-on-write permission. A three-argument callback receives InplaceMode::kAllow only when its value is on a uniquely owned path. Forward this mode toMutateExpectedfor child values orDefaultMutateExpectedfor the current value’s default descent.Note
Pass an owned root with
std::move(root)to permit root reuse. In a__s_maybe_inplace_mutate__hook, the corresponding nested idiom isself->field = StructuralMap(std::move(self->field), callback); const-correctness rejects that ownership transfer outside a mutable maybe-in-place hook.- Parameters:
root – The owning root value to mutate.
callbacks – Callbacks tested in declaration order.
- Returns:
The mutated owning value, or an Error if mutation or a callback fails.