You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "Seven-Streams (via GitHub)" <gi...@apache.org> on 2026/07/30 20:46:33 UTC

Re: [PR] [Perf][Rust] Optimize match_any! ordered conversion and exact-leaf dispatch [tvm-ffi]

Seven-Streams commented on code in PR #692:
URL: https://github.com/apache/tvm-ffi/pull/692#discussion_r3686131405


##########
rust/tvm-ffi/tests/test_match_any.rs:
##########
@@ -63,14 +106,53 @@ fn matches_concrete_object_containers_in_source_order() {
     assert_eq!(matched_view, ("tensor", 2));
 }
 
+#[test]
+fn custom_try_into_matcher_keeps_ordered_compatibility() {
+    fn matches(value: AnyView<'_>) -> bool {
+        match_any! {
+            value {
+                CustomModuleMatcher(_) => true,
+                _ => false,
+            }
+        }
+    }
+
+    let module: Module = Function::get_global("ffi.SystemLib")
+        .unwrap()
+        .call_tuple_with_len::<0, _>(())
+        .unwrap()
+        .try_into()
+        .unwrap();
+    assert!(matches(AnyView::from(&module)));
+    assert!(!matches(AnyView::from(&Shape::from([1_i64, 2]))));
+}
+
 #[test]
 fn parameterized_containers_keep_ordered_conversion() {
     let array = [1.5_f64, 2.5].into_iter().collect::<Array<f64>>();
+    // Twenty arms make the macro consider lookup dispatch, but Array<T> is
+    // content-dependent and therefore keeps the complete ordered conversion.
     let selected = match_any! {
         Any::from(array) {
             Array::<i64>(_) => "integer array",
             Tensor(_) => "tensor",
             Shape(_) => "shape",
+            Module(_) => "module",

Review Comment:
   too ordered



##########
rust/tvm-ffi/tests/test_match_any.rs:
##########
@@ -80,48 +162,155 @@ fn parameterized_containers_keep_ordered_conversion() {
 }
 
 #[test]
-fn leaf_lookup_keeps_the_first_arm() {
-    fn classify(value: Any) -> usize {
+fn lookup_selects_later_arms_and_isolates_generic_pattern_lists() {
+    fn classify<T>(value: AnyView<'_>) -> usize
+    where
+        T: AnyCompatible + 'static,
+        for<'a> AnyView<'a>: TryInto<T>,
+    {
         match_any! {
             value {
-                Module(_) => 0,
-                Module(_) => 1,
-                _ => 2,
+                T(ref _value) => 0,
+                T(mut _value) => 1,
+                T(_) => 2,

Review Comment:
   too ordered



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org