mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
transforms/remove_inter_assigns: prevent combinatorial explosion
This commit is contained in:
parent
fba72cc0a2
commit
171d56af54
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user