tvm_ffi.StructuralVisitor#

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

Bases: Object

Low-level structural traversal visitor.

This class exposes the low-level visitor object used by structural traversal hooks. Instances are supplied by an active traversal and cannot be constructed directly.

Parameters:
  • args (Any)

  • kwargs (Any)

visit(value)#

Low-level API to visit value using this visitor’s dispatch behavior.

Parameters:

value (Any) – Value to visit.

Returns:

result – None if traversal should continue, otherwise a VisitInterrupt carrying the early-exit payload.

Return type:

VisitInterrupt | None

default_visit(value)#

Visit value using its registered or reflected child traversal.

Warning

Never call default_visit on the value whose __s_visit__ hook is currently running. Doing so re-enters the same hook recursively and can exhaust the C stack, crashing the process.

This bypasses the active engine callback dispatch for value itself, but still invokes the value type’s registered __s_visit__ hook when one exists. Use it for a child whose default traversal is wanted. Recursive children still use this visitor.

Parameters:

value (Any) – Value whose default children should be traversed.

Returns:

result – None if traversal should continue, otherwise a VisitInterrupt carrying the early-exit payload.

Return type:

VisitInterrupt | None

def_region_kind()#

Low-level API to return the currently active structural def-region kind.

Returns:

kind – The active DefRegionKind.

Return type:

DefRegionKind

with_def_region_kind(kind, callback)#

Low-level API to 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