tvm_ffi.structural_visit

tvm_ffi.structural_visit#

tvm_ffi.structural_visit(root, callbacks=())#

Visit a value structurally with callbacks that own child traversal.

Each callback receives (value, visitor). It may call StructuralVisitor.visit() for selected children or StructuralVisitor.default_visit() for the value’s registered/default descent. Returning without either call prunes that value’s subtree.

At the outer error boundary, after recursive traversal collects visit context, errors are offered once to the original input root type’s __ffi_enrich_visit_error__(error, root) hook. Only the exact root dynamic type’s attribute is used; parent types are not searched. The hook receives the original input root and returns the original or enriched FFI error. An absent or failing hook leaves the original error unchanged. Recursive visitor/mutator methods only collect context.

Parameters:
  • root (Any) – Root value to traverse.

  • callbacks (tuple | Sequence | Callable) – A callback, (type, callback) entry, grouped type entry, or sequence of entries. Entries are tried in order and the first match owns descent.

Returns:

result – None if traversal completed, otherwise a VisitInterrupt.

Return type:

VisitInterrupt | None