Define TVM_FFI_S_MUTATE_ASSIGN_OR_RETURN#
Defined in File structural_mutate.h
Define Documentation#
-
TVM_FFI_S_MUTATE_ASSIGN_OR_RETURN(Type, Name, ResultExpr)#
Unwrap a successful mutation result into a newly declared value or return its error.
Typemust be concrete; use a type alias when it contains a top-level comma. A type mismatch returnsTypeErrorthrough the surrounding raw orExpectedfunction without throwing, reported with a fixed string. The check is omitted when the declared type subsumes the result’s success type. Its early returns work from either a rawTVMFFIAnyhook or anExpected<T>helper, including one with a different success type. This macro declaresNameinto the enclosing scope and must be used in a braced block, never as an unbraced control-flow body.Example:
TVMFFIAny FooMutate(StructuralMutatorObj* mutator, AnyView value) noexcept { const FooNode* self = details::AnyUnsafe::RawObjectPtrFromAnyViewAfterCheck<const FooNode>(value); constexpr InplaceMode inplace_mode = InplaceMode::kDisallow; TVM_FFI_S_MUTATE_ASSIGN_OR_RETURN(UnchangedOr<Expr>, a, mutator->MutateExpected(self->a, inplace_mode)); TVM_FFI_S_MUTATE_ASSIGN_OR_RETURN(UnchangedOr<Expr>, b, mutator->MutateExpected(self->b, inplace_mode)); if (a.UnchangedOrSameAs(self->a) && b.UnchangedOrSameAs(self->b)) { return Unchanged().CopyToTVMFFIAny(); } ObjectPtr<FooNode> copy = make_object<FooNode>(*self); copy->a = std::move(a).ValueOrUnchanged(std::move(copy->a)); copy->b = std::move(b).ValueOrUnchanged(std::move(copy->b)); return details::AnyUnsafe::MoveAnyToTVMFFIAny(Any(std::move(copy))); }
Keep one statement per traversed field. A field skipped intentionally must be guarded and carry a
// skips:note.See also
Unchanged::CopyToTVMFFIAny
- Parameters:
Type – The concrete successful value type.
Name – The name of the value declared in the enclosing scope.
ResultExpr – An expression producing the
Expectedvalue to unwrap.