[pypy-commit] pypy flow-no-local-exception: Kill code.

arigo noreply at buildbot.pypy.org
Thu Aug 1 10:42:23 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: flow-no-local-exception
Changeset: r65871:31b884f1dbac
Date: 2013-07-31 13:20 +0200
http://bitbucket.org/pypy/pypy/changeset/31b884f1dbac/

Log:	Kill code.

diff --git a/rpython/rtyper/lltypesystem/rlist.py b/rpython/rtyper/lltypesystem/rlist.py
--- a/rpython/rtyper/lltypesystem/rlist.py
+++ b/rpython/rtyper/lltypesystem/rlist.py
@@ -6,7 +6,7 @@
      GcStruct, Void, Signed, malloc, typeOf, nullptr, typeMethod)
 from rpython.rtyper.rlist import (AbstractBaseListRepr, AbstractListRepr,
     AbstractFixedSizeListRepr, AbstractListIteratorRepr, ll_setitem_nonneg,
-    ADTIList, ADTIFixedList, dum_nocheck)
+    ADTIList, ADTIFixedList)
 from rpython.rtyper.rmodel import Repr, inputconst, externalvsinternal
 from rpython.tool.pairtype import pairtype, pair
 
@@ -394,10 +394,9 @@
         assert v_sizehint is None
         cno = inputconst(Signed, len(items_v))
         v_result = llops.gendirectcall(LIST.ll_newlist, cno)
-    v_func = inputconst(Void, dum_nocheck)
     for i, v_item in enumerate(items_v):
         ci = inputconst(Signed, i)
-        llops.gendirectcall(ll_setitem_nonneg, v_func, v_result, ci, v_item)
+        llops.gendirectcall(ll_setitem_nonneg, v_result, ci, v_item)
     return v_result
 
 # special operations for list comprehension optimization
diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py
--- a/rpython/rtyper/rlist.py
+++ b/rpython/rtyper/rlist.py
@@ -32,10 +32,6 @@
 })
 
 
-def dum_checkidx(): pass
-def dum_nocheck(): pass
-
-
 class __extend__(annmodel.SomeList):
     def rtyper_makerepr(self, rtyper):
         listitem = self.listdef.listitem
@@ -206,11 +202,6 @@
         hop.gendirectcall(ll_extend, v_lst1, v_lst2)
 
     def rtype_method_pop(self, hop):
-        if hop.has_implicit_exception(IndexError):
-            spec = dum_checkidx
-        else:
-            spec = dum_nocheck
-        v_func = hop.inputconst(Void, spec)
         if hop.nb_args == 2:
             args = hop.inputargs(self, Signed)
             assert hasattr(args[1], 'concretetype')
@@ -226,7 +217,7 @@
             args = hop.inputargs(self)
             llfn = ll_pop_default
         hop.exception_is_here()
-        v_res = hop.gendirectcall(llfn, v_func, *args)
+        v_res = hop.gendirectcall(llfn, *args)
         return self.recast(hop.llops, v_res)
 
 
@@ -243,53 +234,31 @@
 
 class __extend__(pairtype(AbstractBaseListRepr, IntegerRepr)):
 
-    def rtype_getitem((r_lst, r_int), hop, checkidx=False):
+    def rtype_getitem((r_lst, r_int), hop):
         v_lst, v_index = hop.inputargs(r_lst, Signed)
-        if checkidx:
-            hop.exception_is_here()
-        else:
-            hop.exception_cannot_occur()
-        if hop.args_s[0].listdef.listitem.mutated or checkidx:
+        hop.exception_cannot_occur()
+        if hop.args_s[0].listdef.listitem.mutated:
             if hop.args_s[1].nonneg:
                 llfn = ll_getitem_nonneg
             else:
                 llfn = ll_getitem
-            if checkidx:
-                spec = dum_checkidx
-            else:
-                spec = dum_nocheck
-            c_func_marker = hop.inputconst(Void, spec)
-            v_res = hop.gendirectcall(llfn, c_func_marker, v_lst, v_index)
         else:
-            # this is the 'foldable' version, which is not used when
-            # we check for IndexError
+            # this is the 'foldable' version
             if hop.args_s[1].nonneg:
                 llfn = ll_getitem_foldable_nonneg
             else:
                 llfn = ll_getitem_foldable
-            v_res = hop.gendirectcall(llfn, v_lst, v_index)
+        v_res = hop.gendirectcall(llfn, v_lst, v_index)
         return r_lst.recast(hop.llops, v_res)
 
-    rtype_getitem_key = rtype_getitem
-
-    def rtype_getitem_idx((r_lst, r_int), hop):
-        return pair(r_lst, r_int).rtype_getitem(hop, checkidx=True)
-
-    rtype_getitem_idx_key = rtype_getitem_idx
-
     def rtype_setitem((r_lst, r_int), hop):
-        if hop.has_implicit_exception(IndexError):
-            spec = dum_checkidx
-        else:
-            spec = dum_nocheck
-        v_func = hop.inputconst(Void, spec)
         v_lst, v_index, v_item = hop.inputargs(r_lst, Signed, r_lst.item_repr)
         if hop.args_s[1].nonneg:
             llfn = ll_setitem_nonneg
         else:
             llfn = ll_setitem
         hop.exception_is_here()
-        return hop.gendirectcall(llfn, v_func, v_lst, v_index, v_item)
+        return hop.gendirectcall(llfn, v_lst, v_index, v_item)
 
     def rtype_mul((r_lst, r_int), hop):
         cRESLIST = hop.inputconst(Void, hop.r_result.LIST)
@@ -300,18 +269,13 @@
 class __extend__(pairtype(AbstractListRepr, IntegerRepr)):
 
     def rtype_delitem((r_lst, r_int), hop):
-        if hop.has_implicit_exception(IndexError):
-            spec = dum_checkidx
-        else:
-            spec = dum_nocheck
-        v_func = hop.inputconst(Void, spec)
         v_lst, v_index = hop.inputargs(r_lst, Signed)
         if hop.args_s[1].nonneg:
             llfn = ll_delitem_nonneg
         else:
             llfn = ll_delitem
         hop.exception_is_here()
-        return hop.gendirectcall(llfn, v_func, v_lst, v_index)
+        return hop.gendirectcall(llfn, v_lst, v_index)
 
     def rtype_inplace_mul((r_lst, r_int), hop):
         v_lst, v_factor = hop.inputargs(r_lst, Signed)
@@ -582,22 +546,16 @@
     l.ll_setitem_fast(index, newitem)
 ll_insert_nonneg.oopspec = 'list.insert(l, index, newitem)'
 
-def ll_pop_nonneg(func, l, index):
+def ll_pop_nonneg(l, index):
     ll_assert(index >= 0, "unexpectedly negative list pop index")
-    if func is dum_checkidx:
-        if index >= l.ll_length():
-            raise IndexError
-    else:
-        ll_assert(index < l.ll_length(), "list pop index out of bound")
+    ll_assert(index < l.ll_length(), "list pop index out of bound")
     res = l.ll_getitem_fast(index)
-    ll_delitem_nonneg(dum_nocheck, l, index)
+    ll_delitem_nonneg(l, index)
     return res
 ll_pop_nonneg.oopspec = 'list.pop(l, index)'
 
-def ll_pop_default(func, l):
+def ll_pop_default(l):
     length = l.ll_length()
-    if func is dum_checkidx and (length == 0):
-        raise IndexError
     ll_assert(length > 0, "pop from empty list")
     index = length - 1
     newlength = index
@@ -608,10 +566,8 @@
     l._ll_resize_le(newlength)
     return res
 
-def ll_pop_zero(func, l):
+def ll_pop_zero(l):
     length = l.ll_length()
-    if func is dum_checkidx and (length == 0):
-        raise IndexError
     ll_assert(length > 0, "pop(0) from empty list")
     newlength = length - 1
     res = l.ll_getitem_fast(0)
@@ -628,18 +584,14 @@
     return res
 ll_pop_zero.oopspec = 'list.pop(l, 0)'
 
-def ll_pop(func, l, index):
+def ll_pop(l, index):
     length = l.ll_length()
     if index < 0:
         index += length
-    if func is dum_checkidx:
-        if index < 0 or index >= length:
-            raise IndexError
-    else:
-        ll_assert(index >= 0, "negative list pop index out of bound")
-        ll_assert(index < length, "list pop index out of bound")
+    ll_assert(index >= 0, "negative list pop index out of bound")
+    ll_assert(index < length, "list pop index out of bound")
     res = l.ll_getitem_fast(index)
-    ll_delitem_nonneg(dum_nocheck, l, index)
+    ll_delitem_nonneg(l, index)
     return res
 
 @jit.look_inside_iff(lambda l: jit.isvirtual(l))
@@ -654,32 +606,18 @@
         i += 1
         length_1_i -= 1
 
-def ll_getitem_nonneg(func, l, index):
+def ll_getitem_nonneg(l, index):
     ll_assert(index >= 0, "unexpectedly negative list getitem index")
-    if func is dum_checkidx:
-        if index >= l.ll_length():
-            raise IndexError
     return l.ll_getitem_fast(index)
 ll_getitem_nonneg._always_inline_ = True
 # no oopspec -- the function is inlined by the JIT
 
-def ll_getitem(func, l, index):
-    if func is dum_checkidx:
-        length = l.ll_length()    # common case: 0 <= index < length
-        if r_uint(index) >= r_uint(length):
-            # Failed, so either (-length <= index < 0), or we have to raise
-            # IndexError.  First add 'length' to get the final index, then
-            # check that we now have (0 <= index < length).
-            index = r_uint(index) + r_uint(length)
-            if index >= r_uint(length):
-                raise IndexError
-            index = intmask(index)
-    else:
-        # We don't want checking, but still want to support index < 0.
-        # Only call ll_length() if needed.
-        if index < 0:
-            index += l.ll_length()
-            ll_assert(index >= 0, "negative list getitem index out of bound")
+def ll_getitem(l, index):
+    # We don't want checking, but still want to support index < 0.
+    # Only call ll_length() if needed.
+    if index < 0:
+        index += l.ll_length()
+        ll_assert(index >= 0, "negative list getitem index out of bound")
     return l.ll_getitem_fast(index)
 # no oopspec -- the function is inlined by the JIT
 
@@ -695,38 +633,23 @@
 ll_getitem_foldable._always_inline_ = True
 # no oopspec -- the function is inlined by the JIT
 
-def ll_setitem_nonneg(func, l, index, newitem):
+def ll_setitem_nonneg(l, index, newitem):
     ll_assert(index >= 0, "unexpectedly negative list setitem index")
-    if func is dum_checkidx:
-        if index >= l.ll_length():
-            raise IndexError
     l.ll_setitem_fast(index, newitem)
 ll_setitem_nonneg._always_inline_ = True
 # no oopspec -- the function is inlined by the JIT
 
-def ll_setitem(func, l, index, newitem):
-    if func is dum_checkidx:
-        length = l.ll_length()
-        if r_uint(index) >= r_uint(length):   # see comments in ll_getitem().
-            index = r_uint(index) + r_uint(length)
-            if index >= r_uint(length):
-                raise IndexError
-            index = intmask(index)
-    else:
-        if index < 0:
-            index += l.ll_length()
-            ll_assert(index >= 0, "negative list setitem index out of bound")
+def ll_setitem(l, index, newitem):
+    if index < 0:
+        index += l.ll_length()
+        ll_assert(index >= 0, "negative list setitem index out of bound")
     l.ll_setitem_fast(index, newitem)
 # no oopspec -- the function is inlined by the JIT
 
-def ll_delitem_nonneg(func, l, index):
+def ll_delitem_nonneg(l, index):
     ll_assert(index >= 0, "unexpectedly negative list delitem index")
     length = l.ll_length()
-    if func is dum_checkidx:
-        if index >= length:
-            raise IndexError
-    else:
-        ll_assert(index < length, "list delitem index out of bound")
+    ll_assert(index < length, "list delitem index out of bound")
     newlength = length - 1
     j = index
     j1 = j+1
@@ -741,19 +664,11 @@
     l._ll_resize_le(newlength)
 ll_delitem_nonneg.oopspec = 'list.delitem(l, index)'
 
-def ll_delitem(func, l, index):
-    if func is dum_checkidx:
-        length = l.ll_length()
-        if r_uint(index) >= r_uint(length):   # see comments in ll_getitem().
-            index = r_uint(index) + r_uint(length)
-            if index >= r_uint(length):
-                raise IndexError
-            index = intmask(index)
-    else:
-        if index < 0:
-            index += l.ll_length()
-            ll_assert(index >= 0, "negative list delitem index out of bound")
-    ll_delitem_nonneg(dum_nocheck, l, index)
+def ll_delitem(l, index):
+    if index < 0:
+        index += l.ll_length()
+        ll_assert(index >= 0, "negative list delitem index out of bound")
+    ll_delitem_nonneg(l, index)
 # no oopspec -- the function is inlined by the JIT
 
 def ll_extend(l1, l2):
@@ -989,7 +904,7 @@
 
 def ll_listremove(lst, obj, eqfn):
     index = ll_listindex(lst, obj, eqfn) # raises ValueError if obj not in lst
-    ll_delitem_nonneg(dum_nocheck, lst, index)
+    ll_delitem_nonneg(lst, index)
 
 def ll_inplace_mul(l, factor):
     if factor == 1:
diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -292,14 +292,6 @@
             return inputconst(Bool, hop.s_result.const)
         return hop.rtyper.type_system.generic_is(robj1, robj2, hop)
 
-    # default implementation for checked getitems
-
-    def rtype_getitem_idx_key((r_c1, r_o1), hop):
-        return pair(r_c1, r_o1).rtype_getitem(hop)
-
-    rtype_getitem_idx = rtype_getitem_idx_key
-    rtype_getitem_key = rtype_getitem_idx_key
-
 # ____________________________________________________________
 
 
diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py
--- a/rpython/rtyper/rrange.py
+++ b/rpython/rtyper/rrange.py
@@ -1,7 +1,6 @@
 from rpython.flowspace.model import Constant
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.lltypesystem.lltype import Signed, Void, Ptr
-from rpython.rtyper.rlist import dum_nocheck, dum_checkidx
 from rpython.rtyper.rmodel import Repr, IntegerRepr, IteratorRepr
 from rpython.tool.pairtype import pairtype
 
@@ -31,11 +30,6 @@
 class __extend__(pairtype(AbstractRangeRepr, IntegerRepr)):
 
     def rtype_getitem((r_rng, r_int), hop):
-        if hop.has_implicit_exception(IndexError):
-            spec = dum_checkidx
-        else:
-            spec = dum_nocheck
-        v_func = hop.inputconst(Void, spec)
         v_lst, v_index = hop.inputargs(r_rng, Signed)
         if r_rng.step != 0:
             cstep = hop.inputconst(Signed, r_rng.step)
@@ -46,7 +40,7 @@
         else:
             llfn = ll_rangeitem
         hop.exception_is_here()
-        return hop.gendirectcall(llfn, v_func, v_lst, v_index, cstep)
+        return hop.gendirectcall(llfn, v_lst, v_index, cstep)
 
 # ____________________________________________________________
 #
@@ -70,22 +64,13 @@
         result = 0
     return result
 
-def ll_rangeitem_nonneg(func, l, index, step):
-    if func is dum_checkidx and index >= _ll_rangelen(l.start, l.stop, step):
-        raise IndexError
+def ll_rangeitem_nonneg(l, index, step):
     return l.start + index * step
 
-def ll_rangeitem(func, l, index, step):
-    if func is dum_checkidx:
+def ll_rangeitem(l, index, step):
+    if index < 0:
         length = _ll_rangelen(l.start, l.stop, step)
-        if index < 0:
-            index += length
-        if index < 0 or index >= length:
-            raise IndexError
-    else:
-        if index < 0:
-            length = _ll_rangelen(l.start, l.stop, step)
-            index += length
+        index += length
     return l.start + index * step
 
 # ____________________________________________________________
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -446,32 +446,16 @@
 
 
 class __extend__(pairtype(AbstractStringRepr, IntegerRepr)):
-    def rtype_getitem((r_str, r_int), hop, checkidx=False):
+    def rtype_getitem((r_str, r_int), hop):
         string_repr = r_str.repr
         v_str, v_index = hop.inputargs(string_repr, Signed)
-        if checkidx:
-            if hop.args_s[1].nonneg:
-                llfn = r_str.ll.ll_stritem_nonneg_checked
-            else:
-                llfn = r_str.ll.ll_stritem_checked
+        if hop.args_s[1].nonneg:
+            llfn = r_str.ll.ll_stritem_nonneg
         else:
-            if hop.args_s[1].nonneg:
-                llfn = r_str.ll.ll_stritem_nonneg
-            else:
-                llfn = r_str.ll.ll_stritem
-        if checkidx:
-            hop.exception_is_here()
-        else:
-            hop.exception_cannot_occur()
+            llfn = r_str.ll.ll_stritem
+        hop.exception_cannot_occur()
         return hop.gendirectcall(llfn, v_str, v_index)
 
-    rtype_getitem_key = rtype_getitem
-
-    def rtype_getitem_idx((r_str, r_int), hop):
-        return pair(r_str, r_int).rtype_getitem(hop, checkidx=True)
-
-    rtype_getitem_idx_key = rtype_getitem_idx
-
     def rtype_mul((r_str, r_int), hop):
         str_repr = r_str.repr
         v_str, v_int = hop.inputargs(str_repr, Signed)
@@ -837,27 +821,12 @@
         return bool(s) and cls.ll_strlen(s) != 0
     ll_str_is_true = classmethod(ll_str_is_true)
 
-    def ll_stritem_nonneg_checked(cls, s, i):
-        if i >= cls.ll_strlen(s):
-            raise IndexError
-        return cls.ll_stritem_nonneg(s, i)
-    ll_stritem_nonneg_checked = classmethod(ll_stritem_nonneg_checked)
-
     def ll_stritem(cls, s, i):
         if i < 0:
             i += cls.ll_strlen(s)
         return cls.ll_stritem_nonneg(s, i)
     ll_stritem = classmethod(ll_stritem)
 
-    def ll_stritem_checked(cls, s, i):
-        length = cls.ll_strlen(s)
-        if i < 0:
-            i += length
-        if i >= length or i < 0:
-            raise IndexError
-        return cls.ll_stritem_nonneg(s, i)
-    ll_stritem_checked = classmethod(ll_stritem_checked)
-
     def parse_fmt_string(fmt):
         # we support x, d, s, f, [r]
         it = iter(fmt)
diff --git a/rpython/rtyper/test/test_rlist.py b/rpython/rtyper/test/test_rlist.py
--- a/rpython/rtyper/test/test_rlist.py
+++ b/rpython/rtyper/test/test_rlist.py
@@ -14,18 +14,6 @@
 from rpython.translator.translator import TranslationContext
 
 
-# undo the specialization parameter
-for n1 in 'get set del'.split():
-    for n2 in '', '_nonneg':
-        name = 'll_%sitem%s' % (n1, n2)
-        globals()['_' + name] = globals()[name]
-        exec """if 1:
-            def %s(*args):
-                return _%s(dum_checkidx, *args)
-""" % (name, name)
-del n1, n2, name
-
-
 class BaseTestListImpl:
 
     def check_list(self, l1, expected):
diff --git a/rpython/rtyper/test/test_rrange.py b/rpython/rtyper/test/test_rrange.py
--- a/rpython/rtyper/test/test_rrange.py
+++ b/rpython/rtyper/test/test_rrange.py
@@ -1,5 +1,5 @@
 from rpython.rlib.rarithmetic import intmask
-from rpython.rtyper.rrange import ll_rangelen, ll_rangeitem, ll_rangeitem_nonneg, dum_nocheck
+from rpython.rtyper.rrange import ll_rangelen, ll_rangeitem, ll_rangeitem_nonneg
 from rpython.rtyper.lltypesystem import rrange
 from rpython.rtyper.test.tool import BaseRtypingTest
 
@@ -17,11 +17,11 @@
                 RANGE = rrange.RangeRepr(step).RANGE
                 l = rrange.ll_newrange(RANGE, start, stop)
             assert ll_rangelen(l, step) == length
-            lst = [ll_rangeitem(dum_nocheck, l, i, step) for i in range(length)]
+            lst = [ll_rangeitem(l, i, step) for i in range(length)]
             assert lst == expected
-            lst = [ll_rangeitem_nonneg(dum_nocheck, l, i, step) for i in range(length)]
+            lst = [ll_rangeitem_nonneg(l, i, step) for i in range(length)]
             assert lst == expected
-            lst = [ll_rangeitem(dum_nocheck, l, i-length, step) for i in range(length)]
+            lst = [ll_rangeitem(l, i-length, step) for i in range(length)]
             assert lst == expected
 
         for start in (-10, 0, 1, 10):


More information about the pypy-commit mailing list