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

rxe at codespeak.net rxe at codespeak.net
Fri Nov 3 16:56:33 CET 2006


Author: rxe
Date: Fri Nov  3 16:56:27 2006
New Revision: 34124

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:
specialize calls with deepfrozen arguments.  add deepfrozen to constructor on SomeLLAbstractConstant.   Propgate some more deepfrozen in some places.  (arre, rxe)

Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py	Fri Nov  3 16:56:27 2006
@@ -175,6 +175,14 @@
                     specialize = True
                 else:
                     key.append('x')
+
+                if (isinstance(arg_hs, hintmodel.SomeLLAbstractConstant)
+                    and arg_hs.deepfrozen):
+                    key.append('D')
+                    specialize = True
+                else:
+                    key.append('x')
+
             if specialize:
                 return ''.join(key)
             else:

Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Fri Nov  3 16:56:27 2006
@@ -134,13 +134,14 @@
 
 class SomeLLAbstractConstant(SomeLLAbstractValue):
     " color: dont know yet.. "
-    deepfrozen = False
-    
-    def __init__(self, T, origins, eager_concrete=False, myorigin=None):
+
+    def __init__(self, T, origins, eager_concrete=False, myorigin=None,
+                 deepfrozen=False):
         SomeLLAbstractValue.__init__(self, T)
         self.origins = origins
         self.eager_concrete = eager_concrete
         self.myorigin = myorigin
+        self.deepfrozen = deepfrozen
         assert myorigin is None or myorigin.spaceop is not None
 
     def fmt_origins(self, origins):
@@ -235,7 +236,9 @@
                         if isinstance(hs_dep, SomeLLAbstractConstant)]
         d = newset({getbookkeeper().myorigin(): True},
                    *deps_origins)
-        return SomeLLAbstractConstant(hs_v1.concretetype, d, eager_concrete=hs_v1.eager_concrete)
+        return SomeLLAbstractConstant(hs_v1.concretetype, d,
+                                      eager_concrete=hs_v1.eager_concrete,
+                                      deepfrozen=hs_v1.deepfrozen)
     else:
         return hs_v1
 
@@ -256,8 +259,6 @@
     def hint(hs_v1, hs_flags):
         if hs_flags.const.get('variable', False): # only for testing purposes!!!
             return SomeLLAbstractVariable(hs_v1.concretetype)
-        if hs_flags.const.get('concrete', False):
-            raise HintError("cannot make a concrete from %r" % (hs_v1,))
         if hs_flags.const.get('forget', False):
             # turn a variable to a constant
             origin = getbookkeeper().myorigin()
@@ -266,7 +267,9 @@
             hs_concrete = SomeLLAbstractConstant(hs_v1.concretetype, {})
             hs_concrete.eager_concrete = True
             return hs_concrete 
-            
+        raise HintError("hint %s makes no sense on %r" % (hs_flags.const,
+                                                          hs_v1))
+    
     def getfield(hs_v1, hs_fieldname):
         S = hs_v1.concretetype.TO
         FIELD_TYPE = getattr(S, hs_fieldname.const)
@@ -329,10 +332,9 @@
             assert isinstance(hs_c1, SomeLLAbstractConstant)
             return reorigin(hs_c1)
         if hs_flags.const.get('deepfreeze', False):
-            hs_concrete = SomeLLAbstractConstant(hs_c1.concretetype,
-                                                 hs_c1.origins)
-            hs_concrete.deepfrozen = True
-            return hs_concrete 
+            return SomeLLAbstractConstant(hs_c1.concretetype,
+                                          hs_c1.origins,
+                                          deepfrozen = True)
         return SomeLLAbstractValue.hint(hs_c1, hs_flags)
 
     def direct_call(hs_f1, *args_hs):
@@ -349,6 +351,7 @@
         # don't try to annotate suggested_primitive graphs
         if getattr(getattr(fnobj, '_callable', None), 'suggested_primitive', False):
             return SomeLLAbstractVariable(lltype.typeOf(fnobj).RESULT)
+
         # normal call
         if not hasattr(fnobj, 'graph'):
             raise NotImplementedError("XXX call to externals or primitives")
@@ -359,7 +362,7 @@
         if isinstance(hs_res, SomeLLAbstractConstant):
             hs_res.myorigin = bookkeeper.myorigin()
             hs_res.myorigin.is_call_result = True
-
+            
         # we need to make sure that hs_res does not become temporarily less
         # general as a result of calling another specialized version of the
         # function
@@ -371,11 +374,10 @@
         if S._hints.get('immutable', False) or hs_c1.deepfrozen:
             origin = getbookkeeper().myorigin()
             d = setadd(hs_c1.origins, origin)
-            res = SomeLLAbstractConstant(FIELD_TYPE, d,
-                                         eager_concrete=hs_c1.eager_concrete,
-                                         myorigin=origin)
-            res.deepfrozen = hs_c1.deepfrozen
-            return res
+            return SomeLLAbstractConstant(FIELD_TYPE, d,
+                                          eager_concrete=hs_c1.eager_concrete,
+                                          myorigin=origin,
+                                          deepfrozen=hs_c1.deepfrozen)
         else:
             return SomeLLAbstractVariable(FIELD_TYPE)
 
@@ -384,10 +386,9 @@
         SUB_TYPE = getattr(S, hs_fieldname.const)
         origin = getbookkeeper().myorigin()
         d = setadd(hs_c1.origins, origin)
-        res = SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d, myorigin=origin)
-        res.deepfrozen = hs_c1.deepfrozen
-        return res
-    
+        return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d,
+                                      myorigin=origin,
+                                      deepfrozen=hs_c1.deepfrozen)    
 
 class __extend__(SomeLLAbstractContainer):
 
@@ -455,7 +456,8 @@
         return SomeLLAbstractConstant(hs_c1.concretetype, d,
                                       eager_concrete = hs_c1.eager_concrete and
                                                        hs_c2.eager_concrete,
-                                      myorigin = myorigin)
+                                      myorigin = myorigin,
+                                      deepfrozen = hs_c1.deepfrozen and hs_c2.deepfrozen)
 
 
     def getarrayitem((hs_c1, hs_index)):
@@ -464,11 +466,10 @@
         if A._hints.get('immutable', False) or hs_c1.deepfrozen:
             origin = getbookkeeper().myorigin()
             d = newset(hs_c1.origins, hs_index.origins, {origin: True})
-            res = SomeLLAbstractConstant(READ_TYPE, d,
-                                         eager_concrete=hs_c1.eager_concrete,
-                                         myorigin=origin)
-            res.deepfrozen = hs_c1.deepfrozen
-            return res
+            return SomeLLAbstractConstant(READ_TYPE, d,
+                                          eager_concrete=hs_c1.eager_concrete,
+                                          myorigin=origin,
+                                          deepfrozen=hs_c1.deepfrozen)
         else:
             return SomeLLAbstractVariable(READ_TYPE)
 
@@ -573,6 +574,7 @@
     return SomeLLAbstractVariable(RESTYPE)
 
 def const_unary(hs_c1):
+    #XXX unsure hacks
     bk = getbookkeeper()
     origin = bk.myorigin()
     d = setadd(hs_c1.origins, origin)
@@ -580,8 +582,10 @@
     return SomeLLAbstractConstant(RESTYPE, d,
                                   eager_concrete = hs_c1.eager_concrete,
                                   myorigin = origin)
+                                  #deepfrozen = hs_c1.deepfrozen)
 
 def const_binary((hs_c1, hs_c2)):
+    #XXX unsure hacks
     bk = getbookkeeper()
     origin = bk.myorigin()
     d = newset(hs_c1.origins, hs_c2.origins, {origin: True})
@@ -590,6 +594,7 @@
                                   eager_concrete = hs_c1.eager_concrete or
                                                    hs_c2.eager_concrete,
                                   myorigin = origin)
+                                  #deepfrozen = hs_c1.deepfrozen and hs_c2.deepfrozen)
 
 def setup(oplist, ValueCls, var_fn, ConstantCls, const_fn):
     for name in oplist:

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	Fri Nov  3 16:56:27 2006
@@ -18,6 +18,9 @@
 P_OOPSPEC_NOVIRTUAL.oopspec = True
 P_OOPSPEC_NOVIRTUAL.novirtualcontainer = True
 
+P_NOVIRTUAL = AnnotatorPolicy()
+P_NOVIRTUAL.novirtualcontainer = True
+
 def hannotate(func, argtypes, policy=None, annotator=False, inline=None,
               backendoptimize=False):
     # build the normal ll graphs for ll_function
@@ -96,7 +99,31 @@
     hs = hannotate(ll_function, [annmodel.SomePtr(lltype.Ptr(A)), int])
     assert type(hs) is SomeLLAbstractVariable
     assert hs.concretetype == lltype.Signed
-  
+
+def test_lists_deepfreeze():
+
+    l1 = [1,2,3,4,5]
+    l2 = [6,7,8,9,10]
+    
+    def getlist(n):
+        if n:
+            return l1
+        else:
+            return l2
+    
+    def ll_function(n, i):
+        l = getlist(n)
+        l = hint(l, deepfreeze=True)
+
+        res = l[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:
@@ -429,8 +456,9 @@
     ll_add_graph = graphof(ha.base_translator, ll_add)
     gdesc = ha.bookkeeper.getdesc(ll_add_graph)    
     assert len(gdesc._cache) == 2
-    assert 'Ex' in gdesc._cache
-    v1, v2 = gdesc._cache['Ex'].getargs()
+    assert 'Exxx' in gdesc._cache
+    v1, v2 = gdesc._cache['Exxx'].getargs()
+
     assert isinstance(ha.binding(v1), SomeLLAbstractConstant)
     assert isinstance(ha.binding(v2), SomeLLAbstractConstant)
     assert ha.binding(v1).eager_concrete



More information about the Pypy-commit mailing list