The GitHub Actions job "mainline-only" on tvm-ffi.git/main has failed.
Run started by GitHub user tqchen (triggered by tqchen).

Head commit for run:
c4d9cd3ee05e0911635d9e08d2b89782cea6bc3c / Shushi Hong <[email protected]>
[Feat][Rust] Add native structural_map and structural_mutate (#704)

This PR adds Rust-native `structural_map` and `structural_mutate`
support as the Rust counterpart to the C++ structural mutation APIs
introduced in #649. It builds on the Rust `structural_visit` and
`structural_walk` infrastructure from #693.

## Design

Rust owns:

- Callback dispatch and walk order.
- Definition-region propagation.
- DAG and FreeVar identity remapping.
- Error context and panic propagation.
- The user-facing structural-map and structural-mutator APIs.

Type-specific traversal remains with the implementation that registered
the runtime type.

For default recursion, Rust looks up the existing structural mutation
type attributes:

- `__s_mutate__`
- `__s_maybe_inplace_mutate__`

Rust constructs an ABI-compatible `ffi.StructuralMutator` object.
Registered hooks receive this active mutator and recursively call its
language-independent vtable to return child values to Rust.

This allows the existing C++ hooks for Array, List, Map, and Dict to
manage their private storage while Rust continues to control callback
dispatch and recursive transformation.

Hooks may be registered as either opaque function pointers or
`ffi.Function` objects.

This PR does not add a Map/Dict-specific C API, does not add
`TVMFFIMapMutateValues`, and does not mirror the private C++ Map/Dict
storage layout.

## Rust APIs

This PR provides:

- `structural_map` with pre-order and post-order callbacks.
- A low-level `StructuralMutator` trait for custom recursion.
- `InplaceValue` for engine-authorized in-place mutation.
- `StructuralVarRemap` for owning DAG and FreeVar substitutions.
- Typed closures and ordered callback tuples of up to eight handlers.
- `#[dispatch(map)]` generated dispatch.
- Optional `DefRegionKind` callback arguments.
- Fallible callbacks returning `Result<Any>`.
- Shared callback value handling between structural visit and map.
- Structural error context for objects and reflected fields.

Callback tuples use ordered first-match dispatch. A `&MapValue` handler
acts as the catch-all handler and should therefore appear last.

## Mutation semantics

The root is consumed so Rust ownership and the runtime reference count
determine whether in-place mutation is allowed.

- Uniquely owned Array, List, Map, and Dict objects may reuse their
storage.
- Passing a shared root, such as `root.clone()`, selects copy-on-write
behavior.
- Map and Dict keys are structural anchors and are not mapped.
- If no value changes, the original object may be returned.
- Reflected objects use `__ffi_shallow_copy__` together with registered
field getters and setters.
- FreeVar and DAG-node identities are mapped once and reuse the
completed mapped result.
- `None` and other inline values are passed through normal callback
dispatch.
- Changes completed through an in-place path are not rolled back if a
later callback fails.

Rust panics are caught before crossing the C ABI. The panic is resumed
only after the registered runtime hook returns, allowing C++ RAII
cleanup to finish first.

A retained `ffi.StructuralMutator` reference also fails safely after the
active structural-mutation call ends instead of keeping a dangling Rust
callback context.

## Shared structural callback support

The structural visit and map implementations share:

- Borrowed callback-value handling.
- Typed object-node casts.
- Callback tuple arity generation.

The procedural macro implementation is generalized from visit-only
dispatch to support both `#[dispatch(visit)]` and `#[dispatch(map)]`.

---------

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

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

With regards,
GitHub Actions via GitBox


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

Reply via email to