[pypy-svn] r49968 - in pypy/dist/pypy: jit/hintannotator jit/hintannotator/test rpython/ootypesystem
antocuni at codespeak.net
antocuni at codespeak.net
Thu Dec 20 21:30:06 CET 2007
Author: antocuni
Date: Thu Dec 20 21:30:04 2007
New Revision: 49968
Modified:
pypy/dist/pypy/jit/hintannotator/model.py
pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
pypy/dist/pypy/rpython/ootypesystem/ootype.py
Log:
- disable oopspec in the policy for ootype tests
- add two new tests about nonfrozen lists and strings, and make them passing
- introduce the concept of "immutable types" for ootype; they are
treated as they were always deepfrozen
Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py (original)
+++ pypy/dist/pypy/jit/hintannotator/model.py Thu Dec 20 21:30:04 2007
@@ -515,30 +515,16 @@
METH = lltype.typeOf(meth)
graph_list = TYPE._lookup_graphs(name)
if not graph_list:
- # it's a method of a BuiltinType
+ # it's a graphless method of a BuiltinADTType
bk = getbookkeeper()
- origin = bk.myorigin()
- d = hs_c1.origins.copy()
- eager_concrete = hs_c1.eager_concrete
- for hs_arg in args_hs:
- d.update(hs_arg.origins)
- eager_concrete = eager_concrete or hs_arg.eager_concrete
- d.update({origin: True})
-
- RESTYPE = bk.current_op_concretetype()
- hs_res = SomeLLAbstractConstant(RESTYPE, d,
- eager_concrete = eager_concrete,
- myorigin = origin)
- # if hs_c1.is_constant(): # and hs_arg.is_constat() for all args_hs
- # XXX # constfold here?
- return hs_res
+ return handle_highlevel_operation_novirtual(bk, True, TYPE.immutable, hs_c1, *args_hs)
elif len(graph_list) == 1:
# like a direct_call
graph = graph_list.pop()
return hs_c1._call_single_graph(graph, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args
else:
# like an indirect_call
- return hs_c1._call_multiple_graphs(graph_list, METH.RESULT, hs_c1, *args_hs)
+ return hs_c1._call_multiple_graphs(graph_list, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args
def getfield(hs_c1, hs_fieldname):
S = hs_c1.concretetype.TO
@@ -731,6 +717,22 @@
# ____________________________________________________________
+def handle_highlevel_operation_novirtual(bookkeeper, ismethod, immutable, *args_hs):
+ RESULT = bookkeeper.current_op_concretetype()
+ if ismethod and (immutable or args_hs[0].deepfrozen):
+ for hs_v in args_hs:
+ if not isinstance(hs_v, SomeLLAbstractConstant):
+ break
+ else:
+ myorigin = bookkeeper.myorigin()
+ d = newset({myorigin: True}, *[hs_c.origins
+ for hs_c in args_hs])
+ return SomeLLAbstractConstant(RESULT, d,
+ eager_concrete = False, # probably
+ myorigin = myorigin)
+ return variableoftype(RESULT)
+
+
def handle_highlevel_operation(bookkeeper, ll_func, *args_hs):
# parse the oopspec and fill in the arguments
operation_name, args = ll_func.oopspec.split('(', 1)
@@ -751,19 +753,8 @@
if bookkeeper.annotator.policy.novirtualcontainer:
# "blue variables" disabled, we just return a red var all the time.
# Exception: an operation on a frozen container is constant-foldable.
- RESULT = bookkeeper.current_op_concretetype()
- if '.' in operation_name and args_hs[0].deepfrozen:
- for hs_v in args_hs:
- if not isinstance(hs_v, SomeLLAbstractConstant):
- break
- else:
- myorigin = bookkeeper.myorigin()
- d = newset({myorigin: True}, *[hs_c.origins
- for hs_c in args_hs])
- return SomeLLAbstractConstant(RESULT, d,
- eager_concrete = False, # probably
- myorigin = myorigin)
- return variableoftype(RESULT)
+ ismethod = '.' in operation_name
+ return handle_highlevel_operation_novirtual(bookkeeper, ismethod, False, *args_hs)
# --- the code below is not used any more except by test_annotator.py ---
if operation_name == 'newlist':
Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py Thu Dec 20 21:30:04 2007
@@ -71,6 +71,7 @@
graph1 = graphof(t, func)
# build hint annotator types
+ policy = self.fixpolicy(policy)
hannotator = HintAnnotator(base_translator=t, policy=policy)
hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
{OriginFlags(): True})
@@ -84,6 +85,9 @@
else:
return hs
+ def fixpolicy(self, policy):
+ return policy
+
class BaseAnnotatorTest(AbstractAnnotatorTest):
@@ -415,6 +419,25 @@
hs = self.hannotate(ll_function, [int], policy=P_OOPSPEC_NOVIRTUAL)
assert hs.is_green()
+ def test_nonfrozen_list(self):
+ lst = [5, 7, 9]
+ def ll_function(x):
+ mylist = hint(lst, concrete=True)
+ hint(x, concrete=True)
+ z = mylist[x]
+ return z
+ hs = self.hannotate(ll_function, [int], policy=P_OOPSPEC_NOVIRTUAL)
+ assert isinstance(hs, SomeLLAbstractVariable)
+
+ def test_nonfrozen_string(self):
+ s = 'foobar'
+ def ll_function(x):
+ z = s[x]
+ hint(z, concrete=True)
+ return z
+ hs = self.hannotate(ll_function, [int], policy=P_NOVIRTUAL)
+ assert hs.is_green()
+
def test_prebuilt_structure(self):
S = self.make_struct('S', ('n', lltype.Signed))
s = self.malloc(S)
@@ -1053,9 +1076,14 @@
class TestOOType(BaseAnnotatorTest):
type_system = 'ootype'
-
malloc = property(lambda self: ootype.new)
+ def fixpolicy(self, policy):
+ import copy
+ newpolicy = copy.copy(policy)
+ newpolicy.oopspec = False
+ return newpolicy
+
def make_struct(self, name, *fields, **kwds):
fields = dict(fields)
hints = kwds.pop('hints', None)
@@ -1069,11 +1097,14 @@
def skip_policy(self):
py.test.skip('fixme? (This policy is not relevant for now)')
+ # these tests fail because ootype doesn't support SomeLLAbstractContainer
test_simple_list_operations = skip_policy
test_some_more_list_operations = skip_policy
test_make_a_list = skip_policy
test_simple_struct_malloc = skip_policy
test_container_union = skip_policy
+
+ # these tests fail because of deepfreeze
test_specialize_deepfreeze_calls = skip_policy
test_deepfreeze_variables = skip_policy
test_cast_pointer_keeps_deepfreeze = skip_policy
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Thu Dec 20 21:30:04 2007
@@ -204,6 +204,7 @@
return graphs
+
class SpecializableType(OOType):
def _specialize_type(self, TYPE, generic_types):
if isinstance(TYPE, SpecializableType):
@@ -300,6 +301,8 @@
class BuiltinADTType(BuiltinType):
+ immutable = False # conservative
+
def _setup_methods(self, generic_types, can_raise=[]):
methods = {}
for name, meth in self._GENERIC_METHODS.iteritems():
@@ -325,6 +328,8 @@
class AbstractString(BuiltinADTType):
+ immutable = True
+
def __init__(self):
self._null = _null_string(self)
More information about the pypy-svn
mailing list