tqchen commented on code in PR #601: URL: https://github.com/apache/tvm-ffi/pull/601#discussion_r3326944381
########## src/ffi/extra/structural_visit.cc: ########## @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*! + * \file src/ffi/extra/structural_visit.cc + * \brief Structural visit implementation. + */ +#include <tvm/ffi/container/array.h> +#include <tvm/ffi/container/dict.h> +#include <tvm/ffi/container/list.h> +#include <tvm/ffi/container/map.h> +#include <tvm/ffi/extra/structural_visit.h> +#include <tvm/ffi/function.h> +#include <tvm/ffi/reflection/accessor.h> +#include <tvm/ffi/reflection/registry.h> + +namespace tvm { +namespace ffi { + +namespace details { + +// --------------------------------------------------------------------------- +// StructuralVisitor helpers. +// --------------------------------------------------------------------------- + +// Type-attr hooks store an ABI structural visit callback as an opaque pointer. +using FStructuralVisit = TVMFFIAny (*)(StructuralVisitorObj* visitor, const Object* value) noexcept; + +/*! + * \brief Try to visit \p value using a type-specific structural visit hook. + * + * \param visitor The active visitor. + * \param value The object being visited. + * \param attr The registered type attribute for \p value. + * \param handled Set to true if \p attr represents a structural visit hook. + * \return Expected interrupt state. An error means traversal failed. + */ +Expected<Optional<VisitInterrupt>> TryVisitWithTypeAttr(StructuralVisitorObj* visitor, + const ObjectRef& value, AnyView attr, + bool* handled) { Review Comment: this can be inlined into the caller -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
