[pypy-commit] pypy default: Add debugging support for @elidable decorators.

arigo noreply at buildbot.pypy.org
Tue Oct 18 12:07:40 CEST 2011


Author: Armin Rigo <arigo at 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
 


More information about the pypy-commit mailing list