[pypy-svn] r14707 - in pypy/dist/pypy: annotation translator/test
pedronis at codespeak.net
pedronis at codespeak.net
Fri Jul 15 21:09:26 CEST 2005
Author: pedronis
Date: Fri Jul 15 21:09:24 2005
New Revision: 14707
Modified:
pypy/dist/pypy/annotation/listdef.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
fix bug in listitem.merge, read locations of the other listitem were not reflown even if the merge involved a generalization of the previous annotation for other.
Test that show-cased the problem.
Modified: pypy/dist/pypy/annotation/listdef.py
==============================================================================
--- pypy/dist/pypy/annotation/listdef.py (original)
+++ pypy/dist/pypy/annotation/listdef.py Fri Jul 15 21:09:24 2005
@@ -22,9 +22,22 @@
if other.range_step != self.range_step:
self.range_step = None
self.itemof.update(other.itemof)
+ read_locations = self.read_locations.copy()
+ other_read_locations = other.read_locations.copy()
self.read_locations.update(other.read_locations)
self.patch() # which should patch all refs to 'other'
- self.generalize(other.s_value)
+ s_value = self.s_value
+ s_other_value = other.s_value
+ s_new_value = tracking_unionof(self.__class__.__name__, s_value, s_other_value)
+ if s_new_value != s_value:
+ self.s_value = s_new_value
+ # reflow from reading points
+ for position_key in read_locations:
+ self.bookkeeper.annotator.reflowfromposition(position_key)
+ if s_new_value != s_other_value:
+ # reflow from reading points
+ for position_key in other_read_locations:
+ self.bookkeeper.annotator.reflowfromposition(position_key)
def patch(self):
for listdef in self.itemof:
Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py (original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py Fri Jul 15 21:09:24 2005
@@ -1395,6 +1395,31 @@
s = a.build_types(f, [int, str])
assert s.knowntype == int
+ def test_listitem_merge_asymmetry_bug(self):
+ class K:
+ pass
+ def mutr(k, x, i):
+ k.l2 = [x] + k.l2 # this involves a side-effectful union and unification, with this order
+ # of arguments some reflowing was missed
+ k.l2[i] = x
+ def witness(i):
+ pass
+ def trouble(k):
+ l = k.l1 + k.l2
+ for i in range(len(l)):
+ witness(l[i])
+ def f(flag, k, x, i):
+ if flag:
+ k = K()
+ k.l1 = []
+ k.l2 = []
+ trouble(k)
+ mutr(k, x, i)
+ a = self.RPythonAnnotator()
+ a.build_types(f, [bool, K, int, int])
+ g = a.translator.getflowgraph(witness)
+ assert a.binding(g.getargs()[0]).knowntype == int
+
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list