[pypy-svn] r71348 - in pypy/trunk/pypy: interpreter jit/metainterp objspace/std rlib rlib/test
fijal at codespeak.net
fijal at codespeak.net
Sat Feb 20 02:16:38 CET 2010
Author: fijal
Date: Sat Feb 20 02:16:34 2010
New Revision: 71348
Modified:
pypy/trunk/pypy/interpreter/function.py
pypy/trunk/pypy/jit/metainterp/codewriter.py
pypy/trunk/pypy/objspace/std/celldict.py
pypy/trunk/pypy/objspace/std/sharingdict.py
pypy/trunk/pypy/objspace/std/typeobject.py
pypy/trunk/pypy/rlib/jit.py
pypy/trunk/pypy/rlib/test/test_jit.py
Log:
Merge string-promote branch.
This branch removes most of purefunction_promote in favor of doing
an actual call in cases some arguments are not constant. Fixes
an issue with getattr(x, prefix + var) always failing a guard_value
on string identity
Modified: pypy/trunk/pypy/interpreter/function.py
==============================================================================
--- pypy/trunk/pypy/interpreter/function.py (original)
+++ pypy/trunk/pypy/interpreter/function.py Sat Feb 20 02:16:34 2010
@@ -16,7 +16,7 @@
funccallunrolling = unrolling_iterable(range(4))
- at jit.purefunction_promote
+ at jit.purefunction_promote()
def _get_immutable_code(func):
assert not func.can_change_code
return func.code
Modified: pypy/trunk/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/trunk/pypy/jit/metainterp/codewriter.py Sat Feb 20 02:16:34 2010
@@ -835,6 +835,8 @@
hints = op.args[1].value
if hints.get('promote') and op.args[0].concretetype is not lltype.Void:
self.minimize_variables()
+ from pypy.rpython.lltypesystem.rstr import STR
+ assert op.args[0].concretetype != lltype.Ptr(STR)
self.emit('guard_value', self.var_position(op.args[0]))
self.register_var(op.result)
else:
Modified: pypy/trunk/pypy/objspace/std/celldict.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/celldict.py (original)
+++ pypy/trunk/pypy/objspace/std/celldict.py Sat Feb 20 02:16:34 2010
@@ -28,10 +28,11 @@
if makenew or jit.we_are_jitted():
# when we are jitting, we always go through the pure function
# below, to ensure that we have no residual dict lookup
+ self = jit.hint(self, promote=True)
return self._getcell_makenew(key)
return self.content.get(key, None)
- @jit.purefunction_promote
+ @jit.purefunction
def _getcell_makenew(self, key):
res = self.content.get(key, None)
if res is not None:
Modified: pypy/trunk/pypy/objspace/std/sharingdict.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/sharingdict.py (original)
+++ pypy/trunk/pypy/objspace/std/sharingdict.py Sat Feb 20 02:16:34 2010
@@ -1,6 +1,7 @@
from pypy.objspace.std.dictmultiobject import IteratorImplementation
from pypy.objspace.std.dictmultiobject import W_DictMultiObject, _is_sane_hash
-from pypy.rlib.jit import purefunction_promote, hint, we_are_jitted, unroll_safe
+from pypy.rlib.jit import purefunction_promote, we_are_jitted, unroll_safe
+from pypy.rlib.jit import purefunction
from pypy.rlib.rweakref import RWeakValueDictionary
NUM_DIGITS = 4
@@ -32,11 +33,11 @@
self.other_structs.set(added_key, new_structure)
return new_structure
- @purefunction_promote
+ @purefunction_promote('0')
def lookup_position(self, key):
return self.keys.get(key, -1)
- @purefunction_promote
+ @purefunction_promote('0')
def get_next_structure(self, key):
new_structure = self.other_structs.get(key)
if new_structure is None:
@@ -45,7 +46,7 @@
self._size_estimate += new_structure.size_estimate()
return new_structure
- @purefunction_promote
+ @purefunction_promote()
def size_estimate(self):
return self._size_estimate >> NUM_DIGITS
Modified: pypy/trunk/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/typeobject.py (original)
+++ pypy/trunk/pypy/objspace/std/typeobject.py Sat Feb 20 02:16:34 2010
@@ -9,7 +9,7 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.objectmodel import current_object_addr_as_int, compute_hash
from pypy.rlib.jit import hint, purefunction_promote, we_are_jitted
-from pypy.rlib.jit import dont_look_inside
+from pypy.rlib.jit import dont_look_inside, purefunction
from pypy.rlib.rarithmetic import intmask, r_uint
from copy_reg import _HEAPTYPE
@@ -157,7 +157,7 @@
def has_object_getattribute(w_self):
return w_self.getattribute_if_not_from_object() is None
- @purefunction_promote
+ @purefunction_promote()
def _pure_version_tag(w_self):
return w_self._version_tag
@@ -255,13 +255,13 @@
space = w_self.space
w_self = hint(w_self, promote=True)
assert space.config.objspace.std.withmethodcache
- version_tag = w_self.version_tag()
+ version_tag = hint(w_self.version_tag(), promote=True)
if version_tag is None:
tup = w_self._lookup_where(name)
return tup
return w_self._pure_lookup_where_with_method_cache(name, version_tag)
- @purefunction_promote
+ @purefunction
def _pure_lookup_where_with_method_cache(w_self, name, version_tag):
space = w_self.space
SHIFT = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
@@ -679,7 +679,7 @@
def _issubtype(w_type1, w_type2):
return w_type2 in w_type1.mro_w
- at purefunction_promote
+ at purefunction_promote()
def _pure_issubtype(w_type1, w_type2, version_tag1, version_tag2):
return _issubtype(w_type1, w_type2)
Modified: pypy/trunk/pypy/rlib/jit.py
==============================================================================
--- pypy/trunk/pypy/rlib/jit.py (original)
+++ pypy/trunk/pypy/rlib/jit.py Sat Feb 20 02:16:34 2010
@@ -25,24 +25,27 @@
func._jit_loop_invariant_ = True
return func
-
-def purefunction_promote(func):
- import inspect
- purefunction(func)
- args, varargs, varkw, defaults = inspect.getargspec(func)
- args = ["v%s" % (i, ) for i in range(len(args))]
- assert varargs is None and varkw is None
- assert not defaults
- argstring = ", ".join(args)
- code = ["def f(%s):\n" % (argstring, )]
- for arg in args:
- code.append(" %s = hint(%s, promote=True)\n" % (arg, arg))
- code.append(" return func(%s)\n" % (argstring, ))
- d = {"func": func, "hint": hint}
- exec py.code.Source("\n".join(code)).compile() in d
- result = d["f"]
- result.func_name = func.func_name + "_promote"
- return result
+def purefunction_promote(promote_args='all'):
+ def decorator(func):
+ import inspect
+ purefunction(func)
+ args, varargs, varkw, defaults = inspect.getargspec(func)
+ args = ["v%s" % (i, ) for i in range(len(args))]
+ assert varargs is None and varkw is None
+ assert not defaults
+ argstring = ", ".join(args)
+ code = ["def f(%s):\n" % (argstring, )]
+ if promote_args != 'all':
+ args = [('v%d' % int(i)) for i in promote_args.split(",")]
+ for arg in args:
+ code.append(" %s = hint(%s, promote=True)\n" % (arg, arg))
+ code.append(" return func(%s)\n" % (argstring, ))
+ d = {"func": func, "hint": hint}
+ exec py.code.Source("\n".join(code)).compile() in d
+ result = d["f"]
+ result.func_name = func.func_name + "_promote"
+ return result
+ return decorator
class Entry(ExtRegistryEntry):
_about_ = hint
Modified: pypy/trunk/pypy/rlib/test/test_jit.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_jit.py (original)
+++ pypy/trunk/pypy/rlib/test/test_jit.py Sat Feb 20 02:16:34 2010
@@ -25,7 +25,7 @@
assert res == 5
def test_purefunction_promote(self):
- @purefunction_promote
+ @purefunction_promote()
def g(func):
return func + 1
def f(x):
@@ -33,6 +33,30 @@
res = self.interpret(f, [2])
assert res == 5
+ def test_purefunction_promote_args(self):
+ @purefunction_promote(promote_args='0')
+ def g(func, x):
+ return func + 1
+ def f(x):
+ return g(x * 2, x)
+
+ import dis
+ from StringIO import StringIO
+ import sys
+
+ s = StringIO()
+ sys.stdout = s
+ dis.dis(g)
+ sys.stdout = sys.__stdout__
+ x = s.getvalue().find('CALL_FUNCTION')
+ assert x != -1
+ x = s.getvalue().find('CALL_FUNCTION', x)
+ assert x != -1
+ x = s.getvalue().find('CALL_FUNCTION', x)
+ assert x != -1
+ res = self.interpret(f, [2])
+ assert res == 5
+
def test_annotate_hooks(self):
def can_inline(m): pass
More information about the Pypy-commit
mailing list