Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r48190:81e9199c50b9 Date: 2011-10-18 10:21 +0200 http://bitbucket.org/pypy/pypy/changeset/81e9199c50b9/
Log: Add debugging support for @elidable decorators. Disabled by default because it keeps all arguments ever passed alive. diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py --- a/pypy/rlib/jit.py +++ b/pypy/rlib/jit.py @@ -8,6 +8,8 @@ from pypy.rpython.extregistry import ExtRegistryEntry from pypy.tool.sourcetools import func_with_new_name +DEBUG_ELIDABLE_FUNCTIONS = False + def elidable(func): """ Decorate a function as "trace-elidable". This means precisely that: @@ -24,6 +26,18 @@ If a particular call to this function ends up raising an exception, then it is handled like a normal function call (this decorator is ignored). """ + if DEBUG_ELIDABLE_FUNCTIONS: + cache = {} + oldfunc = func + def func(*args): + result = oldfunc(*args) # if it raises, no caching + try: + oldresult = cache.setdefault(args, result) + except TypeError: + pass # unhashable args + else: + assert oldresult == result + return result func._elidable_function_ = True return func _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit