[pypy-commit] pypy value-classes: Add test case where a virtualized value class is forced

sbauman pypy.commits at gmail.com
Tue Sep 27 23:37:18 EDT 2016


Author: Spenser Bauman <sabauma at gmail.com>
Branch: value-classes
Changeset: r87429:1994dc5dc367
Date: 2016-09-27 23:36 -0400
http://bitbucket.org/pypy/pypy/changeset/1994dc5dc367/

Log:	Add test case where a virtualized value class is forced

diff --git a/rpython/jit/metainterp/test/test_virtual.py b/rpython/jit/metainterp/test/test_virtual.py
--- a/rpython/jit/metainterp/test/test_virtual.py
+++ b/rpython/jit/metainterp/test/test_virtual.py
@@ -1022,6 +1022,7 @@
                 self.unbox = v
 
         const = Box(X(5))
+        array = [None, None]
         def f():
             # Prevent all retracing of side exits. Ensures that the unroll
             # optimizer will attempt to jump to either the preamble or loop.
@@ -1035,6 +1036,7 @@
                 driver.jit_merge_point(i=i, val=val)
                 # Logical & rather than comparison to confuse range analysis.
                 # Test only succeeds on the first 2 iterations
+                array[i % 2] = val
                 if i & -2 == 0:
                     val = X(i)
                 else:
@@ -1051,6 +1053,46 @@
             def __init__(self, v):
                 self.v = v
 
+        # A mutable cell to prevent the JIT from inferring that the non-virtual
+        # object is a constant.
+        class Box(object):
+            def __init__(self, v):
+                self.unbox = v
+
+        const = Box(X(5))
+        array = [None, None]
+        def f():
+            # Prevent all retracing of side exits. Ensures that the unroll
+            # optimizer will attempt to jump to either the preamble or loop.
+            set_param(driver, 'retrace_limit', -1)
+            set_param(driver, 'threshold', 1)
+            val   = X(0)
+            i     = 0
+            const.unbox = X(5)
+            while i < 17:
+                driver.can_enter_jit(i=i, val=val)
+                driver.jit_merge_point(i=i, val=val)
+                # Store into a constant array to force the virtual object created
+                # by the previous iteration.
+                array[i % 2] = val
+                # Logical & rather than comparison to confuse range analysis.
+                # Test only succeeds on the first 2 iterations
+                if i & -2 == 0:
+                    val = X(i)
+                else:
+                    val = const.unbox
+                i += 1
+            return 0
+
+        self.meta_interp(f, [])
+
+    def test_avoid_preamble_4(self):
+        driver = JitDriver(greens=[], reds=['i', 'val'])
+        class X(object):
+            _value_class_ = True
+            def __init__(self, v):
+                self.v = v
+
         const = X(5)
         def f():
             # Prevent all retracing of side exits. Ensures that the unroll


More information about the pypy-commit mailing list