MergeComposite Error when defining custom pattern

This is an interesting case and thanks for pointing out. I investigated it a bit and identified that this is not the problem of MergeComposite but the pattern partition. Specifically, you can reproduce this problem by replacing assert test_pattern.match(r) # True with assert test_pattern.partition(r).

In pattern partition, for each matched pattern, it creates 1) a set of new parameters with FunctionVar_<group ID>_<var_ID> as their names, and 2) a new set of nodes to be the partitioned function body. Finally, it uses the above two to create a partition function. The problem comes from dataflow_matcher.cc:647, where it tries to check if the new sets of nodes still matches the pattern. However, since the parameter names are changed, it doesn’t match your variable name x anymore. That’s why it throws the exception.

The fastest workaround is commenting out dataflow_matcher.cc:647 in case you need to move forward now. We should still solve this problem. At the first glance, I can think of two approaches.

  1. Simply remove this check.
  2. Canoncialize the pattern used in L647 by removing name specific matching.

@mbrookhart do you have any suggestion? Thanks.