Author: Ronan Lamy <[email protected]>
Branch: var-in-Some
Changeset: r71566:74ed98b37ed2
Date: 2014-05-18 07:58 +0100
http://bitbucket.org/pypy/pypy/changeset/74ed98b37ed2/

Log:    deal with can_only_throw in HLOperation

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -468,20 +468,7 @@
         # occour for this specific, typed operation.
         if block.exitswitch == c_last_exception:
             op = block.operations[-1]
-            if op.dispatch == 2:
-                arg1 = self.binding(op.args[0])
-                arg2 = self.binding(op.args[1])
-                binop = getattr(pair(arg1, arg2), op.opname, None)
-                can_only_throw = annmodel.read_can_only_throw(binop, arg1, 
arg2)
-            elif op.dispatch == 1:
-                arg1 = self.binding(op.args[0])
-                opname = op.opname
-                if opname == 'contains': opname = 'op_contains'
-                unop = getattr(arg1, opname, None)
-                can_only_throw = annmodel.read_can_only_throw(unop, arg1)
-            else:
-                can_only_throw = None
-
+            can_only_throw = op.get_can_only_throw(self)
             if can_only_throw is not None:
                 candidates = can_only_throw
                 candidate_exits = exits
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -13,7 +13,8 @@
 from rpython.flowspace.model import (Constant, WrapException, const, Variable,
                                      SpaceOperation)
 from rpython.flowspace.specialcase import register_flow_sc
-from rpython.annotator.model import SomeTuple, AnnotatorError
+from rpython.annotator.model import (
+    SomeTuple, AnnotatorError, read_can_only_throw)
 from rpython.flowspace.specialcase import SPECIAL_CASES
 
 
@@ -101,6 +102,9 @@
         spec = type(self).get_specialization(*args_s)
         return spec(*args)
 
+    def get_can_only_throw(self, annotator):
+        return None
+
 class PureOperation(HLOperation):
     pure = True
 
@@ -155,12 +159,22 @@
                 pass
         raise AnnotatorError("Unknown operation")
 
+    def get_can_only_throw(self, annotator):
+        args_s = [annotator.binding(v) for v in self.args]
+        spec = type(self).get_specialization(*args_s)
+        return read_can_only_throw(spec, args_s[0])
+
     @classmethod
     def get_specialization(cls, s_arg, *_ignored):
         try:
             impl = getattr(s_arg, cls.opname)
+
             def specialized(arg, *other_args):
                 return impl(*[x.ann for x in other_args])
+            try:
+                specialized.can_only_throw = impl.can_only_throw
+            except AttributeError:
+                pass
             return specialized
         except AttributeError:
             return cls._dispatch(type(s_arg))
@@ -172,10 +186,20 @@
     @classmethod
     def get_specialization(cls, s_arg1, s_arg2, *_ignored):
         impl = getattr(pair(s_arg1, s_arg2), cls.opname)
+
         def specialized(arg1, arg2, *other_args):
             return impl(*[x.ann for x in other_args])
+        try:
+            specialized.can_only_throw = impl.can_only_throw
+        except AttributeError:
+            pass
         return specialized
 
+    def get_can_only_throw(self, annotator):
+        args_s = [annotator.binding(v) for v in self.args]
+        spec = type(self).get_specialization(*args_s)
+        return read_can_only_throw(spec, args_s[0], args_s[1])
+
 
 def add_operator(name, arity, dispatch=None, pyfunc=None, pure=False, 
ovf=False):
     operator_func = getattr(operator, name, None)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to