# [pypy-commit] pypy virtual-dicts: we now have a representation of a list of fielddescrs, I don't understand what generalization_of is supposed to do.

Tue Oct 25 01:21:31 CEST 2011

```Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: virtual-dicts
Changeset: r48402:068b20a399e7
Date: 2011-10-24 19:21 -0400
http://bitbucket.org/pypy/pypy/changeset/068b20a399e7/

Log:	we now have a representation of a list of fielddescrs, I don't
understand what generalization_of is supposed to do.

diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -288,7 +288,6 @@
self._items[index][descr] = itemvalue

def _really_force(self, optforce):
-        raise NotImplementedError
assert self.source_op is not None
if not we_are_translated():
self.source_op.name = 'FORCE ' + self.source_op.name
@@ -300,20 +299,25 @@
op = ResOperation(rop.SETINTERIORFIELD_GC, [box, ConstInt(index), subbox], None, descr=descr)
optforce.emit_operation(op)

+    def _get_list_of_descrs(self):
+        descrs = []
+        for item in self._items:
+            item_descrs = item.keys()
+            sort_descrs(item_descrs)
+            descrs.append(item_descrs)
+        return descrs
+
def get_args_for_fail(self, modifier):
if self.box is None and not modifier.already_seen_virtual(self.keybox):
+            itemdescrs = self._get_list_of_descrs()
itemboxes = []
-            values = []
-            for items in self._items:
-                descrs = items.keys()
-                sort_descrs(descrs)
-                for descr in descrs:
-                    itemboxes.append(items[descr].get_key_box())
-                    values.append(items[descr])
+            for i in range(len(self._items)):
+                for descr in itemdescrs[i]:
+                    itemboxes.append(self._items[i][descr].get_key_box())
modifier.register_virtual_fields(self.keybox, itemboxes)
-            for item in values:
-                item.get_args_for_fail(modifier)
-
+            for i in range(len(self._items)):
+                for descr in itemdescrs[i]:
+                    self._items[i][descr].get_args_for_fail(modifier)

@@ -325,7 +329,7 @@
return self

def _make_virtual(self, modifier):
-        return modifier.make_varraystruct(self.arraydescr)
+        return modifier.make_varraystruct(self.arraydescr, self._get_list_of_descrs())

class OptVirtualize(optimizer.Optimization):
diff --git a/pypy/jit/metainterp/optimizeopt/virtualstate.py b/pypy/jit/metainterp/optimizeopt/virtualstate.py
--- a/pypy/jit/metainterp/optimizeopt/virtualstate.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualstate.py
@@ -194,13 +194,29 @@
debug_print(indent + 'VArrayStateInfo(%d):' % self.position)

class VArrayStructStateInfo(AbstractVirtualStateInfo):
-    def __init__(self, arraydescr):
+    def __init__(self, arraydescr, fielddescrs):
self.arraydescr = arraydescr
+        self.fielddescrs = fielddescrs

def _enum(self, virtual_state):
for s in self.fieldstate:
s.enum(virtual_state)

+    def enum_forced_boxes(self, boxes, value, optimizer):
+        assert isinstance(value, virtualize.VArrayStructValue)
+        assert value.is_virtual()
+        p = 0
+        for i in range(len(self.fielddescrs)):
+            for j in range(len(self.fielddescrs[i])):
+                v = value._items[i][self.fielddescrs[i][j]]
+                s = self.fieldstate[p]
+                if s.position > self.position:
+                    s.enum_forced_boxes(boxes, v, optimizer)
+                p += 1
+
+        debug_print(indent + 'VArrayStructStateInfo(%d):' % self.position)
+

class NotVirtualStateInfo(AbstractVirtualStateInfo):
def __init__(self, value):
@@ -471,8 +487,8 @@
def make_varray(self, arraydescr):
return VArrayStateInfo(arraydescr)

-    def make_varraystruct(self, arraydescr):
-        return VArrayStructStateInfo(arraydescr)
+    def make_varraystruct(self, arraydescr, fielddescrs):
+        return VArrayStructStateInfo(arraydescr, fielddescrs)

class BoxNotProducable(Exception):
pass
diff --git a/pypy/jit/metainterp/resume.py b/pypy/jit/metainterp/resume.py
--- a/pypy/jit/metainterp/resume.py
+++ b/pypy/jit/metainterp/resume.py
@@ -273,8 +273,8 @@
def make_varray(self, arraydescr):
return VArrayInfo(arraydescr)

-    def make_varraystruct(self, arraydescr):
-        return VArrayStructInfo(arraydescr)
+    def make_varraystruct(self, arraydescr, fielddescrs):
+        return VArrayStructInfo(arraydescr, fielddescrs)

def make_vstrplain(self, is_unicode=False):
if is_unicode:
@@ -541,8 +541,9 @@
debug_print("\t\t", str(untag(i)))

class VArrayStructInfo(AbstractVirtualInfo):
-    def __init__(self, arraydescr):
+    def __init__(self, arraydescr, fielddescrs):
self.arraydescr = arraydescr
+        self.fielddescrs = fielddescrs

def debug_prints(self):
debug_print("\tvarraystructinfo", self.arraydescr)
```