[pypy-svn] r34172 - in pypy/dist/pypy/jit/hintannotator: . test

rxe at codespeak.net rxe at codespeak.net
Sat Nov 4 15:35:33 CET 2006


Author: rxe
Date: Sat Nov  4 15:35:31 2006
New Revision: 34172

Modified:
   pypy/dist/pypy/jit/hintannotator/bookkeeper.py
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
Log:
implement deepfrozen for dicts - arre,fijal,arigo,rxe

Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py	Sat Nov  4 15:35:31 2006
@@ -1,5 +1,5 @@
 from pypy.tool.tls import tlsobject
-from pypy.objspace.flow.model import copygraph, SpaceOperation
+from pypy.objspace.flow.model import copygraph, SpaceOperation, Constant
 from pypy.annotation import model as annmodel
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.algo.unionfind import UnionFind
@@ -129,12 +129,14 @@
     def immutableconstant(self, const):
         res = hintmodel.SomeLLAbstractConstant(const.concretetype, {})
         res.const = const.value
+        # we want null pointers to be deepfrozen!
+        if isinstance(const.concretetype, lltype.Ptr):
+            if not const.value:
+                res.deepfrozen = True
         return res
 
-    def immutablevalue(self, value):        
-        res = hintmodel.SomeLLAbstractConstant(lltype.typeOf(value), {})
-        res.const = value
-        return res
+    def immutablevalue(self, value):
+        return self.immutableconstant(Constant(value, lltype.typeOf(value)))
     
     def current_op_concretetype(self):
         _, block, i = self.position_key

Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Sat Nov  4 15:35:31 2006
@@ -401,6 +401,7 @@
                                       myorigin=origin,
                                       deepfrozen=hs_c1.deepfrozen)    
 
+
 class __extend__(SomeLLAbstractContainer):
 
     def setfield(hs_s1, hs_fieldname, hs_value):
@@ -484,7 +485,15 @@
         else:
             return SomeLLAbstractVariable(READ_TYPE)
 
-
+    def getarraysubstruct((hs_c1, hs_index)):
+        A = hs_c1.concretetype.TO
+        SUB_TYPE = A.OF
+        origin = getbookkeeper().myorigin()
+        d = newset(hs_c1.origins, hs_index.origins, {origin: True})
+        return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d,
+                                      myorigin=origin,
+                                      deepfrozen=hs_c1.deepfrozen)    
+        
 class __extend__(pairtype(SomeLLAbstractContainer, SomeLLAbstractContainer)):
 
     def union((hs_cont1, hs_cont2)):

Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py	Sat Nov  4 15:35:31 2006
@@ -124,6 +124,31 @@
     hs = hannotate(ll_function, [int, int], policy=P_NOVIRTUAL)
     assert hs.concretetype == lltype.Signed
 
+def test_dicts_deepfreeze():
+
+    d1 = {1:2, 2:3}
+    d2 = {2:3, 3:4}
+    
+    def getdict(n):
+        if n:
+            return d1
+        else:
+            return d2
+    
+    def ll_function(n, i):
+        d = getdict(n)
+        d = hint(d, deepfreeze=True)
+
+        res = d[i]
+        res = hint(res, concrete=True)
+        
+        res = hint(res, variable=True)
+        return res
+
+    hs = hannotate(ll_function, [int, int], policy=P_NOVIRTUAL)
+    assert hs.concretetype == lltype.Signed
+
+
 def test_simple_hint_origins():
     def ll_function(cond, x,y):
         if cond:



More information about the Pypy-commit mailing list