tvm
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | List of all members
tvm::ObjectMutator Class Reference

Native mutation with exact dispatch and structural fallback. More...

#include <object_functor.h>

Inheritance diagram for tvm::ObjectMutator:
Collaboration diagram for tvm::ObjectMutator:

Public Member Functions

 ObjectMutator ()
 Construct a mutator using structural fallback for every object.
 
 ObjectMutator (const ObjectMutator &other)=delete
 
ObjectMutator & operator= (const ObjectMutator &other)=delete
 
virtual UnchangedOr< ffi::Any > Mutate (ffi::AnyView value, InplaceMode inplace_mode=InplaceMode::kDisallow)
 Mutate a borrowed value, throwing on failure.
 
Expected< UnchangedOr< ffi::Any > > MutateExpected (ffi::AnyView value, InplaceMode inplace_mode=InplaceMode::kDisallow) noexcept
 Adapt the virtual throwing entrypoint to the structural ABI.
 
ffi::Any VarRemapGet (ffi::AnyView var)
 Look up a variable replacement, throwing on failure.
 
void VarRemapSet (ffi::AnyView var, ffi::AnyView value)
 Record a variable replacement, throwing on failure.
 
TVM_FFI_INLINE Expected< ffi::Any > VarRemapGetExpected (ffi::AnyView var) noexcept
 Look up a replacement in the variable-remap environment.
 
TVM_FFI_INLINE Expected< void > VarRemapSetExpected (ffi::AnyView var, ffi::AnyView mapped_value) noexcept
 Record a replacement in the variable-remap environment.
 

Protected Types

using VTable = ObjectFunctor< UnchangedOr< ffi::Any >(const ffi::Object *, ObjectMutator *, InplaceMode)>
 Exact native dispatch table with owning replacement results.
 

Protected Member Functions

 ObjectMutator (const VTable *vtable)
 Construct a mutator with a finalized native dispatch table.
 

Static Protected Member Functions

static void InitVTable (VTable *vtable)
 Initialize the base registrations in a fresh mutable table.
 
template<typename Self , typename Node >
static void SetDispatch (VTable *vtable)
 Register an exact node type in a fresh table initialized by its parent. Derived node types require separate registrations.
 

Detailed Description

Native mutation with exact dispatch and structural fallback.

Allocate mutators with ffi::make_object<Derived>(). Inputs are borrowed; replacements and errors own their values. Overrides forward inplace_mode to child calls, following the structural mutation ownership contract.

Member Typedef Documentation

◆ VTable

using tvm::ObjectMutator::VTable = ObjectFunctor<UnchangedOr<ffi::Any>(const ffi::Object*, ObjectMutator*, InplaceMode)>
protected

Exact native dispatch table with owning replacement results.

Constructor & Destructor Documentation

◆ ObjectMutator() [1/3]

tvm::ObjectMutator::ObjectMutator ( )
inline

Construct a mutator using structural fallback for every object.

◆ ObjectMutator() [2/3]

tvm::ObjectMutator::ObjectMutator ( const ObjectMutator &  other)
delete

◆ ObjectMutator() [3/3]

tvm::ObjectMutator::ObjectMutator ( const VTable *  vtable)
inlineexplicitprotected

Construct a mutator with a finalized native dispatch table.

Parameters
vtableThe immutable table, which must outlive this mutator.

Member Function Documentation

◆ InitVTable()

static void tvm::ObjectMutator::InitVTable ( VTable *  vtable)
inlinestaticprotected

Initialize the base registrations in a fresh mutable table.

Parameters
vtableThe table to initialize before adding derived registrations.

◆ Mutate()

virtual UnchangedOr< ffi::Any > tvm::ObjectMutator::Mutate ( ffi::AnyView  value,
InplaceMode  inplace_mode = InplaceMode::kDisallow 
)
inlinevirtual

Mutate a borrowed value, throwing on failure.

Parameters
valueThe borrowed object or inline value to mutate.
inplace_modeInherited permission along the path to this value.
Returns
An owning replacement or Unchanged. Non-object inputs return their inline value.
Note
Establishes uniqueness before invoking typed hooks. Entry overrides must preserve inherited denial and check uniqueness before writing or forwarding permission. Qualified Parent::Mutate bypasses the current override while descendants remain virtual. Completed in-place changes are not rolled back on error.

In-place mutation requires every node and owning container on the root-to-current path to be unique. Inherited inplace_mode records ancestor permission; Mutate checks the current target. Never promote inherited denial to permission. Within a Mutate_ hook, forward mode to a parent hook or an immediate child:

Parent_::Mutate_(node, mode); // The current node was already checked.
Mutate(node->elem, mode); // Mutate checks elem's uniqueness.
virtual UnchangedOr< ffi::Any > Mutate(ffi::AnyView value, InplaceMode inplace_mode=InplaceMode::kDisallow)
Mutate a borrowed value, throwing on failure.
Definition object_functor.h:380

Direct descent that skips an owning ancestor must check that ancestor too:

auto child_mode = node->elem.unique() ? mode : InplaceMode::kDisallow;
Mutate(node->elem->a, child_mode);

When in doubt, omit inplace_mode. The default kDisallow is always safe; pass permission explicitly only when the full ancestor path is accounted for.

Reimplemented in tvm::ExprMutator.

◆ MutateExpected()

Expected< UnchangedOr< ffi::Any > > tvm::ObjectMutator::MutateExpected ( ffi::AnyView  value,
InplaceMode  inplace_mode = InplaceMode::kDisallow 
)
inlinenoexcept

Adapt the virtual throwing entrypoint to the structural ABI.

Parameters
valueThe borrowed value to mutate.
inplace_modeInherited mutation permission.
Returns
The replacement, Unchanged, or the caught error.
Note
Matches the FFI safe-call exception contract. Error identity is preserved; other standard exceptions become InternalError.

◆ operator=()

ObjectMutator & tvm::ObjectMutator::operator= ( const ObjectMutator &  other)
delete

◆ SetDispatch()

template<typename Self , typename Node >
static void tvm::ObjectMutator::SetDispatch ( VTable *  vtable)
inlinestaticprotected

Register an exact node type in a fresh table initialized by its parent. Derived node types require separate registrations.

Template Parameters
SelfThe mutator implementing the hook.
NodeThe exact node type handled by the hook.
Parameters
vtableThe mutable table to receive the registration.

◆ VarRemapGet()

ffi::Any tvm::ObjectMutator::VarRemapGet ( ffi::AnyView  var)
inline

Look up a variable replacement, throwing on failure.

◆ VarRemapGetExpected()

TVM_FFI_INLINE Expected< ffi::Any > tvm::ObjectMutator::VarRemapGetExpected ( ffi::AnyView  var)
inlinenoexcept

Look up a replacement in the variable-remap environment.

Parameters
varThe borrowed variable identity to look up.
Returns
The owning replacement, None on a miss, or an Error.

◆ VarRemapSet()

void tvm::ObjectMutator::VarRemapSet ( ffi::AnyView  var,
ffi::AnyView  value 
)
inline

Record a variable replacement, throwing on failure.

◆ VarRemapSetExpected()

TVM_FFI_INLINE Expected< void > tvm::ObjectMutator::VarRemapSetExpected ( ffi::AnyView  var,
ffi::AnyView  mapped_value 
)
inlinenoexcept

Record a replacement in the variable-remap environment.

Parameters
varThe borrowed variable identity to bind.
mapped_valueThe borrowed replacement value.
Returns
Successful completion or an Error.

The documentation for this class was generated from the following file: