[pypy-commit] pypy exc-later: Kill getitem_idx and all the related machinery

rlamy noreply at buildbot.pypy.org
Tue Mar 17 21:15:35 CET 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: exc-later
Changeset: r76447:4661b2eab0ed
Date: 2015-03-17 20:16 +0000
http://bitbucket.org/pypy/pypy/changeset/4661b2eab0ed/

Log:	Kill getitem_idx and all the related machinery

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -126,18 +126,6 @@
         else:
             return obj
 
-    # checked getitems
-
-    def _getitem_can_only_throw(s_c1, s_o2):
-        impl = pair(s_c1, s_o2).getitem
-        return read_can_only_throw(impl, s_c1, s_o2)
-
-    def getitem_idx((s_c1, s_o2)):
-        impl = pair(s_c1, s_o2).getitem
-        return impl()
-    getitem_idx.can_only_throw = _getitem_can_only_throw
-
-
 
 class __extend__(pairtype(SomeType, SomeType),
                  pairtype(SomeType, SomeConstantType),
@@ -563,10 +551,6 @@
         return lst1.listdef.read_item()
     getitem.can_only_throw = [IndexError]
 
-    def getitem_idx((lst1, int2)):
-        return lst1.listdef.read_item()
-    getitem_idx.can_only_throw = [IndexError]
-
     def setitem((lst1, int2), s_value):
         lst1.listdef.mutate()
         lst1.listdef.generalize(s_value)
@@ -582,10 +566,6 @@
         return SomeChar(no_nul=str1.no_nul)
     getitem.can_only_throw = [IndexError]
 
-    def getitem_idx((str1, int2)):
-        return SomeChar(no_nul=str1.no_nul)
-    getitem_idx.can_only_throw = [IndexError]
-
     def mul((str1, int2)): # xxx do we want to support this
         return SomeString(no_nul=str1.no_nul)
 
@@ -594,10 +574,6 @@
         return SomeUnicodeCodePoint()
     getitem.can_only_throw = [IndexError]
 
-    def getitem_idx((str1, int2)):
-        return SomeUnicodeCodePoint()
-    getitem_idx.can_only_throw = [IndexError]
-
     def mul((str1, int2)): # xxx do we want to support this
         return SomeUnicodeString()
 
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -421,7 +421,6 @@
 add_operator('setattr', 3, dispatch=1, pyfunc=setattr)
 add_operator('delattr', 2, dispatch=1, pyfunc=delattr)
 add_operator('getitem', 2, dispatch=2, pure=True)
-add_operator('getitem_idx', 2, dispatch=2, pure=True)
 add_operator('setitem', 3, dispatch=2)
 add_operator('delitem', 2, dispatch=2)
 add_operator('getslice', 3, dispatch=1, pyfunc=do_getslice, pure=True)
@@ -683,7 +682,6 @@
 # allows the annotator to be more precise, see test_reraiseAnything/KeyError in
 # the annotator tests
 op.getitem.canraise = [IndexError, KeyError, Exception]
-op.getitem_idx.canraise = [IndexError, KeyError, Exception]
 op.setitem.canraise = [IndexError, KeyError, Exception]
 op.delitem.canraise = [IndexError, KeyError, Exception]
 op.contains.canraise = [Exception]    # from an r_dict
diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py
--- a/rpython/rtyper/rlist.py
+++ b/rpython/rtyper/rlist.py
@@ -246,9 +246,9 @@
 
 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:
+        if hop.has_implicit_exception(IndexError):
             hop.exception_is_here()
             spec = dum_checkidx
         else:
@@ -268,9 +268,6 @@
         v_res = hop.gendirectcall(llfn, c_func_marker, c_basegetitem, v_lst, v_index)
         return r_lst.recast(hop.llops, v_res)
 
-    def rtype_getitem_idx((r_lst, r_int), hop):
-        return pair(r_lst, r_int).rtype_getitem(hop, checkidx=True)
-
     def rtype_setitem((r_lst, r_int), hop):
         if hop.has_implicit_exception(IndexError):
             spec = dum_checkidx
diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -283,12 +283,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((r_c1, r_o1), hop):
-        return pair(r_c1, r_o1).rtype_getitem(hop)
-
-
 # ____________________________________________________________
 
 
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -561,28 +561,23 @@
 
 
 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.has_implicit_exception(IndexError):
             if hop.args_s[1].nonneg:
                 llfn = r_str.ll.ll_stritem_nonneg_checked
             else:
                 llfn = r_str.ll.ll_stritem_checked
+            hop.exception_is_here()
         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()
         return hop.gendirectcall(llfn, v_str, v_index)
 
-    def rtype_getitem_idx((r_str, r_int), hop):
-        return pair(r_str, r_int).rtype_getitem(hop, checkidx=True)
-
     def rtype_mul((r_str, r_int), hop):
         str_repr = r_str.repr
         v_str, v_int = hop.inputargs(str_repr, Signed)
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -135,23 +135,6 @@
                     s_dict.dictdef.generalize_key(self.binding(op.args[1]))
 
 
-def transform_getitem(ann, blocks):
-    for block in blocks:
-        if block.canraise:
-            last_op = block.raising_op
-            if last_op.opname == 'getitem':
-                postfx = []
-                if any(issubclass(IndexError, exit.exitcase)
-                        for exit in block.exits if exit.exitcase):
-                    postfx.append('idx')
-                if postfx:
-                    Op = getattr(op, '_'.join(['getitem'] + postfx))
-                    newop = Op(*last_op.args)
-                    newop.result = last_op.result
-                    block.operations[-1] = newop
-
-
-
 def transform_dead_op_vars(self, block_subset):
     # we redo the same simplification from simplify.py,
     # to kill dead (never-followed) links,
@@ -266,7 +249,6 @@
     transform_extend_with_str_slice,
     transform_extend_with_char_count,
     transform_list_contains,
-    transform_getitem,
     ]
 
 def transform_graph(ann, extra_passes=None, block_subset=None):


More information about the pypy-commit mailing list