tqchen commented on code in PR #647:
URL: https://github.com/apache/tvm-ffi/pull/647#discussion_r3486209481


##########
include/tvm/ffi/container/tuple.h:
##########
@@ -338,10 +338,8 @@ struct TypeTraits<Tuple<Types...>> : public 
ObjectRefTypeTraitsBase<Tuple<Types.
   }
 };
 
-namespace details {
 template <typename... T, typename... U>
-inline constexpr bool type_contains_v<Tuple<T...>, Tuple<U...>> = 
(type_contains_v<T, U> && ...);
-}  // namespace details
+inline constexpr bool type_subsumes_v<Tuple<T...>, Tuple<U...>> = 
(type_subsumes_v<T, U> && ...);

Review Comment:
   Fixed in 32d8c49. The Tuple specialization now checks pack arity with `if 
constexpr` before instantiating the element-wise fold, so unequal packs 
evaluate to `false` instead of causing a compilation error. Added compile-time 
negative coverage for both shorter-target and longer-target cases alongside the 
existing positive cases.



##########
include/tvm/ffi/type_traits.h:
##########
@@ -118,22 +118,39 @@ inline std::string TypeIndexToTypeKey(int32_t type_index) 
{
   return std::string(type_info->type_key.data, type_info->type_key.size);
 }
 
-namespace details {
 /*!
- * \brief Check whether `Derived` can reuse `Base` storage directly.
+ * \brief Whether TargetType subsumes SourceType for direct storage reuse.
  *
- * \tparam Base The base type.
- * \tparam Derived The derived type.
- * \return True if Derived's storage can be used as Base's storage, false 
otherwise.
+ * The target type is first and the source type is second. The result is true
+ * exactly when every SourceType value can reuse TargetType storage without
+ * conversion.
+ *
+ * \tparam TargetType The target storage type.
+ * \tparam SourceType The source value type.
  */
-template <typename Base, typename Derived>
-inline constexpr bool type_contains_v =
-    std::is_base_of_v<Base, Derived> || std::is_same_v<Base, Derived>;
+template <typename TargetType, typename SourceType>
+inline constexpr bool type_subsumes_v =
+    std::is_base_of_v<TargetType, SourceType> || std::is_same_v<TargetType, 
SourceType>;
 
 // Special case for Any, which can store any compatible value directly.
-template <typename Derived>
-inline constexpr bool type_contains_v<Any, Derived> = true;
-}  // namespace details
+template <typename SourceType>
+inline constexpr bool type_subsumes_v<Any, SourceType> = true;
+
+/*!
+ * \brief Whether RefType contains every ObjectType instance.
+ *
+ * The containing reference type is first and the contained object type is
+ * second. The default is true exactly when RefType has an exact container type
+ * and ObjectType derives from that container type. Direct specializations can
+ * provide the proof for non-exact reference types.
+ *
+ * \tparam RefType The object reference type.
+ * \tparam ObjectType The object type.
+ */
+template <typename RefType, typename ObjectType>
+inline constexpr bool object_ref_contains_v =
+    RefType::_type_container_is_exact &&
+    std::is_base_of_v<typename RefType::ContainerType, ObjectType>;

Review Comment:
   Fixed in 32d8c49. `object_ref_contains_v` now lives in `object.h` and checks 
the ObjectRef/Object domains before accessing reference metadata, so primitive 
and wrong-category instantiations evaluate to `false`. The API remains a 
directly specializable inline variable template with no struct customization 
layer, and compile-time positive/negative coverage includes primitive, 
node-as-ref, and primitive-as-node cases.



-- 
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]

Reply via email to