Ronan Lamy avatar Ronan Lamy committed a7c05d2

Rename FrameState.__eq__ to .matches

Comments (0)

Files changed (3)

rpython/flowspace/flowcontext.py

         candidates = self.joinpoints.setdefault(next_instr, [])
         for block in candidates:
             newstate = block.framestate.union(currentstate)
-            if newstate is None:
-                continue
-            elif newstate == block.framestate:
-                outputargs = currentstate.getoutputargs(newstate)
-                currentblock.closeblock(Link(outputargs, block))
-                return
-            else:
+            if newstate is not None:
                 break
         else:
             newstate = currentstate.copy()
             self.pendingblocks.append(newblock)
             return
 
+        if newstate.matches(block.framestate):
+            outputargs = currentstate.getoutputargs(newstate)
+            currentblock.closeblock(Link(outputargs, block))
+            return
+
         newblock = SpamBlock(newstate)
         varnames = self.pycode.co_varnames
         for name, w_value in zip(varnames, newstate.mergeable):

rpython/flowspace/framestate.py

     def getvariables(self):
         return [w for w in self.mergeable if isinstance(w, Variable)]
 
-    def __eq__(self, other):
-        """Two states are equal
-        if they only use different Variables at the same place"""
+    def matches(self, other):
+        """Two states match if they only differ by using different Variables
+        at the same place"""
         # safety check, don't try to compare states with different
         # nonmergeable states
-        assert isinstance(other, FrameState)
-        assert len(self.mergeable) == len(other.mergeable)
         assert self.blocklist == other.blocklist
         assert self.next_instr == other.next_instr
         for w1, w2 in zip(self.mergeable, other.mergeable):
                 return False
         return True
 
-    def __ne__(self, other):
-        return not (self == other)
-
     def union(self, other):
         """Compute a state that is at least as general as both self and other.
            A state 'a' is more general than a state 'b' if all Variables in 'b'

rpython/flowspace/test/test_framestate.py

         frame = self.getframe(self.func_simple)
         fs1 = frame.getstate(0)
         fs2 = frame.getstate(0)
-        assert fs1 == fs2
+        assert fs1.matches(fs2)
 
     def test_neq_hacked_framestate(self):
         frame = self.getframe(self.func_simple)
         fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
         fs2 = frame.getstate(0)
-        assert fs1 != fs2
+        assert not fs1.matches(fs2)
 
     def test_union_on_equal_framestates(self):
         frame = self.getframe(self.func_simple)
         fs1 = frame.getstate(0)
         fs2 = frame.getstate(0)
-        assert fs1.union(fs2) == fs1
+        assert fs1.union(fs2).matches(fs1)
 
     def test_union_on_hacked_framestates(self):
         frame = self.getframe(self.func_simple)
         fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
         fs2 = frame.getstate(0)
-        assert fs1.union(fs2) == fs2  # fs2 is more general
-        assert fs2.union(fs1) == fs2  # fs2 is more general
+        assert fs1.union(fs2).matches(fs2)  # fs2 is more general
+        assert fs2.union(fs1).matches(fs2)  # fs2 is more general
 
     def test_restore_frame(self):
         frame = self.getframe(self.func_simple)
         fs1 = frame.getstate(0)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
         frame.setstate(fs1)
-        assert fs1 == frame.getstate(0)
+        assert fs1.matches(frame.getstate(0))
 
     def test_copy(self):
         frame = self.getframe(self.func_simple)
         fs1 = frame.getstate(0)
         fs2 = fs1.copy()
-        assert fs1 == fs2
+        assert fs1.matches(fs2)
 
     def test_getvariables(self):
         frame = self.getframe(self.func_simple)
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.