[pypy-svn] r78977 - in pypy/branch/rlist-jit/pypy: annotation interpreter module/exceptions objspace/std rlib

arigo at codespeak.net arigo at codespeak.net
Wed Nov 10 17:55:03 CET 2010


Author: arigo
Date: Wed Nov 10 17:55:01 2010
New Revision: 78977

Modified:
   pypy/branch/rlist-jit/pypy/annotation/policy.py
   pypy/branch/rlist-jit/pypy/annotation/specialize.py
   pypy/branch/rlist-jit/pypy/interpreter/pycode.py
   pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/rlist-jit/pypy/objspace/std/objspace.py
   pypy/branch/rlist-jit/pypy/rlib/debug.py
Log:
Remove again space.newtuple_imm(), as its job can nicely be done
with a specialization.


Modified: pypy/branch/rlist-jit/pypy/annotation/policy.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/annotation/policy.py	(original)
+++ pypy/branch/rlist-jit/pypy/annotation/policy.py	Wed Nov 10 17:55:01 2010
@@ -1,6 +1,7 @@
 # base annotation policy for specialization
 from pypy.annotation.specialize import default_specialize as default
 from pypy.annotation.specialize import specialize_argvalue, specialize_argtype, specialize_arglistitemtype
+from pypy.annotation.specialize import specialize_list_not_modified_any_more
 from pypy.annotation.specialize import memo
 # for some reason, model must be imported first,
 # or we create a cycle.
@@ -75,6 +76,7 @@
     specialize__arg = staticmethod(specialize_argvalue) # specialize:arg(N)
     specialize__argtype = staticmethod(specialize_argtype) # specialize:argtype(N)
     specialize__arglistitemtype = staticmethod(specialize_arglistitemtype)
+    specialize__list_not_modified_any_more = staticmethod(specialize_list_not_modified_any_more)
 
     def specialize__ll(pol, *args):
         from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy

Modified: pypy/branch/rlist-jit/pypy/annotation/specialize.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/annotation/specialize.py	(original)
+++ pypy/branch/rlist-jit/pypy/annotation/specialize.py	Wed Nov 10 17:55:01 2010
@@ -369,3 +369,8 @@
     else:
         key = s.listdef.listitem.s_value.knowntype
     return maybe_star_args(funcdesc, key, args_s)
+    
+def specialize_list_not_modified_any_more(funcdesc, args_s, i):
+    s = args_s[i]
+    key = (s.knowntype is list and s.listdef.listitem.must_not_mutate)
+    return maybe_star_args(funcdesc, key, args_s)

Modified: pypy/branch/rlist-jit/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/interpreter/pycode.py	(original)
+++ pypy/branch/rlist-jit/pypy/interpreter/pycode.py	Wed Nov 10 17:55:01 2010
@@ -269,10 +269,10 @@
         dis.dis(co)
 
     def fget_co_consts(space, self):
-        return space.newtuple_imm(self.co_consts_w)
+        return space.newtuple(self.co_consts_w)
     
     def fget_co_names(space, self):
-        return space.newtuple_imm(self.co_names_w)
+        return space.newtuple(self.co_names_w)
 
     def fget_co_varnames(space, self):
         return space.newtuple([space.wrap(name) for name in self.co_varnames])
@@ -383,8 +383,8 @@
             w(self.co_stacksize), 
             w(self.co_flags),
             w(self.co_code), 
-            space.newtuple_imm(self.co_consts_w), 
-            space.newtuple_imm(self.co_names_w), 
+            space.newtuple(self.co_consts_w), 
+            space.newtuple(self.co_names_w), 
             space.newtuple([w(v) for v in self.co_varnames]), 
             w(self.co_filename),
             w(self.co_name), 

Modified: pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py	Wed Nov 10 17:55:01 2010
@@ -113,12 +113,12 @@
         elif lgt == 1:
             return space.str(self.args_w[0])
         else:
-            return space.str(space.newtuple_imm(self.args_w))
+            return space.str(space.newtuple(self.args_w))
     descr_str.unwrap_spec = ['self', ObjSpace]
 
     def descr_repr(self, space):
         if self.args_w:
-            args_repr = space.str_w(space.repr(space.newtuple_imm(self.args_w)))
+            args_repr = space.str_w(space.repr(space.newtuple(self.args_w)))
         else:
             args_repr = "()"
         clsname = self.getclass(space).getname(space, '?')
@@ -126,13 +126,13 @@
     descr_repr.unwrap_spec = ['self', ObjSpace]
 
     def descr_getargs(space, self):
-        return space.newtuple_imm(self.args_w)
+        return space.newtuple(self.args_w)
 
     def descr_setargs(space, self, w_newargs):
         self.args_w = space.fixedview(w_newargs)
 
     def descr_getitem(self, space, w_index):
-        return space.getitem(space.newtuple_imm(self.args_w), w_index)
+        return space.getitem(space.newtuple(self.args_w), w_index)
     descr_getitem.unwrap_spec = ['self', ObjSpace, W_Root]
 
     def getdict(self):
@@ -146,7 +146,7 @@
         self.w_dict = w_dict
 
     def descr_reduce(self, space):
-        lst = [self.getclass(space), space.newtuple_imm(self.args_w)]
+        lst = [self.getclass(space), space.newtuple(self.args_w)]
         if self.w_dict is not None and space.is_true(self.w_dict):
             lst = lst + [self.w_dict]
         return space.newtuple(lst)
@@ -294,7 +294,7 @@
     elif len(self.args_w) == 1:
         return space.repr(self.args_w[0])
     else:
-        return space.str(space.newtuple_imm(self.args_w))
+        return space.str(space.newtuple(self.args_w))
 key_error_str.unwrap_spec = ['self', ObjSpace]
     
 W_KeyError = _new_exception('KeyError', W_LookupError,
@@ -336,7 +336,7 @@
             lst = [self.getclass(space), space.newtuple(
                 self.args_w + [self.w_filename])]
         else:
-            lst = [self.getclass(space), space.newtuple_imm(self.args_w)]
+            lst = [self.getclass(space), space.newtuple(self.args_w)]
         if self.w_dict is not None and space.is_true(self.w_dict):
             lst = lst + [self.w_dict]
         return space.newtuple(lst)
@@ -520,7 +520,7 @@
         if len(args_w) == 1:
             self.w_code = args_w[0]
         elif len(args_w) > 1:
-            self.w_code = space.newtuple_imm(args_w)
+            self.w_code = space.newtuple(args_w)
         W_BaseException.descr_init(self, space, args_w)
     descr_init.unwrap_spec = ['self', ObjSpace, 'args_w']
 

Modified: pypy/branch/rlist-jit/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/rlist-jit/pypy/objspace/std/objspace.py	Wed Nov 10 17:55:01 2010
@@ -266,12 +266,7 @@
     def newtuple(self, list_w):
         assert isinstance(list_w, list)
         return W_TupleObject(list_not_modified_any_more(list_w))
-
-    def newtuple_imm(self, list_w):
-        # call this instead of newtuple() if the list already has
-        # the annotation 'list_not_modified_any_more()'
-        assert isinstance(list_w, list)
-        return W_TupleObject(list_w)
+    newtuple._annspecialcase_ = 'specialize:list_not_modified_any_more(1)'
 
     def newlist(self, list_w):
         return W_ListObject(list_w)

Modified: pypy/branch/rlist-jit/pypy/rlib/debug.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/rlib/debug.py	(original)
+++ pypy/branch/rlist-jit/pypy/rlib/debug.py	Wed Nov 10 17:55:01 2010
@@ -239,15 +239,6 @@
     def compute_result_annotation(self, s_arg):
         from pypy.annotation.model import SomeList
         assert isinstance(s_arg, SomeList)
-        # check that we don't call list_not_modified_any_more() on a list that
-        # is already the result of a previous list_not_modified_any_more().
-        # This helps locating issues in a pypy translation: if newtuple() is
-        # first annotated with a list that comes e.g. from fixedview(), it
-        # will immediately crash here instead of later when newtuple() is
-        # also annotated with a normal list.
-        assert not s_arg.listdef.listitem.must_not_mutate, (
-            "argument already has the flag 'must_not_mutate'")
-        s_arg.listdef.mutate()
         # the logic behind it is that we try not to propagate
         # make_sure_not_resized, when list comprehension is not on
         if self.bookkeeper.annotator.translator.config.translation.list_comprehension_operations:



More information about the Pypy-commit mailing list