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


##########
include/tvm/ffi/function_details.h:
##########
@@ -204,6 +217,39 @@ TVM_FFI_INLINE static Error MoveFromSafeCallRaised() {
 TVM_FFI_INLINE static void SetSafeCallRaised(const Error& error) {
   
TVMFFIErrorSetRaised(details::ObjectUnsafe::TVMFFIObjectPtrFromObjectRef(error));
 }
+
+template <typename T>
+struct TypeSchemaImpl {
+  static std::string v() {
+    using U = std::remove_const_t<std::remove_reference_t<T>>;
+    return TypeTraits<U>::TypeSchema();
+  }
+};
+
+template <>
+struct TypeSchemaImpl<void> {
+  static std::string v() {
+    return "{\"type\":\"" + std::string(StaticTypeKey::kTVMFFINone) + "\"}";
+  }
+};
+
+template <>
+struct TypeSchemaImpl<Any> {
+  static std::string v() { return "{\"type\":\"" + 
std::string(StaticTypeKey::kTVMFFIAny) + "\"}"; }
+};
+
+template <>
+struct TypeSchemaImpl<AnyView> {
+  static std::string v() { return "{\"type\":\"" + 
std::string(StaticTypeKey::kTVMFFIAny) + "\"}"; }
+};
+
+template <>
+struct TypeSchemaImpl<Function> {

Review Comment:
   should it be covered by generic impl for ObjectRef?



##########
include/tvm/ffi/reflection/registry.h:
##########
@@ -35,13 +38,37 @@ namespace tvm {
 namespace ffi {
 /*! \brief Reflection namespace */
 namespace reflection {
-
 /*!
  * \brief Trait that can be used to set field info
  * \sa DefaultValue, AttachFieldFlag
  */
 struct FieldInfoTrait {};
 
+/*! \brief User-supplied metadata attached to a field or a method */
+class Metadata : public FieldInfoTrait {

Review Comment:
   ideally we want to keep reflection not depend on extra, i know it can be a 
bit painful, but hopefully we can string stitching here



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -58,6 +59,80 @@ cdef class FieldSetter:
             raise_existing_error()
         raise move_from_last_error().py_error()
 
+_TYPE_SCHEMA_ORIGIN_CONVERTER = {
+    # A few Python-native types
+    "Variant": "Union",
+    "Optional": "Optional",
+    "Tuple": "tuple",
+    "ffi.Function": "Callable",
+    "ffi.Array": "list",
+    "ffi.Map": "dict",
+    "ffi.OpaquePyObject": "Any",
+    # ctype types
+    "void*": "ctypes.c_void_p",
+    # bytes
+    "TVMFFIByteArray*": "bytes",
+    "ffi.SmallBytes": "bytes",
+    "ffi.Bytes": "bytes",
+    # strings
+    "const char*": "str",
+    "ffi.SmallStr": "str",
+    "ffi.String": "str",
+}

Review Comment:
   we need DLTensor* after latest TensorView bring up, can simply map to 
ffi.Tensor for now



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