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


##########
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:
   Follow-up from the careful review in 2c522a6: `GetRef` now places its 
implementation in the successful `if constexpr` branch and keeps the 
containment assertion in the rejected branch. Invalid ref and object categories 
therefore stop at the intended `object_ref_contains_v` assertion instead of 
also instantiating `_type_is_nullable` or an invalid object-pointer cast. GCC 
negative probes with `-Werror=return-type` confirm a single focused diagnostic 
for both 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