Seven-Streams opened a new pull request, #816:
URL: https://github.com/apache/tvm-ffi/pull/816
Stacked on #815 (which is stacked on #804). Only the commits after that
branch belong here; the change is Python and Cython only.
## Summary
A reflected class with a `BigInt` field describes it to Python as
`{"type": "ffi.BigInt"}`, and the Cython `TypeSchema` folds that key into the
`int` origin because a `BigInt` is a Python `int`. The Rust stub generator
only
saw the origin, so it mirrored the 16-byte cell as `i64` and the generated
struct's size assertion failed to compile.
`TypeSchema` now keeps the key a schema was parsed from when the fold loses
information, in a new `type_key` attribute that takes no part in equality or
`repr`. One table, `_TYPE_INDEX_TO_RETAINED_TYPE_KEY`, names such folds;
today
that is `ffi.BigInt` alone. `from_json_obj` and `from_type_index` both set
it,
`to_json` writes it back so a parse and serialize round trip is lossless, and
`NamedTypeSchema` carries it for reflected fields.
On the generator side, `render_rust_type` hands the leaf resolver the origin
and the type key, and `_resolve` prefers a `ty-map` entry for the key over
one
for the origin. The default map already carries `ffi.BigInt ->
tvm_ffi::BigInt`
from #804, so `BigInt` and `Optional<BigInt>` fields now mirror as their own
16-byte cells.
Python-facing behaviour does not change: `.pyi` stubs and `repr` still show
`int`. Lossless folds such as `ffi.String -> str` keep no key on purpose, so
a
user `ty-map` entry for `str` keeps winning.
## Testing
- Python package rebuilt for the Cython change.
- `tests/python/test_type_converter.py` and
`tests/python/test_stubgen_rust.py`:
**682 passed**, 2 pre-existing xfails; the dataclass, structural, BigInt
and
remaining stubgen suites: **1344 passed**.
- New tests: complete-field mirrors for `BigInt` and `Optional<BigInt>` on a
synthetic 64-byte class, including the size assertion; the same fields
reflected from a C++ class compiled with `load_inline`, arriving as origin
`int` with key `ffi.BigInt` and size 16; a user `ty-map` for `str` still
applied to a reflected `ffi.String` field; `from_type_index` agreeing with
the
JSON path; the `to_json` round trip; the parsed-key rules (kept for the
lossy fold, `None` otherwise, nested keys stay on the leaf); and the keys
on
a `Callable[[int], int]` schema in `test_big_int.py`.
- `pre-commit` clean on the touched files (`ruff`, `ruff-format`, `ty`,
`cython-lint`). No C++ or Rust changes.
--
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]