tqchen commented on code in PR #49:
URL: https://github.com/apache/tvm-ffi/pull/49#discussion_r2376743592
##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -261,29 +263,53 @@ cdef inline object make_ret_opaque_object(TVMFFIAny
result):
(<Object>obj).chandle = result.v_obj
return obj.pyobject()
+cdef inline object make_fallback_cls_for_type_index(int32_t type_index):
+ cdef str type_key = _type_index_to_key(type_index)
+ cdef object type_info = _lookup_type_info_from_type_key(type_key)
+ cdef object parent_type_info = type_info.parent_type_info
+ cdef object cls
+ cdef dict ann
+
+ assert type_info.type_cls is None
+ assert parent_type_info is not None
+
+ warnings.warn(
+ f"Returning type `{type_key}` which is not registered via
`@register_object`, "
+ f"falling back to auto-generated
prototype:\n{type_info.prototype_py()}",
+ )
+
+ from tvm_ffi.dataclasses import c_class
Review Comment:
this is a reverse dep, ideally we want to bring up related c_class logics to
type_info.pxi so we don't have such reverse dep
##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -261,29 +263,53 @@ cdef inline object make_ret_opaque_object(TVMFFIAny
result):
(<Object>obj).chandle = result.v_obj
return obj.pyobject()
+cdef inline object make_fallback_cls_for_type_index(int32_t type_index):
+ cdef str type_key = _type_index_to_key(type_index)
+ cdef object type_info = _lookup_type_info_from_type_key(type_key)
+ cdef object parent_type_info = type_info.parent_type_info
+ cdef object cls
+ cdef dict ann
+
+ assert type_info.type_cls is None
+ assert parent_type_info is not None
+
+ warnings.warn(
+ f"Returning type `{type_key}` which is not registered via
`@register_object`, "
+ f"falling back to auto-generated
prototype:\n{type_info.prototype_py()}",
Review Comment:
likely we want to remove warning onwards since we might explicitly relyon
this behavior
##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -109,6 +110,50 @@ class TypeInfo:
type_cls: Optional[type]
type_index: int
type_key: str
+ type_ancestors: list[int]
fields: list[TypeField]
methods: list[TypeMethod]
parent_type_info: Optional[TypeInfo]
+
+ def __post_init__(self):
+ cdef int parent_type_index
+ cdef str parent_type_key
+ if not self.type_ancestors:
+ return
+ parent_type_index = self.type_ancestors[-1]
+ parent_type_key = _type_index_to_key(parent_type_index)
+ self.parent_type_info =
_lookup_type_info_from_type_key(parent_type_key) # ensure parent is registered
+
+ def prototype_py(self) -> str:
+ """Generate Python source code for a prototype class of this type.
+
+ The generated class will have the correct inheritance structure and
+ field definitions, but will not have any method definitions.
Review Comment:
not sure if the string building is needed here specifically for this, likely
not?
--
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]