[pypy-commit] pypy py3k: hg merge default
antocuni
noreply at buildbot.pypy.org
Thu Jul 19 10:18:27 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r56220:5db1a1b43685
Date: 2012-07-19 10:18 +0200
http://bitbucket.org/pypy/pypy/changeset/5db1a1b43685/
Log: hg merge default
diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -225,6 +225,8 @@
assert isinstance(target_token, TargetToken)
assert loop_jitcell_token.target_tokens
loop_jitcell_token.target_tokens.append(target_token)
+ if target_token.short_preamble:
+ metainterp_sd.logger_ops.log_short_preamble([], target_token.short_preamble)
loop = partial_trace
loop.operations = loop.operations[:-1] + part.operations
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -706,6 +706,7 @@
self.virtual_state = None
self.exported_state = None
+ self.short_preamble = None
def repr_of_descr(self):
return 'TargetToken(%d)' % compute_unique_id(self)
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -241,6 +241,16 @@
# guard_nonnull_class on this value, which is rather silly.
# replace the original guard with a guard_value
old_guard_op = value.last_guard
+ if old_guard_op.getopnum() != rop.GUARD_NONNULL:
+ # This is only safe if the class of the guard_value matches the
+ # class of the guard_*_class, otherwise the intermediate ops might
+ # be executed with wrong classes.
+ previous_classbox = value.get_constant_class(self.optimizer.cpu)
+ expected_classbox = self.optimizer.cpu.ts.cls_of_box(op.getarg(1))
+ assert previous_classbox is not None
+ assert expected_classbox is not None
+ if not previous_classbox.same_constant(expected_classbox):
+ raise InvalidLoop('A GUARD_VALUE was proven to always fail')
op = old_guard_op.copy_and_change(rop.GUARD_VALUE,
args = [old_guard_op.getarg(0), op.getarg(1)])
self.optimizer.replaces_guard[op] = old_guard_op
@@ -251,6 +261,8 @@
assert isinstance(descr, compile.ResumeGuardDescr)
descr.guard_opnum = rop.GUARD_VALUE
descr.make_a_counter_per_value(op)
+ # to be safe
+ value.last_guard = None
constbox = op.getarg(1)
assert isinstance(constbox, Const)
self.optimize_guard(op, constbox)
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -7862,6 +7862,17 @@
"""
self.optimize_loop(ops, expected)
+ def test_only_strengthen_guard_if_class_matches(self):
+ ops = """
+ [p1]
+ guard_class(p1, ConstClass(node_vtable2)) []
+ guard_value(p1, ConstPtr(myptr)) []
+ jump(p1)
+ """
+ self.raises(InvalidLoop, self.optimize_loop,
+ ops, ops)
+
+
class TestLLtype(OptimizeOptTest, LLtypeMixin):
pass
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -4,7 +4,7 @@
from pypy.rpython.error import TyperError
from pypy.rlib.objectmodel import malloc_zero_filled, we_are_translated
from pypy.rlib.objectmodel import _hash_string, enforceargs
-from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib.objectmodel import keepalive_until_here, specialize
from pypy.rlib.debug import ll_assert
from pypy.rlib import jit
from pypy.rlib.rarithmetic import ovfcheck
@@ -174,7 +174,7 @@
if s:
return s
else:
- return self.ll.ll_constant(u'None')
+ return self.ll.ll_constant_unicode(u'None')
@jit.elidable
def ll_encode_latin1(self, s):
@@ -963,14 +963,13 @@
def ll_build_finish(builder):
return LLHelpers.ll_join_strs(len(builder), builder)
+ @specialize.memo()
def ll_constant(s):
- if isinstance(s, str):
- return string_repr.convert_const(s)
- elif isinstance(s, unicode):
- return unicode_repr.convert_const(s)
- else:
- assert False
- ll_constant._annspecialcase_ = 'specialize:memo'
+ return string_repr.convert_const(s)
+
+ @specialize.memo()
+ def ll_constant_unicode(s):
+ return unicode_repr.convert_const(s)
def do_stringformat(cls, hop, sourcevarsrepr):
s_str = hop.args_s[0]
diff --git a/pypy/rpython/ootypesystem/rstr.py b/pypy/rpython/ootypesystem/rstr.py
--- a/pypy/rpython/ootypesystem/rstr.py
+++ b/pypy/rpython/ootypesystem/rstr.py
@@ -1,5 +1,6 @@
from pypy.tool.pairtype import pairtype
from pypy.annotation import model as annmodel
+from pypy.rlib.objectmodel import specialize
from pypy.rlib.rarithmetic import ovfcheck
from pypy.rpython.error import TyperError
from pypy.rpython.rstr import AbstractStringRepr,AbstractCharRepr,\
@@ -84,7 +85,7 @@
if s:
return s
else:
- return self.ll.ll_constant(u'None')
+ return self.ll.ll_constant_unicode(u'None')
def ll_encode_latin1(self, value):
sb = ootype.new(ootype.StringBuilder)
@@ -310,14 +311,13 @@
def ll_build_finish(buf):
return buf.ll_build()
+ @specialize.memo()
def ll_constant(s):
- if isinstance(s, str):
- return ootype.make_string(s)
- elif isinstance(s, unicode):
- return ootype.make_unicode(s)
- else:
- assert False
- ll_constant._annspecialcase_ = 'specialize:memo'
+ return ootype.make_string(s)
+
+ @specialize.memo()
+ def ll_constant_unicode(s):
+ return ootype.make_unicode(s)
def do_stringformat(cls, hop, sourcevarsrepr):
InstanceRepr = hop.rtyper.type_system.rclass.InstanceRepr
diff --git a/pypy/rpython/test/test_runicode.py b/pypy/rpython/test/test_runicode.py
--- a/pypy/rpython/test/test_runicode.py
+++ b/pypy/rpython/test/test_runicode.py
@@ -209,6 +209,18 @@
assert self.ll_to_string(res) == const(u'before None after')
#
+ def test_strformat_unicode_and_str(self):
+ # test that we correctly specialize ll_constant when we pass both a
+ # string and an unicode to it
+ const = self.const
+ def percentS(ch):
+ x = "%s" % (ch + "bc")
+ y = u"%s" % (unichr(ord(ch)) + u"bc")
+ return len(x)+len(y)
+ #
+ res = self.interpret(percentS, ["a"])
+ assert res == 6
+
def unsupported(self):
py.test.skip("not supported")
More information about the pypy-commit
mailing list