[pypy-svn] r68374 - in pypy/branch/gc-hash/pypy/annotation: . test

arigo at codespeak.net arigo at codespeak.net
Tue Oct 13 13:47:18 CEST 2009


Author: arigo
Date: Tue Oct 13 13:47:18 2009
New Revision: 68374

Modified:
   pypy/branch/gc-hash/pypy/annotation/dictdef.py
   pypy/branch/gc-hash/pypy/annotation/test/test_annrpython.py
Log:
Test __precomputed_identity_hash in the annotator.
Fix a bug.


Modified: pypy/branch/gc-hash/pypy/annotation/dictdef.py
==============================================================================
--- pypy/branch/gc-hash/pypy/annotation/dictdef.py	(original)
+++ pypy/branch/gc-hash/pypy/annotation/dictdef.py	Tue Oct 13 13:47:18 2009
@@ -2,7 +2,7 @@
 from pypy.annotation.model import SomeInteger, s_Bool, unionof
 from pypy.annotation.model import SomeInstance
 from pypy.annotation.listdef import ListItem
-from pypy.rlib.objectmodel import compute_identity_hash
+from pypy.rlib.objectmodel import compute_hash
 
 
 class DictKey(ListItem):
@@ -133,10 +133,7 @@
         self.dictvalue.generalize(s_value)
 
     def seen_prebuilt_key(self, x):
-        try:
-            compute_identity_hash(x)
-        except TypeError:
-            pass     # e.g. if x is an int
+        compute_hash(x)
 
     def __repr__(self):
         return '<{%r: %r}>' % (self.dictkey.s_value, self.dictvalue.s_value)

Modified: pypy/branch/gc-hash/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/gc-hash/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/branch/gc-hash/pypy/annotation/test/test_annrpython.py	Tue Oct 13 13:47:18 2009
@@ -3187,6 +3187,25 @@
         s = a.build_types(f, [int])
         assert s.const == 0
 
+    def test_hash_sideeffect(self):
+        class X:
+            pass
+        x1 = X()
+        x2 = X()
+        x3 = X()
+        d = {(2, x1): 5, (3, x2): 7}
+        def f(n, m):
+            if   m == 1: x = x1
+            elif m == 2: x = x2
+            else:        x = x3
+            return d[n, x]
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int, int])
+        assert s.knowntype == int
+        assert hasattr(x1, '__precomputed_identity_hash')
+        assert hasattr(x2, '__precomputed_identity_hash')
+        assert not hasattr(x3, '__precomputed_identity_hash')
+
     def test_contains_of_empty_dict(self):
         class A(object):
             def meth(self):



More information about the Pypy-commit mailing list