The GitHub Actions job "CI" on tvm-ffi.git/main has succeeded.
Run started by GitHub user tlopex (triggered by tlopex).

Head commit for run:
24cfa44ca425ece2f2547ae87b81fea2835ddebd / Linzhang Li 
<[email protected]>
[STUBGEN][RUST] Generate complete object mirrors and allocators (#740)

## Summary

Attach the layout classifier (#730) to the Rust backend. A type whose
layout the registry proves is now bound *complete*: a `#[repr(C)]`
struct with every physical field at its reflected offset and width, a
`const` size/alignment assertion, and a lossless allocator
(`<Leaf>Obj::new` crate-private, `<Leaf>::new` public). Everything else
keeps the opaque form of #738. Three new directives: `opaque` vetoes a
reproducible layout, `upcast` adds a hand-written typed view,
`custom-new` renames the generated allocator to `from_complete_fields`
so a hand-written `new` can own the name.

## Motivation

This is what tvm-rust-ext's `STUBGEN_FEEDBACK.md` asks for: ordinary
data nodes allocated in Rust from their complete fields, polymorphic and
unreflected-byte types kept opaque. Generating `ir.` / `tirx.` /
`arith.` / `target.` from tvm-rust-ext's `libtvm_compiler.so` gives 131
types (98 complete, 33 opaque) that compile against the crate without
edits; the differences from the hand-written bindings are exactly what
the directives cover.

## Changes

- `stub/layout.py`: `classify(..., unmirrored=...)` and the `no-mirror`
reason, so types under a builtin parent (`ffi.Enum`, ...) stay opaque:
their base is only a header-only stand-in.
- `rust_generator/codegen.py`: classify each object with its ancestors;
mirror fields (scalars by reflected width, `Optional<T>` as `Option<T>`
or `tvm_ffi::Optional<T>` by payload, directive widths checked against
the field size); render the complete struct and its allocators; `upcast`
and `custom-new` handling.
- `rust_generator/directives.py`, `consts.py`: the three directives and
the width tables.
- `rust_generator/utils.py`: a reflected field named `base` or `data` is
spelled `base_` / `data_`, since those are the generated struct's own
members (TVM has `tirx.Ramp.base`, `tirx.DeclBuffer.data`).
- `examples/rust_stubgen/`: `IntPair` is now a plain data object,
allocated from Rust with the generated `IntPair::new` and read back by
C++.

## Testing

`test_stubgen_rust.py` (36 cases), `test_stubgen.py`,
`test_stub_layout.py`: 121 passed; ruff clean. The example regenerates
an identical `mod.rs` and `cargo run` prints `a=1 b=2 kind=PairKind(1)`
and `sum=3`.

---------

Signed-off-by: yuchuan <[email protected]>

Report URL: https://github.com/apache/tvm-ffi/actions/runs/33923475693

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to