From fca588c0c45163d89e7160f006f6e4e2d2edec0f Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 26 Nov 2010 09:52:45 +0100 Subject: [PATCH] really fix parallel/cascaded assignments this time (and test it): make sure the rhs values are evaluated in source code order --- Cython/Compiler/ParseTreeTransforms.py | 4 +-- tests/run/cascaded_list_unpacking_T467.pyx | 37 ++++++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index a0d18c31..ecad0c31 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -288,7 +288,7 @@ class PostParse(ScopeTrackingTransform): duplicates_and_temps = [ (temp.expression, temp) for temp in temp_refs ] sort_common_subsequences(duplicates_and_temps) - for _, temp_ref in duplicates_and_temps: + for _, temp_ref in duplicates_and_temps[::-1]: assign_node = LetNode(temp_ref, assign_node) return assign_node @@ -362,8 +362,8 @@ def sort_common_subsequences(items): return b.is_sequence_constructor and contains(b.args, a) for pos, item in enumerate(items): + key = item[1] # the ResultRefNode which has already been injected into the sequences new_pos = pos - key = item[0] for i in xrange(pos-1, -1, -1): if lower_than(key, items[i][0]): new_pos = i diff --git a/tests/run/cascaded_list_unpacking_T467.pyx b/tests/run/cascaded_list_unpacking_T467.pyx index 467ad644..c1187e9f 100644 --- a/tests/run/cascaded_list_unpacking_T467.pyx +++ b/tests/run/cascaded_list_unpacking_T467.pyx @@ -7,10 +7,9 @@ def simple_parallel_assignment_from_call(): cdef int ai, bi cdef long al, bl cdef object ao, bo - cdef int side_effect_count = call_count + reset() ai, bi = al, bl = ao, bo = c = d = [intval(1), intval(2)] - side_effect_count = call_count - side_effect_count - return side_effect_count, ao, bo, ai, bi, al, bl, c, d + return call_count, ao, bo, ai, bi, al, bl, c, d def recursive_parallel_assignment_from_call_left(): """ @@ -19,10 +18,9 @@ def recursive_parallel_assignment_from_call_left(): """ cdef int ai, bi, ci cdef object ao, bo, co - cdef int side_effect_count = call_count + reset() (ai, bi), ci = (ao, bo), co = t,o = d = [(intval(1), intval(2)), intval(3)] - side_effect_count = call_count - side_effect_count - return side_effect_count, ao, bo, co, ai, bi, ci, t, o, d + return call_count, ao, bo, co, ai, bi, ci, t, o, d def recursive_parallel_assignment_from_call_right(): """ @@ -31,10 +29,9 @@ def recursive_parallel_assignment_from_call_right(): """ cdef int ai, bi, ci cdef object ao, bo, co - cdef int side_effect_count = call_count + reset() ai, (bi, ci) = ao, (bo, co) = o,t = d = [intval(1), (intval(2), intval(3))] - side_effect_count = call_count - side_effect_count - return side_effect_count, ao, bo, co, ai, bi, ci, o, t, d + return call_count, ao, bo, co, ai, bi, ci, o, t, d def recursive_parallel_assignment_from_call_left_reversed(): """ @@ -43,10 +40,9 @@ def recursive_parallel_assignment_from_call_left_reversed(): """ cdef int ai, bi, ci cdef object ao, bo, co - cdef int side_effect_count = call_count + reset() d = t,o = (ao, bo), co = (ai, bi), ci = [(intval(1), intval(2)), intval(3)] - side_effect_count = call_count - side_effect_count - return side_effect_count, ao, bo, co, ai, bi, ci, t, o, d + return call_count, ao, bo, co, ai, bi, ci, t, o, d def recursive_parallel_assignment_from_call_right_reversed(): """ @@ -55,14 +51,21 @@ def recursive_parallel_assignment_from_call_right_reversed(): """ cdef int ai, bi, ci cdef object ao, bo, co - cdef int side_effect_count = call_count + reset() d = o,t = ao, (bo, co) = ai, (bi, ci) = [intval(1), (intval(2), intval(3))] - side_effect_count = call_count - side_effect_count - return side_effect_count, ao, bo, co, ai, bi, ci, o, t, d + return call_count, ao, bo, co, ai, bi, ci, o, t, d cdef int call_count = 0 +cdef int next_expected_arg = 1 -cdef int intval(int x): - global call_count +cdef reset(): + global call_count, next_expected_arg + call_count = 0 + next_expected_arg = 1 + +cdef int intval(int x) except -1: + global call_count, next_expected_arg call_count += 1 + assert next_expected_arg == x, "calls not in source code order: expected %d, found %d" % (next_expected_arg, x) + next_expected_arg += 1 return x -- 2.26.2