Commits

Hakan Ardo committed 0782655

proper cloning of values

Comments (0)

Files changed (3)

pypy/jit/metainterp/optimizeopt/heap.py

             newd = {}
             new.cached_fields[descr] = newd
             for value, fieldvalue in d.items():
-                newd[value.get_reconstructed(optimizer, valuemap)] = \
-                                       fieldvalue.get_reconstructed(optimizer, valuemap)
+                newd[value.get_cloned(optimizer, valuemap)] = \
+                                       fieldvalue.get_cloned(optimizer, valuemap)
             
         for descr, d in self.known_heap_fields.items():
             newd = {}
             new.known_heap_fields[descr] = newd
             for value, fieldvalue in d.items():
-                newd[value.get_reconstructed(optimizer, valuemap)] = \
-                                       fieldvalue.get_reconstructed(optimizer, valuemap)
+                newd[value.get_cloned(optimizer, valuemap)] = \
+                                       fieldvalue.get_cloned(optimizer, valuemap)
             
         new.cached_arrayitems = {}
         for descr, d in self.cached_arrayitems.items():
             new.cached_arrayitems[descr] = newd
             for value, cache in d.items():
                 newcache = CachedArrayItems()
-                newd[value.get_reconstructed(optimizer, valuemap)] = newcache
+                newd[value.get_cloned(optimizer, valuemap)] = newcache
                 if cache.var_index_item:
                     newcache.var_index_item = \
-                          cache.var_index_item.get_reconstructed(optimizer, valuemap)
+                          cache.var_index_item.get_cloned(optimizer, valuemap)
                 if cache.var_index_indexvalue:
                     newcache.var_index_indexvalue = \
-                          cache.var_index_indexvalue.get_reconstructed(optimizer, valuemap)
+                          cache.var_index_indexvalue.get_cloned(optimizer, valuemap)
                 for index, fieldvalue in cache.fixed_index_items.items():
                     newcache.fixed_index_items[index] = \
-                           fieldvalue.get_reconstructed(optimizer, valuemap)
+                           fieldvalue.get_cloned(optimizer, valuemap)
 
         return new
 

pypy/jit/metainterp/optimizeopt/optimizer.py

     known_class = None
     intbound = None
 
-    def __init__(self, box):
+    def __init__(self, box, level=None, known_class=None, intbound=None):
         self.box = box
-        self.intbound = IntBound(MININT, MAXINT) #IntUnbounded()
+        self.level = level
+        self.known_class = known_class
+        if intbound:
+            self.intbound = intbound
+        else:
+            self.intbound = IntBound(MININT, MAXINT) #IntUnbounded()
+
         if isinstance(box, Const):
             self.make_constant(box)
         # invariant: box is a Const if and only if level == LEVEL_CONSTANT
             boxes.append(self.force_box())
             already_seen[self.get_key_box()] = None
 
-    def get_reconstructed(self, optimizer, valuemap):
+    def get_cloned(self, optimizer, valuemap):
         if self in valuemap:
             return valuemap[self]
-        new = self.reconstruct_for_next_iteration(optimizer)
+        new = self.clone_for_next_iteration(optimizer)
+        assert new.__class__ is self.__class__
+        assert new.is_virtual() == self.is_virtual()
         valuemap[self] = new
-        self.reconstruct_childs(new, valuemap)
+        self.clone_childs(new, valuemap)
         return new
 
-    def reconstruct_for_next_iteration(self, optimizer):
-        return self
+    def clone_for_next_iteration(self, optimizer):
+        return OptValue(self.box, self.level, self.known_class,
+                        self.intbound.clone())
 
-    def reconstruct_childs(self, new, valuemap):
+    def clone_childs(self, new, valuemap):
         pass
 
     def get_args_for_fail(self, modifier):
     def __init__(self, box):
         self.make_constant(box)
 
+    def clone_for_next_iteration(self, optimizer):
+        return self
+    
 CONST_0      = ConstInt(0)
 CONST_1      = ConstInt(1)
 CVAL_ZERO    = ConstantValue(CONST_0)
 
         new.values = {}
         for box, value in self.values.items():
-            new.values[box] = value.get_reconstructed(new, valuemap)
+            new.values[box] = value.get_cloned(new, valuemap)
         new.interned_refs = self.interned_refs
         new.bool_boxes = {}
         for value in new.bool_boxes.keys():
-            new.bool_boxes[value.get_reconstructed(new, valuemap)] = None
+            new.bool_boxes[value.get_cloned(new, valuemap)] = None
 
         # FIXME: Move to rewrite.py
         new.loop_invariant_results = {}
         for key, value in self.loop_invariant_results.items():
             new.loop_invariant_results[key] = \
-                                 value.get_reconstructed(new, valuemap)
+                                 value.get_cloned(new, valuemap)
             
         new.pure_operations = self.pure_operations
         new.producer = self.producer

pypy/jit/metainterp/optimizeopt/virtualize.py

     def _really_force(self):
         raise NotImplementedError("abstract base")
 
-    def reconstruct_for_next_iteration(self, _optimizer):
+    def clone_for_next_iteration(self, _optimizer):
         return optimizer.OptValue(self.force_box())
 
 def get_fielddescrlist_cache(cpu):
         else:
             boxes.append(self.box)
 
-    def reconstruct_for_next_iteration(self, optimizer):
-        self.optimizer = optimizer
-        return self
+    def clone_for_next_iteration(self, optimizer):
+        raise NotImplementedError
 
-    def reconstruct_childs(self, new, valuemap):
+    def clone_childs(self, new, valuemap):
         assert isinstance(new, AbstractVirtualStructValue)
         if new.box is None:
             lst = self._get_field_descr_list()
             for ofs in lst:
                 new._fields[ofs] = \
-                      self._fields[ofs].get_reconstructed(new.optimizer, valuemap)
+                      self._fields[ofs].get_cloned(new.optimizer, valuemap)
 
 class VirtualValue(AbstractVirtualStructValue):
     level = optimizer.LEVEL_KNOWNCLASS
         field_names = [field.name for field in self._fields]
         return "<VirtualValue cls=%s fields=%s>" % (cls_name, field_names)
 
+    def clone_for_next_iteration(self, optimizer):
+        new = VirtualValue(optimizer, self.known_class, self.keybox,
+                           self.source_op)
+        new.box = self.box
+        return new
+            
+
 class VStructValue(AbstractVirtualStructValue):
 
     def __init__(self, optimizer, structdescr, keybox, source_op=None):
         fielddescrs = self._get_field_descr_list()
         return modifier.make_vstruct(self.structdescr, fielddescrs)
 
+    def clone_for_next_iteration(self, optimizer):
+        new = VStructValue(optimizer, self.structdescr, self.keybox,
+                           self.source_op)
+        new.box = self.box
+        return new
+
+    
 class VArrayValue(AbstractVirtualValue):
 
     def __init__(self, optimizer, arraydescr, size, keybox, source_op=None):
         else:
             boxes.append(self.box)
 
-    def reconstruct_for_next_iteration(self, optimizer):
-        self.optimizer = optimizer
-        return self
+    def clone_for_next_iteration(self, optimizer):
+        new = VArrayValue(optimizer, self.arraydescr, len(self._items),
+                          self.keybox, self.source_op)
+        new.box = self.box
+        return new        
 
-    def reconstruct_childs(self, new, valuemap):
+    def clone_childs(self, new, valuemap):
         assert isinstance(new, VArrayValue)
         if new.box is None:
             for i in range(len(self._items)):
-                new._items[i] = self._items[i].get_reconstructed(new.optimizer,
-                                                                 valuemap)
+                new._items[i] = self._items[i].get_cloned(new.optimizer,
+                                                          valuemap)
 
 class OptVirtualize(optimizer.Optimization):
     "Virtualize objects until they escape."