[pypy-svn] r43473 - in pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri May 18 14:06:42 CEST 2007
Author: cfbolz
Date: Fri May 18 14:06:41 2007
New Revision: 43473
Modified:
pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/bookkeeper.py
pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/test/test_annotator.py
Log:
Allow functions to be manually marked as "pure".
Modified: pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/bookkeeper.py (original)
+++ pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/bookkeeper.py Fri May 18 14:06:41 2007
@@ -125,6 +125,14 @@
ARGTYPES = [v.concretetype for v in op.args]
return not operation.is_pure(*ARGTYPES)
+ def analyze_direct_call(self, graph, seen=None):
+ try:
+ func = graph.func
+ if getattr(func, "_pure_function_", False):
+ return False
+ except AttributeError:
+ pass
+ return graphanalyze.GraphAnalyzer.analyze_direct_call(self, graph, seen)
class HintBookkeeper(object):
Modified: pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/test/test_annotator.py (original)
+++ pypy/branch/prolog-jit-experiments/pypy/jit/hintannotator/test/test_annotator.py Fri May 18 14:06:41 2007
@@ -919,3 +919,27 @@
hs = hannotate(f, [], policy=P_NOVIRTUAL)
assert not hs.is_green()
+
+def test_manual_marking_of_pure_functions():
+ d = {}
+ def h1(s):
+ try:
+ return d[s]
+ except KeyError:
+ d[s] = r = hash(s)
+ return r
+ h1._pure_function_ = True
+ def f(n):
+ hint(n, concrete=True)
+ if n == 0:
+ s = "abc"
+ else:
+ s = "123"
+ a = h1(s)
+ return a
+
+ P = StopAtXPolicy(h1)
+ P.oopspec = True
+ P.entrypoint_returns_red = False
+ hs = hannotate(f, [int], policy=P)
+ assert hs.is_green()
More information about the Pypy-commit
mailing list