[Rust][Feat] Add match_any! for object-backed values#682
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
5c51eae to
8625f3e
Compare
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
There was a problem hiding this comment.
Pull request overview
Adds a new Rust match_any! procedural macro to support source-ordered, object-only dispatch over values carried by Any/AnyView/object handles, and wires it into the tvm_ffi public API with initial tests.
Changes:
- Introduces
match_any!macro intvm-ffi-macroswith parsing + expansion for ordered typed arms and required_fallback. - Re-exports the macro from
tvm_ffiand adds anAnyViewconversion helper to support borrowedAnyViewscrutinees. - Adds an integration test covering source-order behavior across several object container types.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/tvm-ffi/tests/test_match_any.rs | New integration test validating ordered dispatch across common object containers. |
| rust/tvm-ffi/src/lib.rs | Re-exports match_any from tvm_ffi_macros at the crate root. |
| rust/tvm-ffi/src/any.rs | Adds From<&AnyView> for AnyView to support borrowed AnyView scrutinees. |
| rust/tvm-ffi-macros/src/utils.rs | Refines “local crate vs external crate” detection for macro expansion. |
| rust/tvm-ffi-macros/src/match_any.rs | Implements the match_any! proc-macro parser and code generator. |
| rust/tvm-ffi-macros/src/lib.rs | Exposes the new match_any proc macro and documents intended semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
cc @tqchen |
This PR adds Rust match_any!, a Phase 1 macro that evaluates an Any-compatible scrutinee once, converts it to AnyView, and tries object-backed target conversions in source order using the existing standard TryInto/TryFrom implementations. The first successful conversion whose optional guard passes selects its arm; a failed conversion or guard continues to the next arm, while a required final _ handles non-object or unmatched values. This implementation intentionally does not add type-index dispatch tables, caches, custom pattern protocols, or heuristic dispatch.