Skip to content

Commit f320dbb

Browse files
committed
Fix optimization in LET
LET a = <expr> + FUNC_CALL(x) can be optimized to FUNC_CALL(x) if a is not needed. But this requires to filter out FUNC_CALL(x) carefully.
1 parent 9e6007a commit f320dbb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

api/optimize.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ToVisit(object):
2121
""" Used just to signal an object to be
2222
traversed.
2323
"""
24+
2425
def __init__(self, obj):
2526
self.obj = obj
2627

@@ -155,7 +156,14 @@ def visit_FUNCTION(self, node):
155156
def visit_LET(self, node):
156157
if self.O_LEVEL > 1 and not node.children[0].accessed:
157158
warning_not_used(node.children[0].lineno, node.children[0].name)
158-
yield symbols.BLOCK(*list(self.filter_inorder(node.children[1], lambda x: isinstance(x, symbols.CALL))))
159+
block = symbols.BLOCK(*[
160+
symbols.CALL(x.entry, x.args, x.lineno) for x in self.filter_inorder(
161+
node.children[1],
162+
lambda x: isinstance(x, symbols.FUNCCALL),
163+
lambda x: not isinstance(x, symbols.FUNCTION)
164+
)
165+
])
166+
yield block
159167
else:
160168
yield (yield self.generic_visit(node))
161169

0 commit comments

Comments
 (0)