Define TVM_FFI_S_VISIT_MAYBE_EARLY_RETURN

Define TVM_FFI_S_VISIT_MAYBE_EARLY_RETURN#

Define Documentation#

TVM_FFI_S_VISIT_MAYBE_EARLY_RETURN(Result)#

Return from a visit hook if Result stops traversal.

Propagates an Error or a VisitInterrupt out of the enclosing function and otherwise falls through. The stopping result is moved directly into the enclosing Optional or Expected return type.

A registered __s_visit__ hook is one line per traversed field followed by the terminal return. A field skipped on purpose is guarded by a condition and carries a // skips: note saying why.

Expected<Optional<VisitInterrupt>> FooVisit(StructuralVisitorObj* visitor,
                                            AnyView value) noexcept {
const FooNode* self =
      detail::AnyUnsafe::RawObjectPtrFromAnyViewAfterCheck<const FooNode>(value);
TVM_FFI_S_VISIT_MAYBE_EARLY_RETURN(visitor->VisitExpected(self->a));
TVM_FFI_S_VISIT_MAYBE_EARLY_RETURN(visitor->VisitExpected(self->b));
return Optional<VisitInterrupt>(std::nullopt);
}
FStructuralVisit hook =
FStructuralVisit::FromNative<&FooVisit>();
Expected<Optional<VisitInterrupt>> result = hook.CallExpected(visitor, value);
Parameters:
  • Result – An expression yielding the descent result to inspect.