Commits

Carl Friedrich Bolz committed 3e92114

start recursively generating guards for virtuals

Comments (0)

Files changed (2)

rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py

             value = OptValue(box)
         return value, box
 
-    def guards(self, info1, info2, box_or_value, expected):
+    def guards(self, info1, info2, box_or_value, expected, inputargs=None):
         value, box = self._box_or_value(box_or_value)
+        if inputargs is None:
+            inputargs = [box]
         info1.position = info2.position = 0
         guards = []
         info1.generate_guards(info2, value, self.cpu, guards, {})
-        self.compare(guards, expected, [box])
+        self.compare(guards, expected, inputargs)
 
     def compare(self, guards, expected, inputargs):
         loop = self.parse(expected)
         self.compare(guards, expected, [box2])
 
     def test_generate_guards_on_virtual_fields_matches(self):
-        py.test.skip("not yet")
         innervalue1 = OptValue(self.nodebox)
         constclassbox = self.cpu.ts.cls_of_box(self.nodebox)
         innervalue1.make_constant_class(constclassbox, -1)
         info2 = VirtualStateInfo(ConstInt(42), [1])
         info2.fieldstate = [innerinfo2]
 
-        value1 = VirtualValue(self.cpu, constclassbox, BoxInt())
+        value1 = VirtualValue(self.cpu, constclassbox, self.nodebox)
         value1._fields = {1: OptValue(self.nodebox)}
 
         expected = """
         guard_nonnull(p0) []
         guard_class(p0, ConstClass(node_vtable)) []
         """
-        self.guards(info1, info2, value1, expected)
+        self.guards(info1, info2, value1, expected, [self.nodebox])
 
     # _________________________________________________________________________
     # the below tests don't really have anything to do with guard generation

rpython/jit/metainterp/optimizeopt/virtualstate.py

 
         return True
 
+
+    def _generate_guards(self, other, value, cpu, extra_guards, renum, bad):
+        if not self._generalization_of_structpart(other):
+            raise InvalidLoop("XXX")
+
+        assert isinstance(other, AbstractVirtualStructStateInfo)
+        assert len(self.fielddescrs) == len(self.fieldstate)
+        assert len(other.fielddescrs) == len(other.fieldstate)
+        assert isinstance(value, virtualize.AbstractVirtualStructValue)
+        assert value.is_virtual()
+
+        if len(self.fielddescrs) != len(other.fielddescrs):
+            raise InvalidLoop("XXX")
+
+        for i in range(len(self.fielddescrs)):
+            if other.fielddescrs[i] is not self.fielddescrs[i]:
+                raise InvalidLoop("XXX")
+            v = value._fields[self.fielddescrs[i]] # must be there
+            self.fieldstate[i].generate_guards(other.fieldstate[i], v, cpu, extra_guards, renum)
+
+
     def _generalization_of_structpart(self, other):
         raise NotImplementedError