[pypy-commit] pypy ssa-flow: Rename FrameState.__eq__ to .matches

rlamy noreply at buildbot.pypy.org
Wed Nov 12 19:43:15 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: ssa-flow
Changeset: r74493:5206983b39c8
Date: 2013-08-16 03:08 +0100
http://bitbucket.org/pypy/pypy/changeset/5206983b39c8/

Log:	Rename FrameState.__eq__ to .matches

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -476,13 +476,7 @@
         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()
@@ -495,6 +489,11 @@
             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):
diff --git a/rpython/flowspace/framestate.py b/rpython/flowspace/framestate.py
--- a/rpython/flowspace/framestate.py
+++ b/rpython/flowspace/framestate.py
@@ -20,13 +20,11 @@
     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):
@@ -35,9 +33,6 @@
                 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'
diff --git a/rpython/flowspace/test/test_framestate.py b/rpython/flowspace/test/test_framestate.py
--- a/rpython/flowspace/test/test_framestate.py
+++ b/rpython/flowspace/test/test_framestate.py
@@ -26,41 +26,41 @@
         ctx = self.get_context(self.func_simple)
         fs1 = ctx.getstate(0)
         fs2 = ctx.getstate(0)
-        assert fs1 == fs2
+        assert fs1.matches(fs2)
 
     def test_neq_hacked_framestate(self):
         ctx = self.get_context(self.func_simple)
         fs1 = ctx.getstate(0)
         ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
         fs2 = ctx.getstate(0)
-        assert fs1 != fs2
+        assert not fs1.matches(fs2)
 
     def test_union_on_equal_framestates(self):
         ctx = self.get_context(self.func_simple)
         fs1 = ctx.getstate(0)
         fs2 = ctx.getstate(0)
-        assert fs1.union(fs2) == fs1
+        assert fs1.union(fs2).matches(fs1)
 
     def test_union_on_hacked_framestates(self):
         ctx = self.get_context(self.func_simple)
         fs1 = ctx.getstate(0)
         ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
         fs2 = ctx.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):
         ctx = self.get_context(self.func_simple)
         fs1 = ctx.getstate(0)
         ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
         ctx.setstate(fs1)
-        assert fs1 == ctx.getstate(0)
+        assert fs1.matches(ctx.getstate(0))
 
     def test_copy(self):
         ctx = self.get_context(self.func_simple)
         fs1 = ctx.getstate(0)
         fs2 = fs1.copy()
-        assert fs1 == fs2
+        assert fs1.matches(fs2)
 
     def test_getvariables(self):
         ctx = self.get_context(self.func_simple)


More information about the pypy-commit mailing list