[pypy-svn] r31445 - in pypy/dist/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Aug 21 17:04:11 CEST 2006
Author: arigo
Date: Mon Aug 21 17:04:07 2006
New Revision: 31445
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
(pedronis, arre, arigo)
Annotation bug and fix: confusion between multiple prebuilt '{}' or '[]'
because they compare equal in the .const :-(
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Mon Aug 21 17:04:07 2006
@@ -330,6 +330,8 @@
self.immutable_cache[key] = result
for e in x:
result.listdef.generalize(self.immutablevalue(e))
+ result.const_box = key
+ return result
elif tp is dict or tp is r_dict:
key = Constant(x)
try:
@@ -355,6 +357,8 @@
pass
else:
done = True
+ result.const_box = key
+ return result
elif ishashable(x) and x in BUILTIN_ANALYZERS:
_module = getattr(x,"__module__","unknown")
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Mon Aug 21 17:04:07 2006
@@ -55,11 +55,10 @@
funcgraph.source = inspect.getsource(func)
return funcgraph
- def reallyshow(self, graph):
- import os
- from pypy.translator.tool.make_dot import make_dot
- dest = make_dot('b', graph)
- os.system('gv %s' % str(dest))
+ def show(self, a):
+ from pypy import conftest
+ if conftest.option.view:
+ a.translator.view()
def test_simple_func(self):
"""
@@ -2213,6 +2212,49 @@
assert isinstance(s, annmodel.SomeInteger)
assert s.nonneg
+ def test_prebuilt_mutables(self):
+ class A:
+ pass
+ class B:
+ pass
+ a1 = A()
+ a2 = A()
+ a1.d = {} # this tests confusion between the two '{}', which
+ a2.d = {} # compare equal
+ a1.l = []
+ a2.l = []
+ b = B()
+ b.d1 = a1.d
+ b.d2 = a2.d
+ b.l1 = a1.l
+ b.l2 = a2.l
+
+ def dmutate(d):
+ d[123] = 321
+
+ def lmutate(l):
+ l.append(42)
+
+ def readout(d, l):
+ return len(d) + len(l)
+
+ def f():
+ dmutate(b.d1)
+ dmutate(b.d2)
+ dmutate(a1.d)
+ dmutate(a2.d)
+ lmutate(b.l1)
+ lmutate(b.l2)
+ lmutate(a1.l)
+ lmutate(a2.l)
+ return readout(a1.d, a1.l) + readout(a2.d, a2.l)
+
+ a = self.RPythonAnnotator()
+ a.build_types(f, [])
+ self.show(a)
+ v1, v2 = graphof(a, readout).getargs()
+ assert not a.bindings[v1].is_constant()
+ assert not a.bindings[v2].is_constant()
def g(n):
More information about the Pypy-commit
mailing list