[pypy-commit] pypy flowoperators: Kill operation.implicit_exceptions
rlamy
noreply at buildbot.pypy.org
Sat Jul 6 02:47:30 CEST 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: flowoperators
Changeset: r65229:99b641e81673
Date: 2013-07-06 02:46 +0200
http://bitbucket.org/pypy/pypy/changeset/99b641e81673/
Log: Kill operation.implicit_exceptions
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -14,7 +14,7 @@
recursively_flatten)
from rpython.flowspace.specialcase import (rpython_print_item,
rpython_print_newline)
-from rpython.flowspace.operation import implicit_exceptions
+from rpython.flowspace.operation import op
class FlowingError(Exception):
@@ -228,6 +228,7 @@
w_exc_cls, w_exc_value = egg.inputargs[-2:]
if isinstance(egg.last_exception, Constant):
w_exc_cls = egg.last_exception
+ assert not isinstance(w_exc_cls.value, list)
raise ImplicitOperationError(w_exc_cls, w_exc_value)
# ____________________________________________________________
@@ -464,7 +465,8 @@
def do_operation_with_implicit_exceptions(self, name, *args_w):
w_result = self.do_operation(name, *args_w)
- self.handle_implicit_exceptions(implicit_exceptions.get(name))
+ oper = getattr(op, name)
+ self.handle_implicit_exceptions(oper.canraise)
return w_result
def handle_implicit_exceptions(self, exceptions):
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -24,6 +24,7 @@
self.pyfunc = pyfunc
self.pure = pure
self.can_overflow = can_overflow
+ self.canraise = []
def make_sc(self):
def sc_operator(space, args_w):
@@ -252,19 +253,18 @@
ValueError: 'val',
}
-implicit_exceptions = {
- # specifying IndexError, and KeyError beyond Exception,
- # allows the annotator to be more precise, see test_reraiseAnything/KeyError in
- # the annotator tests
- 'getitem': [IndexError, KeyError, Exception],
- 'setitem': [IndexError, KeyError, Exception],
- 'delitem': [IndexError, KeyError, Exception],
- 'contains': [Exception], # from an r_dict
- }
+# specifying IndexError, and KeyError beyond Exception,
+# allows the annotator to be more precise, see test_reraiseAnything/KeyError in
+# the annotator tests
+op.getitem.canraise = [IndexError, KeyError, Exception]
+op.setitem.canraise = [IndexError, KeyError, Exception]
+op.delitem.canraise = [IndexError, KeyError, Exception]
+op.contains.canraise = [Exception] # from an r_dict
def _add_exceptions(names, exc):
for name in names.split():
- lis = implicit_exceptions.setdefault(name, [])
+ oper = getattr(op, name)
+ lis = oper.canraise
if exc in lis:
raise ValueError, "your list is causing duplication!"
lis.append(exc)
@@ -273,12 +273,13 @@
def _add_except_ovf(names):
# duplicate exceptions and add OverflowError
for name in names.split():
- lis = implicit_exceptions.setdefault(name, [])[:]
- lis.append(OverflowError)
- implicit_exceptions[name+"_ovf"] = lis
+ oper = getattr(op, name)
+ oper_ovf = getattr(op, name+'_ovf')
+ oper_ovf.canraise = list(oper.canraise)
+ oper_ovf.canraise.append(OverflowError)
_add_exceptions("""div mod divmod truediv floordiv pow
- inplace_div inplace_mod inplace_divmod inplace_truediv
+ inplace_div inplace_mod inplace_truediv
inplace_floordiv inplace_pow""", ZeroDivisionError)
_add_exceptions("""pow inplace_pow lshift inplace_lshift rshift
inplace_rshift""", ValueError)
@@ -287,7 +288,7 @@
inplace_floordiv inplace_div inplace_mod inplace_pow
inplace_lshift""", OverflowError) # without a _ovf version
_add_except_ovf("""neg abs add sub mul
- floordiv div mod pow lshift""") # with a _ovf version
+ floordiv div mod lshift""") # with a _ovf version
_add_exceptions("""pow""",
OverflowError) # for the float case
del _add_exceptions, _add_except_ovf
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -120,7 +120,8 @@
covf = Constant(rarithmetic.ovfcheck)
def check_syntax(opname):
- exlis = operation.implicit_exceptions.get("%s_ovf" % (opname,), [])
+ oper = getattr(operation.op, opname + "_ovf")
+ exlis = oper.canraise
if OverflowError not in exlis:
raise Exception("ovfcheck in %s: Operation %s has no"
" overflow variant" % (graph.name, opname))
@@ -495,11 +496,11 @@
# look for removable operations whose result is never used
for i in range(len(block.operations)-1, -1, -1):
op = block.operations[i]
- if op.result not in read_vars:
+ if op.result not in read_vars:
if canremove(op, block):
del block.operations[i]
- elif op.opname == 'simple_call':
- # XXX we want to have a more effective and safe
+ elif op.opname == 'simple_call':
+ # XXX we want to have a more effective and safe
# way to check if this operation has side effects
# ...
if op.args and isinstance(op.args[0], Constant):
@@ -626,7 +627,7 @@
while candidates:
cand, tgts = candidates.pop()
- newexits = list(cand.exits)
+ newexits = list(cand.exits)
for case, tgt in tgts:
exit = cand.exits[case]
rrenaming = dict(zip(tgt.inputargs,exit.args))
More information about the pypy-commit
mailing list