[pypy-commit] pypy default: Test and comment for elidable functions that can raise.
arigo
noreply at buildbot.pypy.org
Thu Jul 28 18:00:18 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r46042:37f74b79d119
Date: 2011-07-28 10:05 +0200
http://bitbucket.org/pypy/pypy/changeset/37f74b79d119/
Log: Test and comment for elidable functions that can raise.
diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -407,6 +407,32 @@
# the CALL_PURE is constant-folded away by optimizeopt.py
self.check_loops(int_sub=1, call=0, call_pure=0, getfield_gc=0)
+ def test_elidable_raising(self):
+ myjitdriver = JitDriver(greens = ['m'], reds = ['n'])
+ @elidable
+ def externfn(x):
+ if x <= 0:
+ raise ValueError
+ return x - 1
+ def f(n, m):
+ while n > 0:
+ myjitdriver.can_enter_jit(n=n, m=m)
+ myjitdriver.jit_merge_point(n=n, m=m)
+ try:
+ n -= externfn(m)
+ except ValueError:
+ n -= 1
+ return n
+ res = self.meta_interp(f, [22, 6])
+ assert res == -3
+ # the CALL_PURE is constant-folded away by optimizeopt.py
+ self.check_loops(int_sub=1, call=0, call_pure=0)
+ #
+ res = self.meta_interp(f, [22, -5])
+ assert res == 0
+ # raises: becomes CALL and is not constant-folded away
+ self.check_loops(int_sub=1, call=1, call_pure=0)
+
def test_constant_across_mp(self):
myjitdriver = JitDriver(greens = [], reds = ['n'])
class X(object):
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -16,7 +16,8 @@
Most importantly it doesn't mean that an elidable function has no observable
side effect, but those side effects are idempotent (ie caching).
- For now, such a function should never raise an exception.
+ The function can raise an exception, in which case this decorator is
+ ignored.
"""
func._elidable_function_ = True
return func
More information about the pypy-commit
mailing list