This is an automated email from the ASF dual-hosted git repository.

Seven-Streams pushed a change to annotated tag v0.1.15.post2
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git


*** WARNING: tag v0.1.15.post2 was modified! ***

    from 277e7b45 (commit)
      to aa75d78d (tag)
 tagging 277e7b452bafd77fa6725cd47f3937409208b43b (commit)
 replaces v0.1.15
      by Yuchuan
      on Thu Oct 29 12:57:25 2026 -0400

- Log -----------------------------------------------------------------
[FEAT][Rust] Generate placeholders of rs_class objects with `placeholder` 
([#884](https://github.com/apache/tvm-ffi/issues/884))

Reflection builds some objects field by field: a JSON graph read back,
and the `__ffi_init__`
that `ffi._RegisterFFIInit` generates both make an empty object with the
type's creator, then set
each field. A C++ type gets its creator from `refl::ObjectDef`, whose
object can start empty
because its references may be null; a Python `py_class` allocates zeroed
memory. A Rust object
cannot start empty, since its references are never null, so a downstream
project that registers a
creator (`__ffi_new__`) for an `rs_class` type has to make the object
from valid placeholder
values, which reflection then overwrites.

TVM TIRx does this to let Python construct, JSON graphs hold, and
TVMScript parse the IR types an
extension defines in Rust. It carries its own `Placeholder` trait for
it, and every type writes
the same impl by hand:

```rust
impl Placeholder for PairTypeObj {
    fn placeholder() -> Self {
        Self::new(TypeObj::placeholder(), Type::placeholder(), 
Type::placeholder())
    }
}
```

The impl only repeats the struct: the parent's placeholder, then each
field's, in order. This PR
adds the trait here as `tvm_ffi::Placeholder` and lets `#[rs_class]`
write the impl when asked:

```rust
use tvm_ffi::object::ObjectRef;
use tvm_ffi::{def_object_ref, rs_class, Object, Placeholder};

pub struct PointObj {
    base: Object,
    pub x: i64,
    pub label: tvm_ffi::String,
}

def_object_ref!(pub Point, ObjectRef, PointObj);

let point = Point::from(PointObj::placeholder());
assert_eq!((point.x, point.label.as_str()), (0, ""));
```

Signed-off-by: Yuchuan <[email protected]>
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEkslwBtguEPTsW+HG9USfdrq0UGMFAmrjevcACgkQ9USfdrq0
UGM6dA//QVjIPWwfwOL3YP77kqBS/4muYR5FKR2wUT13lncFgKFw9gIARSAFWZeu
ou5kBIKqS1A5SGuJEiR5tp2zom710XtwoQpWnkHXdccsdbxhnfI5XTgYJ8R+53Xi
5aAEEwJlDWcscVlLFIKQa0vpotFKdoYgKZ/RwSzK6zi4dDvKCSEX8YvDPdjOls1Q
ujkYf26CmyJ7rDUO5+F97JRI1/Nn/dH4v9MMBOkSa+nGjktqQqKgO/uzVN/bN3F1
EmHoA3U9A1yxVmkFbfmmD8YRepH/9iWZmcK/FKQwVziCZYhj54zOP6oT/RNY8Oxf
kbBy8xC8lvTKP7et72MYhTkTh0rYtA7kgCu+BYeBjrCiyqk+NrDrvDgK0DO6Nx55
HQ4wmvm1wREbybS+247fH/bIl2URt1HtPXw6o+srV0/33CnE1+3acSwBB3K2M2KH
+oXvugxr0wFLHzseNx0t/JH8YuOheNTadWn0Doqo6xjyH+lGzddOg9/v3qFkD09c
I5NBTg8+WqM29lVUdNhwIc1YqEX3dML7tCwyTPXl1gGh1emG/R5D8mjghwOCCLYZ
qv34njdnaB53Dg/ZIpT+LsuHD7DrJDoRgPD4BACje7SMBLYODgfXKD6gc1kkJO9A
eWJw/fMC73gDV5i6BbBfa0D5RljYDhx+SkhI/sL1ivNl0U8vo+g=
=Rca5
-----END PGP SIGNATURE-----
-----------------------------------------------------------------------


No new revisions were added by this update.

Summary of changes:

Reply via email to