tqchen commented on code in PR #676:
URL: https://github.com/apache/tvm-ffi/pull/676#discussion_r3613965592
##########
include/tvm/ffi/any.h:
##########
@@ -871,6 +871,44 @@ struct AnyEqual {
}
};
+// Defer these definitions until any.h so null Arc values can be rejected with
+// TypeError while object.h stays below the error layer.
+//! \cond Doxygen_Suppress
+template <typename TObject>
+TVM_FFI_INLINE void
+TypeTraits<Arc<TObject>, std::enable_if_t<is_object_subclass_v<TObject> &&
+ std::is_same_v<TObject,
std::remove_cv_t<TObject>>>>::
+ CopyToAnyView(const Arc<TObject>& src, TVMFFIAny* result) {
+ const ObjectPtr<TObject>& ptr = src;
+ if (TVM_FFI_PREDICT_FALSE(ptr == nullptr)) {
Review Comment:
do we need this? i think it is easiert to simply rely on assumption and no
runtime check
##########
include/tvm/ffi/any.h:
##########
@@ -871,6 +871,44 @@ struct AnyEqual {
}
};
+// Defer these definitions until any.h so null Arc values can be rejected with
+// TypeError while object.h stays below the error layer.
+//! \cond Doxygen_Suppress
+template <typename TObject>
+TVM_FFI_INLINE void
+TypeTraits<Arc<TObject>, std::enable_if_t<is_object_subclass_v<TObject> &&
+ std::is_same_v<TObject,
std::remove_cv_t<TObject>>>>::
+ CopyToAnyView(const Arc<TObject>& src, TVMFFIAny* result) {
+ const ObjectPtr<TObject>& ptr = src;
+ if (TVM_FFI_PREDICT_FALSE(ptr == nullptr)) {
+ TVM_FFI_THROW(TypeError) << "Cannot convert null Arc to expected object
type `"
+ << TObject::_type_key << "`";
+ }
+ TVMFFIObject* obj_ptr =
details::ObjectUnsafe::TVMFFIObjectPtrFromObjectPtr(ptr);
+ result->type_index = obj_ptr->type_index;
+ result->zero_padding = 0;
+ TVM_FFI_CLEAR_PTR_PADDING_IN_FFI_ANY(result);
+ result->v_obj = obj_ptr;
+}
+
+template <typename TObject>
+TVM_FFI_INLINE void
+TypeTraits<Arc<TObject>, std::enable_if_t<is_object_subclass_v<TObject> &&
+ std::is_same_v<TObject,
std::remove_cv_t<TObject>>>>::
+ MoveToAny(Arc<TObject> src, TVMFFIAny* result) {
+ ObjectPtr<TObject>& ptr = src;
+ if (TVM_FFI_PREDICT_FALSE(ptr == nullptr)) {
+ TVM_FFI_THROW(TypeError) << "Cannot convert null Arc to expected object
type `"
Review Comment:
no runtime check
##########
include/tvm/ffi/object.h:
##########
@@ -1388,6 +1480,51 @@ struct TypeTraits<ObjectPtr<TObject>,
}
};
+/*!
+ * \brief Type traits for a non-null owning pointer to an unqualified Object
subclass.
+ * \tparam TObject The unqualified Object subclass.
+ */
+template <typename TObject>
+struct TypeTraits<Arc<TObject>,
+ std::enable_if_t<is_object_subclass_v<TObject> &&
+ std::is_same_v<TObject,
std::remove_cv_t<TObject>>>>
+ : public TypeTraitsBase {
+ static constexpr int32_t field_static_type_index = TypeIndex::kTVMFFIObject;
+
+ // Defined in any.h so the null-rejection path can use the error layer.
+ TVM_FFI_INLINE static void CopyToAnyView(const Arc<TObject>& src, TVMFFIAny*
result);
Review Comment:
consider simply redirect to CopyToAnyView/MoveToAny, invariance of notnull
is ensured by type and do not ened check t here
##########
include/tvm/ffi/object.h:
##########
@@ -53,6 +53,12 @@ namespace ffi {
*/
struct UnsafeInit {};
+template <typename T>
+class Arc;
Review Comment:
likely this is not needed since it is covered by friend decl in Arc
##########
include/tvm/ffi/object.h:
##########
@@ -53,6 +53,12 @@ namespace ffi {
*/
struct UnsafeInit {};
+template <typename T>
+class Arc;
+
+template <typename T, typename... Args>
+Arc<T> make_arc(Args&&... args);
Review Comment:
needs to be declared with TVM_FFI_INLINE
##########
include/tvm/ffi/object.h:
##########
@@ -53,6 +53,12 @@ namespace ffi {
*/
struct UnsafeInit {};
+template <typename T>
+class Arc;
+
+template <typename T, typename... Args>
+Arc<T> make_arc(Args&&... args);
Review Comment:
likely this is not needed since it is covered by friend decl in Arc
--
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]