Commits

Armin Rigo committed 16b746c

Write direct tests for the feature documented as "hack hack hack" in
optimizeopt.py. There were none :-( Bad me. Also, streamline it a
bit.

  • Participants
  • Parent commits c475d8b

Comments (0)

Files changed (2)

File pypy/jit/metainterp/optimizeopt.py

             # replace the original guard with a guard_value
             old_guard_op = self.newoperations[value.last_guard_index]
             old_opnum = old_guard_op.opnum
-            old_guard_op.opnum = op.opnum
+            old_guard_op.opnum = rop.GUARD_VALUE
             old_guard_op.args = [old_guard_op.args[0], op.args[1]]
-            if old_opnum == rop.GUARD_NONNULL:
-                # hack hack hack.  Change the guard_opnum on
-                # old_guard_op.descr so that when resuming,
-                # the operation is not skipped by pyjitpl.py.
-                descr = old_guard_op.descr
-                assert isinstance(descr, compile.ResumeGuardDescr)
-                descr.guard_opnum = rop.GUARD_NONNULL_CLASS
+            # hack hack hack.  Change the guard_opnum on
+            # old_guard_op.descr so that when resuming,
+            # the operation is not skipped by pyjitpl.py.
+            descr = old_guard_op.descr
+            assert isinstance(descr, compile.ResumeGuardDescr)
+            descr.guard_opnum = rop.GUARD_VALUE
             emit_operation = False
         constbox = op.args[1]
         assert isinstance(constbox, Const)

File pypy/jit/metainterp/test/test_optimizeopt.py

         self.optimize_loop(ops, "Not, Not, Not, Not, Not", expected)
 
     def test_merge_guard_nonnull_guard_class(self):
+        self.make_fail_descr()
         ops = """
         [p1, i0, i1, i2, p2]
-        guard_nonnull(p1) [i0]
+        guard_nonnull(p1, descr=fdescr) [i0]
         i3 = int_add(i1, i2)
         guard_class(p1, ConstClass(node_vtable)) [i1]
         jump(p2, i0, i1, i3, p2)
         """
         expected = """
         [p1, i0, i1, i2, p2]
-        guard_nonnull_class(p1, ConstClass(node_vtable)) [i0]
+        guard_nonnull_class(p1, ConstClass(node_vtable), descr=fdescr) [i0]
         i3 = int_add(i1, i2)
         jump(p2, i0, i1, i3, p2)
         """
         self.optimize_loop(ops, "Not, Not, Not, Not, Not", expected)
+        self.check_expanded_fail_descr("i0", rop.GUARD_NONNULL_CLASS)
 
     def test_merge_guard_nonnull_guard_value(self):
+        self.make_fail_descr()
         ops = """
         [p1, i0, i1, i2, p2]
-        guard_nonnull(p1) [i0]
+        guard_nonnull(p1, descr=fdescr) [i0]
         i3 = int_add(i1, i2)
         guard_value(p1, ConstPtr(myptr)) [i1]
         jump(p2, i0, i1, i3, p2)
         """
         expected = """
         [p1, i0, i1, i2, p2]
-        guard_value(p1, ConstPtr(myptr)) [i0]
+        guard_value(p1, ConstPtr(myptr), descr=fdescr) [i0]
         i3 = int_add(i1, i2)
         jump(p2, i0, i1, i3, p2)
         """
         self.optimize_loop(ops, "Not, Not, Not, Not, Not", expected)
+        self.check_expanded_fail_descr("i0", rop.GUARD_VALUE)
 
     def test_merge_guard_nonnull_guard_class_guard_value(self):
+        self.make_fail_descr()
         ops = """
         [p1, i0, i1, i2, p2]
-        guard_nonnull(p1) [i0]
+        guard_nonnull(p1, descr=fdescr) [i0]
         i3 = int_add(i1, i2)
         guard_class(p1, ConstClass(node_vtable)) [i2]
         i4 = int_sub(i3, 1)
         """
         expected = """
         [p1, i0, i1, i2, p2]
-        guard_value(p1, ConstPtr(myptr)) [i0]
+        guard_value(p1, ConstPtr(myptr), descr=fdescr) [i0]
         i3 = int_add(i1, i2)
         i4 = int_sub(i3, 1)
         jump(p2, i0, i1, i4, p2)
         """
         self.optimize_loop(ops, "Not, Not, Not, Not, Not", expected)
+        self.check_expanded_fail_descr("i0", rop.GUARD_VALUE)
 
     def test_guard_class_oois(self):
         ops = """
                 _variables_equal(fieldbox, fieldvalue.strip(), strict=False)
                 index += 1
 
-    def check_expanded_fail_descr(self, expectedtext):
+    def check_expanded_fail_descr(self, expectedtext, guard_opnum):
         guard_op, = [op for op in self.loop.operations if op.is_guard()]
         fail_args = guard_op.fail_args
         fdescr = guard_op.descr
+        assert fdescr.guard_opnum == guard_opnum
         reader = resume.ResumeDataReader(fdescr, fail_args,
                                          MyMetaInterp(self.cpu))
         boxes = reader.consume_boxes()
         jump(1, i3)
         """
         self.optimize_loop(ops, 'Not, Not', expected)
-        self.check_expanded_fail_descr('15, i3')
+        self.check_expanded_fail_descr('15, i3', rop.GUARD_TRUE)
 
     def test_expand_fail_2(self):
         self.make_fail_descr()
         self.optimize_loop(ops, 'Not, Not', expected)
         self.check_expanded_fail_descr('''ptr
             where ptr is a node_vtable, valuedescr=i2
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_3(self):
         self.make_fail_descr()
         self.check_expanded_fail_descr('''p1, i3
             where p1 is a node_vtable, valuedescr=1, nextdescr=p2
             where p2 is a node_vtable, valuedescr=i2, nextdescr=p3
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_4(self):
         for arg in ['p1', 'p1,i2', 'i2,p1', 'p1,p2', 'p2,p1',
             self.optimize_loop(ops % arg, 'Not, Not, Not', expected)
             self.check_expanded_fail_descr('''i3, %s, i3
                 where p1 is a node_vtable, valuedescr=i2, nextdescr=p2
-                where p2 is a node_vtable, valuedescr=i2''' % arg)
-
+                where p2 is a node_vtable, valuedescr=i2''' % arg,
+                                           rop.GUARD_TRUE)
 
     def test_expand_fail_5(self):
         self.make_fail_descr()
         self.check_expanded_fail_descr('''p1, i3, p2, i4
             where p1 is a node_vtable, valuedescr=i4, nextdescr=p2
             where p2 is a node_vtable, valuedescr=i2, nextdescr=p1
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_6(self):
         self.make_fail_descr()
                                    Not, Not''', expected)
         self.check_expanded_fail_descr('''p0
             where p0 is a node_vtable, valuedescr=i1b
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_varray(self):
         self.make_fail_descr()
         self.optimize_loop(ops, 'Not', expected)
         self.check_expanded_fail_descr('''p1
             where p1 is a varray arraydescr: 25, i1
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_vstruct(self):
         self.make_fail_descr()
         self.optimize_loop(ops, 'Not, Not', expected)
         self.check_expanded_fail_descr('''p2
             where p2 is a vstruct ssize, adescr=i1, bdescr=p1
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_v_all_1(self):
         self.make_fail_descr()
             where p6s is a vstruct ssize, adescr=ia, bdescr=p7v
             where p5s is a vstruct ssize, adescr=i2, bdescr=p7v
             where p7v is a node_vtable, valuedescr=iv
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_lazy_setfield_1(self):
         self.make_fail_descr()
         self.check_expanded_fail_descr('''
             p1.nextdescr = p2
             where p2 is a node_vtable, valuedescr=i2
-            ''')
+            ''', rop.GUARD_TRUE)
 
     def test_expand_fail_lazy_setfield_2(self):
         self.make_fail_descr()
         self.check_expanded_fail_descr('''
             ConstPtr(myptr).nextdescr = p2
             where p2 is a node_vtable, valuedescr=i2
-            ''')
+            ''', rop.GUARD_TRUE)
 
 
 class TestLLtype(BaseTestOptimizeOpt, LLtypeMixin):
         self.check_expanded_fail_descr('''p2, p1
             where p1 is a node_vtable, nextdescr=p1b
             where p1b is a node_vtable, valuedescr=i1
-            ''')
+            ''', rop.GUARD_NOT_FORCED)
 
     def test_vref_virtual_and_lazy_setfield(self):
         self.make_fail_descr()
             where p2 is a jit_virtual_ref_vtable, virtualtokendescr=i3, virtualrefindexdescr=2
             where p1 is a node_vtable, nextdescr=p1b
             where p1b is a node_vtable, valuedescr=i1
-            ''')
+            ''', rop.GUARD_NO_EXCEPTION)
 
     def test_vref_virtual_after_finish(self):
         self.make_fail_descr()