tlopex opened a new pull request, #704: URL: https://github.com/apache/tvm-ffi/pull/704
This PR adds Rust-native structural transformation support, building on the Rust `structural_visit` and `structural_walk` infrastructure introduced in #693. The transformation engine is implemented in Rust. It provides: - `structural_map` with pre-order and post-order callbacks. - A low-level `StructuralMutator` API for user-controlled recursion. - Typed closures, ordered callback tuples, and `#[dispatch(map)]`. - Definition-region propagation. - DAG and FreeVar identity remapping. - Structural error context. - Native Array, List, Map, Dict, and reflected-object mutation. - Copy-on-write and optional in-place container reuse. Map and Dict keys remain structural anchors and are not mapped. ## Ownership and mutation semantics The root is consumed so Rust ownership and the runtime strong-reference count define whether a container may be reused. - Uniquely owned Array, List, Map, and Dict objects may be updated in place. - Passing a shared root, such as `root.clone()`, selects copy-on-write behavior. - A shared immutable Map is copied lazily when its first changed value is found. - A shared mutable Dict is copied before the first callback, providing a stable snapshot if a callback re-enters and mutates an alias of the source Dict. - If no structural value changes, the original object identity is returned. Foreign `__s_mutate__` hooks are rejected rather than silently replacing custom runtime semantics. Types with custom mutation behavior can explicitly take over through the Rust `StructuralMutator` API. ## Runtime support This PR adds minimal runtime support for shallow-copying Map and Dict storage. The runtime helpers preserve: - The exact Map or Dict runtime type. - Iteration order. - Key and value object identity. - The runtime allocator and deleter contract. No object layout or existing C ABI is changed. The helpers are optional from the Rust crate's perspective. When linked against an older runtime, Rust falls back to the canonical Map/Dict constructors and re-hashes the entries. -- 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]
