def __call__(self, graph): dangerous = set() for head in order(graph, NONTREE, Matcher): for loop in either_loops(head, self.conservative): for node in loop: dangerous.add(node) def new_clone(node, args, kargs): ''' Clone with the appropriate memoizer (cannot use post_clone as need to test original) ''' copy = clone(node, args, kargs) if isinstance(node, Delayed): # no need to memoize the proxy (if we do, we also break # rewriting, since we "hide" the Delayed instance) return copy elif node in dangerous: if self.left: return self.left(copy) else: return copy else: if self.right: return self.right(copy) else: return copy return graph.postorder(DelayedClone(new_clone), Matcher)
def __call__(self, graph): dangerous = set() for head in order(graph, NONTREE, Matcher): for loop in either_loops(head, self.conservative): for node in loop: dangerous.add(node) def new_clone(i, j, node, args, kargs): ''' Clone with the appropriate memoizer (cannot use post_clone as need to test original) ''' copy = clone(i, j, node, args, kargs) if (self.conservative is None and i) or node in dangerous: if self.left: return LeftMemoize.memoize(i, j, self.d, copy, self.left) else: return copy else: if self.right: return self.right(copy) else: return copy return clone_matcher(graph, new_clone, duplicate=True)
def order(self, tree, flags): return list(map(lambda x: x[0], order(tree, flags, Node, LEAF)))