really fix parallel/cascaded assignments this time (and test it): make sure the rhs...
authorStefan Behnel <scoder@users.berlios.de>
Fri, 26 Nov 2010 08:52:45 +0000 (09:52 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 26 Nov 2010 08:52:45 +0000 (09:52 +0100)
Cython/Compiler/ParseTreeTransforms.py
tests/run/cascaded_list_unpacking_T467.pyx

index a0d18c3195c081a10edd75c7f8e9b170da992aa1..ecad0c3190113927e27de612df1c7d431fad1487 100644 (file)
@@ -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
index 467ad644aede991e614b0fb237b4089180eaebdf..c1187e9ff06fbc1631f1fcbd947d1f8a63262bb3 100644 (file)
@@ -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