junrushao opened a new pull request, #486:
URL: https://github.com/apache/tvm-ffi/pull/486
## Summary
- Expose `RecursiveHash` to the Python FFI API (`_ffi_api.py` stub +
`__all__`)
- Add `TestHash` and `TestCustomHash` reflected test fixture classes to
`tvm_ffi.testing`
- Add comprehensive `test_dataclass_hash.py` covering the full
`RecursiveHash` contract
## Architecture
- Two new reflected test fixture classes registered via C++ reflection:
- **`TestHash`** (`testing.TestHash`): exercises `Hash(false)` field
exclusion on `hash_ignored`
- **`TestCustomHash`** (`testing.TestCustomHash`): exercises
`__ffi_hash__` custom hook (hashes only `key`, ignores `label`)
## Test Coverage
| Category | What's tested |
|---|---|
| Primitives | int, float, bool, str, bytes, None, DataType, Device |
| NaN handling | All NaN payloads hash equal; canonicalization in nested
containers |
| Signed zero | `+0.0` and `-0.0` hash identically |
| Containers | Array, List, Shape, Map, Dict — equal/different/empty/nested |
| Reflected objects | TestIntPair, inherited fields (3-level), objects with
container fields |
| Field exclusion | `Hash(false)` via TestHash; `Compare(false)` implies
hash-off |
| Custom hooks | `__ffi_hash__` via TestCustomHash and TestCustomCompare |
| Cycle detection | Self-referential List/Dict hashing succeeds gracefully |
| Consistency law | `RecursiveEq(a, b) ⟹ RecursiveHash(a) ==
RecursiveHash(b)` — primitives, containers, reflected objects, custom hooks |
| Aliasing invariants | Shared vs duplicated references produce identical
hashes |
| Recursion depth | 127 and 1000 levels of nesting (iterative heap-based
stack) |
| DAG scaling | Shared binary DAG hashing is linear, not exponential
(warm-up + averaged) |
| Guard | `__ffi_eq__` without `__ffi_hash__` raises ValueError |
## Test Plan
- [ ] `uv run pytest -vvs tests/python/test_dataclass_hash.py`
--
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]