Ronan Lamy avatar Ronan Lamy committed 7e9efc5

deal with exit switches in eval_block()

Comments (0)

Files changed (2)

rpython/flowspace/simplify.py

         else:
             newblock.operations.append(newop)
             newop.result.rename(op.result)
+    subst = lambda arg: mapping.get(arg, arg)
     switch = block.exitswitch
-    try:
-        result = mapping[switch]
+    if switch is None:
+        newblock.exitswitch = None
+    elif isinstance(switch, Variable):
+        result = subst(switch)
         if isinstance(result, Constant):
-            # XXX: do something!
-            pass
-    except KeyError:
-        pass
-    newblock.exitswitch = switch
-    subst = lambda arg: mapping.get(arg, arg)
+            exit = block.exits[result.value]
+            newblock.exitswitch = None
+            newblock.closeblock(exit.copy(rename=subst))
+            return newblock
+        else:
+            newblock.exitswitch = result
+    else:
+        newblock.exitswitch = switch
     newexits = [link.copy(rename=subst) for link in block.exits]
     newblock.closeblock(*newexits)
     return newblock

rpython/flowspace/test/test_simplify.py

     assert not block2.operations
     link, = block2.exits
     assert link.args == [Constant(22), v2]
+
+def test_eval_bool_switch():
+    v1, v2 = Variable(), Variable()
+    block = Block([v1, v2])
+    on_False, on_True = Block([]), Block([])
+    op1 = op.mul(v1, Constant(3))
+    op2 = op.gt(op1.result, Constant(20))
+    block.operations = [op1, op2]
+    block.exitswitch = op2.result
+    block.closeblock(Link([], on_False), Link([], on_True))
+    block2 = eval_block(block, [Constant(7), v2])
+    assert block2.inputargs == [v2]
+    assert not block2.operations
+    assert block2.exitswitch is None
+    link, = block2.exits
+    assert link.args == []
+    assert link.target is on_True
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.