Hakan Ardo avatar Hakan Ardo committed db653f8

Rearange code to make value.getfiled always return a propert OptValue

Comments (0)

Files changed (3)

pypy/jit/metainterp/optimizeopt/virtualize.py

         self._fields = {}
         self._cached_sorted_fields = None
 
-    def getfield(self, ofs, default):
-        return self._fields.get(ofs, default)
+    def getfield(self, ofs, optimizer):
+        assert optimizer
+        fieldvalue = self._fields.get(ofs, None)
+        if fieldvalue is None:
+            fieldvalue = optimizer.new_const(ofs)
+        return fieldvalue
+
+    def field_is_set(self, ofs):
+        return ofs in self._fields
 
     def setfield(self, ofs, fieldvalue):
         assert isinstance(fieldvalue, optimizer.OptValue)
         # If this is an immutable field (as indicated by op.is_always_pure())
         # then it's safe to reuse the virtual's field, even if it has been
         # forced, because it should never be written to again.
-        if value.is_forced_virtual() and op.is_always_pure():
-            fieldvalue = value.getfield(op.getdescr(), None)
-            if fieldvalue is not None:
-                self.make_equal_to(op.result, fieldvalue)
-                return
+        if value.is_forced_virtual() and op.is_always_pure() and value.field_is_set(op.getdescr()):
+            fieldvalue = value.getfield(op.getdescr(), self.optimizer)
+            self.make_equal_to(op.result, fieldvalue)
+            return
         if value.is_virtual():
             assert isinstance(value, AbstractVirtualValue)
-            fieldvalue = value.getfield(op.getdescr(), None)
-            if fieldvalue is None:
-                fieldvalue = self.optimizer.new_const(op.getdescr())
+            fieldvalue = value.getfield(op.getdescr(), self.optimizer)
             self.make_equal_to(op.result, fieldvalue)
         else:
             value.ensure_nonnull()

pypy/jit/metainterp/optimizeopt/virtualstate.py

         while i < len(self.fielddescrs) and j < len(other.fielddescrs):
             if other.fielddescrs[j] is self.fielddescrs[i]:
                 new_field_value = self.fieldstate[i].make_guardable_generalization_of(other.fieldstate[j],
-                                                       value.getfield(self.fielddescrs[i], None), optimizer)
+                                                       value.getfield(self.fielddescrs[i], optimizer), optimizer)
                 if new_field_value:
                     value.setfield(self.fielddescrs[i], new_field_value)
                 i += 1
                 j += 1
             elif self.fielddescrs[i].sort_key() < other.fielddescrs[j].sort_key():
                 new_field_value = self.fieldstate[i].make_guardable_generalization_of_null(
-                                                       value.getfield(self.fielddescrs[i], None), optimizer)
+                                                       value.getfield(self.fielddescrs[i], optimizer), optimizer)
                 if new_field_value:
                     value.setfield(self.fielddescrs[i], new_field_value)
                 i += 1
             else:
                 new_field_value = other.fieldstate[j].make_guardable_generalization_of_null(
-                                                       value.getfield(other.fielddescrs[j], None), optimizer)
+                                                       value.getfield(other.fielddescrs[j], optimizer), optimizer)
                 if new_field_value:
                     value.setfield(other.fielddescrs[j], new_field_value)
                 j += 1
         while i < len(self.fielddescrs):
             new_field_value = self.fieldstate[i].make_guardable_generalization_of_null(
-                                                   value.getfield(self.fielddescrs[i], None), optimizer)
+                                                   value.getfield(self.fielddescrs[i], optimizer), optimizer)
             if new_field_value:
                 value.setfield(self.fielddescrs[i], new_field_value)
             i += 1
         while j < len(other.fielddescrs):
             new_field_value = other.fieldstate[j].make_guardable_generalization_of_null(
-                                                   value.getfield(other.fielddescrs[j], None), optimizer)
+                                                   value.getfield(other.fielddescrs[j], optimizer), optimizer)
             if new_field_value:
                 value.setfield(other.fielddescrs[j], new_field_value)
             j += 1
         if not value.is_virtual():
             raise BadVirtualState
         for i in range(len(self.fielddescrs)):
-            v = value.getfield(self.fielddescrs[i], None)
-            if v is None:
-                v = optimizer.new_const(self.fielddescrs[i])
+            v = value.getfield(self.fielddescrs[i], optimizer)
             s = self.fieldstate[i]
             if s.position > self.position:
                 s.enum_forced_boxes(boxes, v, optimizer, doforce)

pypy/jit/metainterp/test/test_virtualstate.py

 from pypy.jit.metainterp.history import TreeLoop, JitCellToken
 from pypy.jit.metainterp.optimizeopt.test.test_optimizeopt import FakeMetaInterpStaticData
 from pypy.jit.metainterp.resoperation import ResOperation, rop
-from pypy.jit.metainterp.optimizeopt.optimizer import LEVEL_UNKNOWN, LEVEL_CONSTANT, Optimizer
+from pypy.jit.metainterp.optimizeopt.optimizer import LEVEL_UNKNOWN, LEVEL_CONSTANT, Optimizer, CVAL_ZERO
 import itertools
 
 class TestBasic:
 
     def make_equal_to(self, box, value, replace=False):
         self.values[box] = value
+
+    def new_const(self, descr):
+        assert isinstance(descr, FakeDescr)
+        return CVAL_ZERO
     
     optearlyforce = None
     opaque_pointers = {}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.