From 171d56af54e1d9d9aea9de454c340f78bbd46c96 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 3 Nov 2014 14:22:24 +0800 Subject: [PATCH] transforms/remove_inter_assigns: prevent combinatorial explosion --- artiq/transforms/remove_inter_assigns.py | 5 ++--- artiq/transforms/tools.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/artiq/transforms/remove_inter_assigns.py b/artiq/transforms/remove_inter_assigns.py index bcc6e2fcd..92b4b7e55 100644 --- a/artiq/transforms/remove_inter_assigns.py +++ b/artiq/transforms/remove_inter_assigns.py @@ -2,8 +2,7 @@ import ast from copy import copy, deepcopy from collections import defaultdict -from artiq.transforms.tools import is_ref_transparent - +from artiq.transforms.tools import is_ref_transparent, count_all_nodes class _TargetLister(ast.NodeVisitor): def __init__(self): @@ -47,7 +46,7 @@ class _InterAssignRemover(ast.NodeTransformer): node.value = self.visit(node.value) node.targets = [self.visit(target) for target in node.targets] rt, depends_on = is_ref_transparent(node.value) - if rt: + if rt and count_all_nodes(node.value) < 100: for target in node.targets: if isinstance(target, ast.Name): if target.id not in depends_on: diff --git a/artiq/transforms/tools.py b/artiq/transforms/tools.py index 45a4bd2c0..07ce20acd 100644 --- a/artiq/transforms/tools.py +++ b/artiq/transforms/tools.py @@ -115,3 +115,18 @@ def is_ref_transparent(expr): return True, dependencies else: return False, None + + +class _NodeCounter(ast.NodeVisitor): + def __init__(self): + self.count = 0 + + def generic_visit(self, node): + self.count += 1 + ast.NodeVisitor.generic_visit(self, node) + + +def count_all_nodes(node): + nc = _NodeCounter() + nc.visit(node) + return nc.count