Commits

Armin Rigo committed 81e9199

Add debugging support for @elidable decorators.
Disabled by default because it keeps all arguments ever passed alive.

Comments (0)

Files changed (1)

 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:
     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