Commit fca588c0 authored by Stefan Behnel's avatar Stefan Behnel

really fix parallel/cascaded assignments this time (and test it): make sure...

really fix parallel/cascaded assignments this time (and test it): make sure the rhs values are evaluated in source code order
parent cefd59bd
...@@ -288,7 +288,7 @@ class PostParse(ScopeTrackingTransform): ...@@ -288,7 +288,7 @@ class PostParse(ScopeTrackingTransform):
duplicates_and_temps = [ (temp.expression, temp) duplicates_and_temps = [ (temp.expression, temp)
for temp in temp_refs ] for temp in temp_refs ]
sort_common_subsequences(duplicates_and_temps) 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) assign_node = LetNode(temp_ref, assign_node)
return assign_node return assign_node
...@@ -362,8 +362,8 @@ def sort_common_subsequences(items): ...@@ -362,8 +362,8 @@ def sort_common_subsequences(items):
return b.is_sequence_constructor and contains(b.args, a) return b.is_sequence_constructor and contains(b.args, a)
for pos, item in enumerate(items): for pos, item in enumerate(items):
key = item[1] # the ResultRefNode which has already been injected into the sequences
new_pos = pos new_pos = pos
key = item[0]
for i in xrange(pos-1, -1, -1): for i in xrange(pos-1, -1, -1):
if lower_than(key, items[i][0]): if lower_than(key, items[i][0]):
new_pos = i new_pos = i
......
...@@ -7,10 +7,9 @@ def simple_parallel_assignment_from_call(): ...@@ -7,10 +7,9 @@ def simple_parallel_assignment_from_call():
cdef int ai, bi cdef int ai, bi
cdef long al, bl cdef long al, bl
cdef object ao, bo cdef object ao, bo
cdef int side_effect_count = call_count reset()
ai, bi = al, bl = ao, bo = c = d = [intval(1), intval(2)] ai, bi = al, bl = ao, bo = c = d = [intval(1), intval(2)]
side_effect_count = call_count - side_effect_count return call_count, ao, bo, ai, bi, al, bl, c, d
return side_effect_count, ao, bo, ai, bi, al, bl, c, d
def recursive_parallel_assignment_from_call_left(): def recursive_parallel_assignment_from_call_left():
""" """
...@@ -19,10 +18,9 @@ def recursive_parallel_assignment_from_call_left(): ...@@ -19,10 +18,9 @@ def recursive_parallel_assignment_from_call_left():
""" """
cdef int ai, bi, ci cdef int ai, bi, ci
cdef object ao, bo, co 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)] (ai, bi), ci = (ao, bo), co = t,o = d = [(intval(1), intval(2)), intval(3)]
side_effect_count = call_count - side_effect_count return call_count, ao, bo, co, ai, bi, ci, t, o, d
return side_effect_count, ao, bo, co, ai, bi, ci, t, o, d
def recursive_parallel_assignment_from_call_right(): def recursive_parallel_assignment_from_call_right():
""" """
...@@ -31,10 +29,9 @@ def recursive_parallel_assignment_from_call_right(): ...@@ -31,10 +29,9 @@ def recursive_parallel_assignment_from_call_right():
""" """
cdef int ai, bi, ci cdef int ai, bi, ci
cdef object ao, bo, co 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))] ai, (bi, ci) = ao, (bo, co) = o,t = d = [intval(1), (intval(2), intval(3))]
side_effect_count = call_count - side_effect_count return call_count, ao, bo, co, ai, bi, ci, o, t, d
return side_effect_count, ao, bo, co, ai, bi, ci, o, t, d
def recursive_parallel_assignment_from_call_left_reversed(): def recursive_parallel_assignment_from_call_left_reversed():
""" """
...@@ -43,10 +40,9 @@ 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 int ai, bi, ci
cdef object ao, bo, co 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)] d = t,o = (ao, bo), co = (ai, bi), ci = [(intval(1), intval(2)), intval(3)]
side_effect_count = call_count - side_effect_count return call_count, ao, bo, co, ai, bi, ci, t, o, d
return side_effect_count, ao, bo, co, ai, bi, ci, t, o, d
def recursive_parallel_assignment_from_call_right_reversed(): def recursive_parallel_assignment_from_call_right_reversed():
""" """
...@@ -55,14 +51,21 @@ 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 int ai, bi, ci
cdef object ao, bo, co 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))] d = o,t = ao, (bo, co) = ai, (bi, ci) = [intval(1), (intval(2), intval(3))]
side_effect_count = call_count - side_effect_count return call_count, ao, bo, co, ai, bi, ci, o, t, d
return side_effect_count, ao, bo, co, ai, bi, ci, o, t, d
cdef int call_count = 0 cdef int call_count = 0
cdef int next_expected_arg = 1
cdef int intval(int x): cdef reset():
global call_count 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 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 return x
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