Author: Armin Rigo <[email protected]>
Branch: conditional_call_value
Changeset: r79465:9b7bcfa5c1e4
Date: 2015-09-05 15:40 +0200
http://bitbucket.org/pypy/pypy/changeset/9b7bcfa5c1e4/

Log:    Check in these, which were meant for "default". The compute_hash()
        test relies on RPython seeing inside the ll_strhash() function,
        which is only true in this branch.

diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py 
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -669,15 +669,20 @@
 
     def optimize_GETFIELD_GC(self, op):
         value = self.getvalue(op.getarg(0))
+        # The only interesting cases are if 'value' is an instance of
+        # AbstractVirtualStructValue.  It might not be virtual even then,
+        # but we need to check first---otherwise we can crash on
+        # getfield_gc(some_string, 'hash').
+        maybe_virtual = isinstance(value, AbstractVirtualStructValue)
         # If this is an immutable field (as indicated by op.is_always_pure())
         # then it's safe to reuse the virtual's field, even if it has been
         # forced, because it should never be written to again.
-        if value.is_forced_virtual() and op.is_always_pure():
+        if maybe_virtual and value.is_forced_virtual() and op.is_always_pure():
             fieldvalue = value.getfield(op.getdescr(), None)
             if fieldvalue is not None:
                 self.make_equal_to(op.result, fieldvalue)
                 return
-        if value.is_virtual():
+        if maybe_virtual and value.is_virtual():
             assert isinstance(value, AbstractVirtualValue)
             fieldvalue = value.getfield(op.getdescr(), None)
             if fieldvalue is None:
diff --git a/rpython/jit/metainterp/test/test_string.py 
b/rpython/jit/metainterp/test/test_string.py
--- a/rpython/jit/metainterp/test/test_string.py
+++ b/rpython/jit/metainterp/test/test_string.py
@@ -958,3 +958,18 @@
         self.meta_interp(f, [])
         self.check_simple_loop({"int_add": 1, "int_lt": 1, "guard_true": 1,
                                 'jump': 1})
+
+    def test_string_hash_2(self):
+        from rpython.rlib.objectmodel import compute_hash
+
+        jitdriver = JitDriver(greens=[], reds=['x', 'z', 'u'])
+        def f(x):
+            z = 0
+            u = 0
+            while z < 10:
+                jitdriver.jit_merge_point(x=x, z=z, u=u)
+                s = "abcdefghij"[:z]
+                u = compute_hash(s)
+                z += 1
+            return u
+        self.meta_interp(f, [42])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to