Author: Carl Friedrich Bolz <[email protected]>
Branch: elidable-canfold-exception
Changeset: r70047:4ce5abc5856b
Date: 2014-03-18 09:32 +0100
http://bitbucket.org/pypy/pypy/changeset/4ce5abc5856b/
Log: make the old @elidable still usable, with a warning
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1,5 +1,6 @@
import sys
import types
+import warnings
import py
@@ -12,7 +13,7 @@
DEBUG_ELIDABLE_FUNCTIONS = False
-def elidable(canfolderror=None):
+def elidable(*args, **kwargs):
""" Decorate a function as "trace-elidable". Usually this means simply that
the function is constant-foldable, i.e. is pure and has no side-effects.
@@ -37,9 +38,7 @@
In this case, if it raises specific exception listed there, it's also
constant folded away.
"""
- if isinstance(canfolderror, types.FunctionType):
- raise Exception("@elidable was changed to a full "
- "decorator, use @elidable()")
+
def decorator(func):
if DEBUG_ELIDABLE_FUNCTIONS:
cache = {}
@@ -58,6 +57,17 @@
func._elidable_exceptions_ = canfolderror
return func
+ if len(args) == 1:
+ # non-ported
+ assert len(kwargs) == 0
+ warnings.warn("@elidable is deprecated, use @elidable() instead",
stacklevel=2)
+ canfolderror = None
+ return decorator(args[0])
+ else:
+ assert len(args) == 0
+ canfolderror = kwargs.get('canfolderror', None)
+ return decorator
+
def purefunction(*args, **kwargs):
import warnings
warnings.warn("purefunction is deprecated, use elidable instead",
DeprecationWarning)
@@ -133,7 +143,7 @@
function
"""
def decorator(func):
- elidable(func)
+ elidable()(func)
args = _get_args(func)
argstring = ", ".join(args)
code = ["def f(%s):\n" % (argstring, )]
diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py
--- a/rpython/rlib/test/test_jit.py
+++ b/rpython/rlib/test/test_jit.py
@@ -3,7 +3,7 @@
from rpython.conftest import option
from rpython.annotator.model import UnionError
from rpython.rlib.jit import (hint, we_are_jitted, JitDriver, elidable_promote,
- JitHintError, oopspec, isconstant, conditional_call)
+ JitHintError, oopspec, isconstant, conditional_call, elidable)
from rpython.rlib.rarithmetic import r_uint
from rpython.rtyper.test.tool import BaseRtypingTest
from rpython.rtyper.lltypesystem import lltype
@@ -91,6 +91,27 @@
myjitdriver = JitDriver(greens=['n'], reds=[])
py.test.raises(JitHintError, fn, 100)
+def test_elidable():
+ import warnings
+ # deprecated version
+ if 1:#with warnings.catch_warnings(record=True) as w:
+ #assert not w
+ @elidable
+ def f():
+ pass
+ assert f._elidable_function_
+ #assert "@elidable()" in w[0].message[0]
+
+ # proper version
+ @elidable()
+ def f():
+ pass
+ assert f._elidable_function_
+ @elidable(canfolderror=ValueError)
+ def f():
+ pass
+ assert f._elidable_function_
+
class TestJIT(BaseRtypingTest):
def test_hint(self):
def f():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit