junrushao commented on code in PR #670:
URL: https://github.com/apache/tvm-ffi/pull/670#discussion_r3592638199
##########
include/tvm/ffi/object.h:
##########
@@ -546,6 +546,19 @@ inline constexpr bool is_qualified_object_v =
} // namespace details
+/*!
+ * \brief Mark a forward-declared type as an Object subclass.
+ *
+ * Invoke this macro at global namespace scope after forward declaring Type.
+ * Generated ABI headers use it so recursive container fields can instantiate
+ * ObjectPtr traits before the pointee type's definition is complete.
+ *
+ * \param Type The fully qualified Object subclass.
+ */
+#define TVM_FFI_DECLARE_OBJECT_SUBCLASS(Type) \
+ template <> \
+ inline constexpr bool tvm::ffi::details::is_object_subclass_v<Type> = true
Review Comment:
A minimal example of the ordering this enables is:
```cpp
namespace example {
struct NodeObj;
}
template <>
inline constexpr bool
tvm::ffi::is_object_subclass_v<::example::NodeObj> = true;
namespace example {
struct NodeObj : public tvm::ffi::Object {
tvm::ffi::List<tvm::ffi::ObjectPtr<NodeObj>> children;
};
}
```
When `children` is declared, `NodeObj` remains incomplete until the closing
brace. `List` instantiates `TypeTraits<ObjectPtr<NodeObj>>`, so without the
specialization the primary `std::is_base_of_v<Object, NodeObj>` is ill-formed.
Generated headers now follow exactly this forward-declare → specialize → define
ordering.
--
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]