[pypy-svn] r69317 - in pypy/trunk/pypy: interpreter objspace/std rlib rlib/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Nov 16 11:31:46 CET 2009
Author: cfbolz
Date: Mon Nov 16 11:31:45 2009
New Revision: 69317
Modified:
pypy/trunk/pypy/interpreter/function.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:
A new decorator, purefunction_promote that is like purefunction but also
promotes all its arguments. Use it in a few places. Maybe should be renamed to
jit_compile_time?
Modified: pypy/trunk/pypy/interpreter/function.py
==============================================================================
--- pypy/trunk/pypy/interpreter/function.py (original)
+++ pypy/trunk/pypy/interpreter/function.py Mon Nov 16 11:31:45 2009
@@ -16,7 +16,7 @@
funccallunrolling = unrolling_iterable(range(4))
- at jit.purefunction
+ at jit.purefunction_promote
def _get_immutable_code(func):
assert not func.can_change_code
return func.code
@@ -58,7 +58,6 @@
def getcode(self):
if jit.we_are_jitted():
if not self.can_change_code:
- self = jit.hint(self, promote=True)
return _get_immutable_code(self)
return jit.hint(self.code, promote=True)
return self.code
Modified: pypy/trunk/pypy/objspace/std/sharingdict.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/sharingdict.py (original)
+++ pypy/trunk/pypy/objspace/std/sharingdict.py Mon Nov 16 11:31:45 2009
@@ -1,6 +1,6 @@
from pypy.objspace.std.dictmultiobject import IteratorImplementation
from pypy.objspace.std.dictmultiobject import W_DictMultiObject, _is_sane_hash
-from pypy.rlib.jit import purefunction, hint, we_are_jitted, unroll_safe
+from pypy.rlib.jit import purefunction_promote, hint, we_are_jitted, unroll_safe
from pypy.rlib.rweakref import RWeakValueDictionary
NUM_DIGITS = 4
@@ -32,41 +32,22 @@
self.other_structs.set(added_key, new_structure)
return new_structure
+ @purefunction_promote
def lookup_position(self, key):
- # jit helper
- self = hint(self, promote=True)
- key = hint(key, promote=True)
- return _lookup_position_shared(self, key)
+ return self.keys.get(key, -1)
+ @purefunction_promote
def get_next_structure(self, key):
- # jit helper
- self = hint(self, promote=True)
- key = hint(key, promote=True)
- newstruct = _get_next_structure_shared(self, key)
- if not we_are_jitted():
- self._size_estimate -= self.size_estimate()
- self._size_estimate += newstruct.size_estimate()
+ new_structure = self.other_structs.get(key)
+ if new_structure is None:
+ new_structure = self.new_structure(key)
+ self._size_estimate -= self.size_estimate()
+ self._size_estimate += newstruct.size_estimate()
return newstruct
+ @purefunction_promote
def size_estimate(self):
- self = hint(self, promote=True)
- return _size_estimate(self)
-
- at purefunction
-def _lookup_position_shared(self, key):
- return self.keys.get(key, -1)
-
- at purefunction
-def _get_next_structure_shared(self, key):
- new_structure = self.other_structs.get(key)
- if new_structure is None:
- new_structure = self.new_structure(key)
- return new_structure
-
- at purefunction
-def _size_estimate(self):
- return self._size_estimate >> NUM_DIGITS
-
+ return self._size_estimate >> NUM_DIGITS
class State(object):
def __init__(self, space):
Modified: pypy/trunk/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/typeobject.py (original)
+++ pypy/trunk/pypy/objspace/std/typeobject.py Mon Nov 16 11:31:45 2009
@@ -7,7 +7,8 @@
from pypy.objspace.std.dictproxyobject import W_DictProxyObject
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, we_are_jitted, dont_look_inside
+from pypy.rlib.jit import hint, purefunction_promote, we_are_jitted
+from pypy.rlib.jit import dont_look_inside
from pypy.rlib.rarithmetic import intmask, r_uint
from copy_reg import _HEAPTYPE
@@ -126,7 +127,6 @@
w_self.space.config.objspace.std.immutable_builtintypes):
return w_self._version_tag
# pure objects cannot get their version_tag changed
- w_self = hint(w_self, promote=True)
return w_self._pure_version_tag()
def getattribute_if_not_from_object(w_self):
@@ -155,7 +155,7 @@
def has_object_getattribute(w_self):
return w_self.getattribute_if_not_from_object() is None
- @purefunction
+ @purefunction_promote
def _pure_version_tag(w_self):
return w_self._version_tag
@@ -242,14 +242,12 @@
w_self = hint(w_self, promote=True)
assert space.config.objspace.std.withmethodcache
version_tag = w_self.version_tag()
- version_tag = hint(version_tag, promote=True)
if version_tag is None:
tup = w_self._lookup_where(name)
return tup
- name = hint(name, promote=True)
return w_self._pure_lookup_where_with_method_cache(name, version_tag)
- @purefunction
+ @purefunction_promote
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
@@ -662,7 +660,7 @@
def _issubtype(w_type1, w_type2):
return w_type2 in w_type1.mro_w
- at purefunction
+ at purefunction_promote
def _pure_issubtype(w_type1, w_type2, version_tag1, version_tag2):
return _issubtype(w_type1, w_type2)
@@ -672,8 +670,6 @@
if space.config.objspace.std.withtypeversion and we_are_jitted():
version_tag1 = w_type1.version_tag()
version_tag2 = w_type2.version_tag()
- version_tag1 = hint(version_tag1, promote=True)
- version_tag2 = hint(version_tag2, promote=True)
if version_tag1 is not None and version_tag2 is not None:
res = _pure_issubtype(w_type1, w_type2, version_tag1, version_tag2)
return space.newbool(res)
Modified: pypy/trunk/pypy/rlib/jit.py
==============================================================================
--- pypy/trunk/pypy/rlib/jit.py (original)
+++ pypy/trunk/pypy/rlib/jit.py Mon Nov 16 11:31:45 2009
@@ -1,3 +1,4 @@
+import py
import sys
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rlib.objectmodel import CDefinedIntSymbolic
@@ -18,6 +19,23 @@
func._jit_unroll_safe_ = True
return func
+def purefunction_promote(func):
+ import inspect
+ purefunction(func)
+ args, varargs, varkw, defaults = inspect.getargspec(func)
+ 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
+
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 Mon Nov 16 11:31:45 2009
@@ -1,5 +1,5 @@
import py
-from pypy.rlib.jit import hint, we_are_jitted, JitDriver
+from pypy.rlib.jit import hint, we_are_jitted, JitDriver, purefunction_promote
from pypy.translator.translator import TranslationContext, graphof
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rpython.lltypesystem import lltype
@@ -23,6 +23,14 @@
res = self.interpret(f, [4])
assert res == 5
+ def test_purefunction_promote(self):
+ @purefunction_promote
+ def g(x):
+ return x + 1
+ def f(x):
+ return g(x * 2)
+ res = self.interpret(f, [2])
+ assert res == 5
def test_annotate_hooks(self):
More information about the Pypy-commit
mailing list