tvm_ffi.StructuralMutator#

class tvm_ffi.StructuralMutator(*args, **kwargs)#

Bases: Object

Low-level structural mutator.

This class exposes the mutator object used by structural-map and custom mutation hooks.

Parameters:
  • args (Any)

  • kwargs (Any)

mutate(value)#

Mutate value without modifying it in place.

The original value is returned when none of its structural fields change; otherwise, the result is a mutated copy.

Parameters:

value (Any) – Value to mutate.

Returns:

result – The mutated owning value.

Return type:

Any

default_mutate(value)#

Mutate value using its registered or reflected default behavior.

This bypasses the active engine callback for value itself while recursive children re-enter the same mutator. A structural_mutate callback may use it on its matched value to request default descent.

Parameters:

value (Any) – Value whose default mutation should run.

Returns:

result – The mutated owning value.

Return type:

Any

var_remap_get(var)#

Return the replacement recorded for a variable identity.

Parameters:

var (Object) – Variable identity to look up. It must be an object-backed value with free-variable or DAG-node structural metadata.

Returns:

result – The recorded replacement, or None if var has no replacement.

Return type:

Any | None

var_remap_set(var, mapped_value)#

Record or replace the substitution for a variable identity.

Parameters:
  • var (Object) – Variable identity to bind. It must be an object-backed value with free-variable or DAG-node structural metadata.

  • mapped_value (Any) – Replacement returned for subsequent lookups of var.

Return type:

None

def_region_kind()#

Return the currently active structural def-region kind.

Returns:

kind – The active DefRegionKind.

Return type:

DefRegionKind

with_def_region_kind(kind, callback)#

Run callback with a temporarily active def-region kind.

Parameters:
  • kind (int) – Def-region kind to use while running callback.

  • callback (Callable[[], Any]) – Nullary callable to execute inside the scoped region.

Returns:

result – The value returned by callback.

Return type:

Any