gemini-code-assist[bot] commented on code in PR #127:
URL: https://github.com/apache/tvm-ffi/pull/127#discussion_r2432700394
##########
include/tvm/ffi/reflection/registry.h:
##########
@@ -406,6 +406,56 @@ class GlobalDef : public ReflectionDefBase {
}
};
+/*!
+ * \brief Helper class to register a constructor method for object types.
+ *
+ * This helper is used with `ObjectDef::def()` to register an `__init__` method
+ * that constructs an object instance with the specified argument types.
+ *
+ * \tparam Args The argument types for the constructor.
+ *
+ * Example usage:
+ * \code
+ * class ExampleObject : public Object {
+ * public:
+ * int64_t v_i64;
+ * int32_t v_i32;
+ *
+ * ExampleObject(int64_t v_i64, int32_t v_i32) : v_i64(v_i64),
v_i32(v_i32) {}
+ * TVM_FFI_DECLARE_OBJECT_INFO("example.ExampleObject", ExampleObject,
Object);
+ * };
+ *
+ * // Register the constructor
+ * refl::ObjectDef<ExampleObject>()
+ * .def(refl::init<int64_t, int32_t>());
+ * \endcode
+ *
+ * \note The object type is automatically deduced from the `ObjectDef` context.
+ */
+template <typename... Args>
+struct init {
+ // Allow ObjectDef to access the execute function
+ template <typename Class>
+ friend class ObjectDef;
+
+ /*!
+ * \brief Constructor
+ */
+ init() {}
Review Comment:

The `init` struct's constructor can be marked as `constexpr` and defaulted.
This allows creating `init` instances at compile time, which is a good practice
in modern C++.
```c
constexpr init() = default;
```
##########
include/tvm/ffi/reflection/registry.h:
##########
@@ -504,6 +554,34 @@ class ObjectDef : public ReflectionDefBase {
return *this;
}
+ /*!
+ * \brief Register a constructor for this object type.
+ *
+ * This method registers a static `__init__` method that constructs an
instance
+ * of the object with the specified argument types. The constructor can be
invoked
+ * from Python or other FFI bindings.
+ *
+ * \tparam Args The argument types for the constructor.
+ * \tparam Extra Additional arguments (e.g., docstring).
+ *
+ * \param init_func An instance of `init<Args...>` specifying constructor
signature.
+ * \param extra Optional additional metadata such as docstring.
+ *
+ * \return Reference to this `ObjectDef` for method chaining.
+ *
+ * Example:
+ * \code
+ * refl::ObjectDef<MyObject>()
+ * .def(refl::init<int64_t, std::string>(), "Constructor docstring");
+ * \endcode
+ */
+ template <typename... Args, typename... Extra>
+ TVM_FFI_INLINE ObjectDef& def(init<Args...> init_func, Extra&&... extra) {
Review Comment:

The `init_func` parameter is not used within the function body; it serves
only for template argument deduction. To prevent potential compiler warnings
about unused parameters, it's good practice to mark it with `[[maybe_unused]]`.
```c
TVM_FFI_INLINE ObjectDef& def([[maybe_unused]] init<Args...> init_func,
Extra&&... extra) {
```
--
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]