You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "junrushao (via GitHub)" <gi...@apache.org> on 2026/04/11 19:52:25 UTC

[PR] fix(py_class): propagate parent total_size through empty intermediate classes [tvm-ffi]

junrushao opened a new pull request, #539:
URL: https://github.com/apache/tvm-ffi/pull/539

   ## Summary
   
   - **Bug**: In Python-defined type hierarchies, when an intermediate parent class had no own fields (e.g., `GrandParent(x, y) -> Parent(pass) -> Child(a, b)`), `TypeInfo.total_size` fell back to `sizeof(TVMFFIObject)` (~24 bytes) for the empty parent, ignoring inherited fields. This caused child field offsets to overlap with grandparent field offsets, leading to silent data corruption on read/write.
   - **Fix**: Consult `parent_type_info.total_size` as the floor when computing total size in `TypeInfo.total_size`, ensuring inherited field space is always accounted for. Also changed `total_size` from `@cached_property` to `@property` to avoid caching stale values before the parent chain is fully resolved.
   - **Tests**: Added 6 regression tests in `TestFieldInheritance` covering offset correctness, size propagation, multi-level empty parents, mutation aliasing, and the `@py_class` decorator API.
   
   ## Test plan
   
   - [x] `uv run pytest -vvs tests/python/test_dataclass_py_class.py::TestFieldInheritance` — all 14 tests pass (8 existing + 6 new)
   - [x] All pre-commit hooks pass


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] fix(py_class): propagate parent total_size through empty intermediate classes [tvm-ffi]

Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao merged PR #539:
URL: https://github.com/apache/tvm-ffi/pull/539


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] fix(py_class): propagate parent total_size through empty intermediate classes [tvm-ffi]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #539:
URL: https://github.com/apache/tvm-ffi/pull/539#discussion_r3068516122


##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -697,6 +697,11 @@ class TypeInfo:
         if c_info != NULL and c_info.metadata != NULL:
             return c_info.metadata.total_size
         cdef int64_t end = sizeof(TVMFFIObject)
+        # Account for parent's total size (inherited fields)
+        if self.parent_type_info is not None:
+            parent_size = self.parent_type_info.total_size

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For better performance and consistency with other parts of this file (e.g., line 959), consider explicitly typing `parent_size` as `int64_t`. This avoids unnecessary Python object overhead during the comparison with `end` and the subsequent assignment.
   
   ```
               cdef int64_t parent_size = self.parent_type_info.total_size
   ```



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org