code: def test_mixed_adt_constructors():
      mod = tvm.IRModule()
      box = relay.GlobalTypeVar("box")
      a = relay.TypeVar("a")
      box_ctor = relay.Constructor("box", [a], box)
      box_data = relay.TypeData(box, [a], [box_ctor])
      mod[box] = box_data
  
      p = Prelude(mod)
      _, cons, nil = p.mod.get_type("List")
  
      v = relay.Var("v")
      box_of_lists_inc = relay.Match(
          v,
          [
              relay.Clause(
                  relay.PatternConstructor(
                      box_ctor,
                      [
                          relay.PatternConstructor(
                              cons,
                              [
                                  relay.PatternWildcard(),
                                  relay.PatternWildcard(),
                              ],
                          )
                      ],
                  ),
                  v,
              )
          ],
      )
  
      # will fail to match a box containing an empty list
      unmatched = unmatched_cases(box_of_lists_inc, mod)
      assert len(unmatched) == 1
      assert isinstance(unmatched[0], relay.PatternConstructor)
      assert unmatched[0].constructor == box_ctor
      assert (
          len(unmatched[0].patterns) == 1
          and unmatched[0].patterns[0].constructor == nil
      )
  
      box_of_lists_comp = relay.Match(
          v,
          [
              relay.Clause(
                  relay.PatternConstructor(
                      box_ctor, [relay.PatternConstructor(nil, [])]
                  ),
                  v,
              ),
              relay.Clause(
                  relay.PatternConstructor(
                      box_ctor,
                      [
                          relay.PatternConstructor(
                              cons,
                              [
                                  relay.PatternWildcard(),
                                  relay.PatternWildcard(),
                              ],
                          )
                      ],
                  ),
                  v,
              ),
          ],
      )
      assert len(unmatched_cases(box_of_lists_comp, mod)) == 0
  
      list_of_boxes_inc = relay.Match(
          v,
          [
              relay.Clause(
                  relay.PatternConstructor(
                      cons,
                      [
                          relay.PatternConstructor(
                              box_ctor, [relay.PatternWildcard()]
                          ),
                          relay.PatternWildcard(),
                      ],
                  ),
                  v,
              )
          ],
      )
  
      # fails to match empty list of boxes
      unmatched = unmatched_cases(list_of_boxes_inc, mod)
      assert len(unmatched) == 1
      assert isinstance(unmatched[0], relay.PatternConstructor)
      assert unmatched[0].constructor == nil
  
      list_of_boxes_comp = relay.Match(
          v,
          [
              # exactly one box
              relay.Clause(
                  relay.PatternConstructor(
                      cons,
                      [
                          relay.PatternConstructor(
                              box_ctor, [relay.PatternWildcard()]
                          ),
                          relay.PatternConstructor(nil, []),
                      ],
                  ),
                  v,
              ),
              # exactly two boxes
              relay.Clause(
                  relay.PatternConstructor(
                      cons,
                      [
                          relay.PatternConstructor(
                              box_ctor, [relay.PatternWildcard()]
                          ),
                          relay.PatternConstructor(
                              cons,
                              [
                                  relay.PatternConstructor(
                                      box_ctor,
                                      [relay.PatternWildcard()],
                                  ),
                                  relay.PatternConstructor(nil, []),
                              ],
                          ),
                      ],
                  ),
                  v,
              ),
              # exactly three boxes
              relay.Clause(
                  relay.PatternConstructor(
                      cons,
                      [
                          relay.PatternConstructor(
                              box_ctor, [relay.PatternWildcard()]
                          ),
                          relay.PatternConstructor(
                              cons,
                              [
                                  relay.PatternConstructor(
                                      box_ctor,
                                      [relay.PatternWildcard()],
                                  ),
                                  relay.PatternConstructor(
                                      cons,
                                      [
                                          relay.PatternConstructor(
                                              box_ctor,
                                              [relay.PatternWildcard()],
                                          ),
                                          relay.PatternConstructor(
                                              nil, []
                                          ),
                                      ],
                                  ),
                              ],
                          ),
                      ],
                  ),
                  v,
              ),
              # one or more boxes
              relay.Clause(
                  relay.PatternConstructor(
                      cons,
                      [
                          relay.PatternWildcard(),
                          relay.PatternWildcard(),
                      ],
                  ),
                  v,
              ),
              # no boxes
              relay.Clause(relay.PatternConstructor(nil, []), v),
          ],
      )
      assert len(unmatched_cases(list_of_boxes_comp, mod)) == 0
  
file_path: tvm/tests/python/relay/test_pass_unmatched_cases.py
imports: import tvm
  from tvm import te
  from tvm import relay
  from tvm.relay.prelude import Prelude
  from tvm.relay.analysis import unmatched_cases
  import pytest
label_desc: Use image node_id 7 for calling a global function with example usage: test_mixed_adt_constructors() without return types