Class StructuralVisitorObj#

Inheritance Relationships#

Base Type#

Derived Type#

  • public tvm::ffi::details::StructuralWalkCallbackVisitorObj< order, Dispatch >

Class Documentation#

class StructuralVisitorObj : public tvm::ffi::Object#

Object node of a structural visitor.

A structural visitor is an active traversal context. It carries the dispatch table used to visit each object and the current def-region state used by structural equality/hash semantics. The visitor is ref-counted so it can cross FFI boundaries, but one underlying visitor object should not be shared by overlapping top-level traversals.

Subclassed by tvm::ffi::details::StructuralWalkCallbackVisitorObj< order, Dispatch >

Public Functions

inline StructuralVisitorObj()#

Construct the default structural visitor.

inline Optional<VisitInterrupt> Visit(AnyView value)#

Visit a value, dispatching through this visitor’s vtable.

Parameters:

value – The value to visit.

Returns:

std::nullopt to continue traversal, or a VisitInterrupt to halt the entire visit.

inline Expected<Optional<VisitInterrupt>> VisitExpected(AnyView value) noexcept#

Visit a value, propagating error through expected return.

Parameters:

value – The value to visit.

Returns:

Expected interrupt state. An error means traversal failed.

inline Optional<VisitInterrupt> DefaultVisit(AnyView value)#

Visit using the structural visit behavior registered by kStructuralVisit for each type, or reflected structural fields when no custom behavior is registered.

inline Expected<Optional<VisitInterrupt>> DefaultVisitExpected(AnyView value) noexcept#

Visit using the registered structural visit behavior by kStructuralVisit, propagating errors by Expected.

Parameters:

value – The value to visit.

Returns:

Expected interrupt state. An error means traversal failed.

inline TVMFFIDefRegionKind def_region_kind() const#

Return the current def-region context.

Returns:

The active def-region kind.

template<typename Callback>
inline auto WithDefRegionKind(TVMFFIDefRegionKind kind, Callback &&callback)#

Temporarily switch the def-region context while invoking callback.

This helper scopes updates to the traversal state used by def/use-region aware visitors. The previous state is restored when the callback returns or throws.

Parameters:
  • kind – The def-region kind to set during the callback.

  • callback – A nullary callable that performs recursive visiting.

Returns:

The value returned by callback.

Protected Functions

inline explicit StructuralVisitorObj(const StructuralVisitorVTable *vtable)#

Construct a structural visitor subclass with a custom dispatch vtable.

Note

This constructor is for internal subclasses. The vtable and its visit callback must be valid for the lifetime of the visitor.

Parameters:

vtable – The non-null dispatch table for this visitor.

Protected Attributes

const StructuralVisitorVTable *vtable_ = nullptr#

Required ABI dispatch table. StructuralVisitorVTable It must never be null on a constructed visitor.

TVMFFIDefRegionKind def_region_mode_ = kTVMFFIDefRegionKindNone#

Current def-region context for structural equality/hash semantics.

This is shared mutable traversal state. Be careful when mutating it through multiple references to the same visitor object. Use WithDefRegionKind to scope temporary changes.