Commit 76f3852e authored by Stefan Behnel's avatar Stefan Behnel

fix conflict between genexpr inlining and dict iteration optimisations

parent c1d71d70
...@@ -1574,7 +1574,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform): ...@@ -1574,7 +1574,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
node.pos, node.pos,
value=ExprNodes.BoolNode(yield_expression.pos, value=not is_any, constant_result=not is_any)) value=ExprNodes.BoolNode(yield_expression.pos, value=not is_any, constant_result=not is_any))
Visitor.recursively_replace_node(loop_node, yield_stat_node, test_node) Visitor.recursively_replace_node(gen_expr_node, yield_stat_node, test_node)
return ExprNodes.InlinedGeneratorExpressionNode( return ExprNodes.InlinedGeneratorExpressionNode(
gen_expr_node.pos, gen=gen_expr_node, orig_func='any' if is_any else 'all') gen_expr_node.pos, gen=gen_expr_node, orig_func='any' if is_any else 'all')
...@@ -1614,7 +1614,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform): ...@@ -1614,7 +1614,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
expr=yield_expression, expr=yield_expression,
target=list_node.target) target=list_node.target)
Visitor.recursively_replace_node(loop_node, yield_stat_node, append_node) Visitor.recursively_replace_node(gen_expr_node, yield_stat_node, append_node)
elif arg.is_sequence_constructor: elif arg.is_sequence_constructor:
# sorted([a, b, c]) or sorted((a, b, c)). The result is always a list, # sorted([a, b, c]) or sorted((a, b, c)). The result is always a list,
...@@ -1687,7 +1687,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform): ...@@ -1687,7 +1687,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
rhs = ExprNodes.binop_node(node.pos, '+', result_ref, yield_expression) rhs = ExprNodes.binop_node(node.pos, '+', result_ref, yield_expression)
) )
Visitor.recursively_replace_node(loop_node, yield_stat_node, add_node) Visitor.recursively_replace_node(gen_expr_node, yield_stat_node, add_node)
exec_code = Nodes.StatListNode( exec_code = Nodes.StatListNode(
node.pos, node.pos,
...@@ -1806,7 +1806,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform): ...@@ -1806,7 +1806,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
expr=yield_expression, expr=yield_expression,
target=result_node.target) target=result_node.target)
Visitor.recursively_replace_node(loop_node, yield_stat_node, append_node) Visitor.recursively_replace_node(gen_expr_node, yield_stat_node, append_node)
return result_node return result_node
def _handle_simple_function_dict(self, node, pos_args): def _handle_simple_function_dict(self, node, pos_args):
...@@ -1840,7 +1840,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform): ...@@ -1840,7 +1840,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
value_expr = yield_expression.args[1], value_expr = yield_expression.args[1],
target=result_node.target) target=result_node.target)
Visitor.recursively_replace_node(loop_node, yield_stat_node, append_node) Visitor.recursively_replace_node(gen_expr_node, yield_stat_node, append_node)
return result_node return result_node
# specific handlers for general call nodes # specific handlers for general call nodes
...@@ -3107,7 +3107,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, ...@@ -3107,7 +3107,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
expr=yield_expression, expr=yield_expression,
target=inlined_genexpr.target) target=inlined_genexpr.target)
Visitor.recursively_replace_node(loop_node, yield_stat_node, append_node) Visitor.recursively_replace_node(gen_expr_node, yield_stat_node, append_node)
args[1] = inlined_genexpr args[1] = inlined_genexpr
return self._substitute_method_call( return self._substitute_method_call(
......
...@@ -247,6 +247,28 @@ def join_sep_genexpr(l): ...@@ -247,6 +247,28 @@ def join_sep_genexpr(l):
return result return result
@cython.test_fail_if_path_exists(
"//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
"//CastNode", "//TypecastNode",
)
@cython.test_assert_path_exists(
"//PythonCapiCallNode",
"//InlinedGeneratorExpressionNode"
)
def join_sep_genexpr_dictiter(dict d):
"""
>>> l = text.split()
>>> d = dict(zip(range(len(l)), l))
>>> print('|'.join( sorted(' '.join('%s:%s' % (k, v) for k, v in d.items()).split()) ))
0:ab|1:jd|2:sdflk|3:as|4:sa|5:sadas|6:asdas|7:fsdf
>>> print('|'.join( sorted(join_sep_genexpr_dictiter(d).split())) )
0:ab|1:jd|2:sdflk|3:as|4:sa|5:sadas|6:asdas|7:fsdf
"""
result = u' '.join('%s:%s' % (k, v) for k, v in d.iteritems())
assert cython.typeof(result) == 'unicode object', cython.typeof(result)
return result
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//PythonCapiCallNode", "//PythonCapiCallNode",
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment