tqchen commented on code in PR #663:
URL: https://github.com/apache/tvm-ffi/pull/663#discussion_r3575710057
##########
include/tvm/ffi/reflection/registry.h:
##########
Review Comment:
call RegisterTypeAttrValue
##########
include/tvm/ffi/reflection/registry.h:
##########
@@ -1004,16 +1104,32 @@ class TypeAttrDef : public ReflectionDefBase {
*
* \return The TypeAttrDef object.
*/
- template <typename Func>
+ template <typename Func, std::enable_if_t<!std::is_convertible_v<Func&&,
AnyView> &&
+
!std::is_convertible_v<std::decay_t<Func>, AnyView>,
+ int> = 0>
TypeAttrDef& def(const char* name, Func&& func) {
- TVMFFIByteArray name_array = {name, std::char_traits<char>::length(name)};
ffi::Function ffi_func =
GetMethod(std::string(type_key_) + "." + name,
std::forward<Func>(func));
- TVMFFIAny value_any = AnyView(ffi_func).CopyToTVMFFIAny();
- TVM_FFI_CHECK_SAFE_CALL(TVMFFITypeRegisterAttr(type_index_, &name_array,
&value_any));
+ RegisterTypeAttrValue(type_index_, name, ffi_func);
return *this;
}
+ /*!
+ * \brief Register the standard AnyView conversion type attribute.
+ *
+ * \tparam TSelf The type produced by the conversion.
+ *
+ * \return The TypeAttrDef object.
+ */
+ template <typename TSelf>
+ TVM_FFI_INLINE TypeAttrDef& def_convert() {
+ if constexpr (details::HasContainerType<TSelf>::value) {
+ static_assert(std::is_same_v<typename TSelf::ContainerType, Class>,
+ "TSelf::ContainerType must match TypeAttrDef's object
type");
+ }
+ return def(type_attr::kConvert,
&details::FFIConvertFromAnyViewToObjectRef<TSelf>);
Review Comment:
this seems to be specialized for convert, ideally we dpn't bloat the api
here per ffi key,
def(type_attr::kConvert, &details::FFIConvertFromAnyViewToObjectRef<TSelf>);
is a fast enough oneliner that i think we should remove this one also
removes need of ContainerType
--
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]