junrushao opened a new pull request, #454:
URL: https://github.com/apache/tvm-ffi/pull/454
## Summary
- Add a centralized, reflection-based repr system (`ffi.ReprPrint`) that
handles cycles and DAG duplicates via BFS traversal
- Built-in types (String, Tensor, Shape, Array, List, Map) have custom
formatters; user-defined types fall back to generic reflection-based repr
showing `type_key@0xADDR(field=value, ...)`
- Add `refl::repr_fields({"field_a", "field_b"})` tag struct to restrict
which fields appear in repr output (omitting = show all fields, `{}` = no
fields)
- Python `__repr__` on Object/Array/List/Map now delegates to `ffi.ReprPrint`
- SmallStr/SmallBytes POD types rendered as quoted strings in repr
## Format examples
```
42 # int
"hello world" # string
Tensor.float32[3, 4]@cpu:0@0x1234 # tensor
Shape([5, 6]) # shape
[1, 2, 3] # array/list
{"key": "value"} # map
testing.TestIntPair@0x1234(a=10, b=20) # user object (all fields)
testing.TestCxxClass@0x1234(v_f64=3.5) # user object (repr_fields
subset)
testing.TestIntPair@0x1234 # duplicate reference (short
form)
```
## Test plan
- [x] 17 new tests in `tests/python/test_repr.py` covering primitives,
strings, containers, tensors, shapes, user objects, repr_fields, duplicate
references, Python `__repr__` integration, and empty containers
- [x] Updated existing `test_container.py::test_repr` for new string quoting
format
- [x] Full test suite passes (401 Python tests, 276 C++ tests)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]