[pypy-commit] pypy expressions-2: apply variable renaming to V_Type

rlamy noreply at buildbot.pypy.org
Mon Nov 17 19:59:10 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: expressions-2
Changeset: r74552:51bd29ba916d
Date: 2014-11-08 18:31 +0000
http://bitbucket.org/pypy/pypy/changeset/51bd29ba916d/

Log:	apply variable renaming to V_Type

diff --git a/rpython/annotator/expression.py b/rpython/annotator/expression.py
--- a/rpython/annotator/expression.py
+++ b/rpython/annotator/expression.py
@@ -15,3 +15,9 @@
 
     def __eq__(self, other):
         return isinstance(other, V_Type) and other.arg == self.arg
+
+    def replace(self, mapping):
+        if self.arg in mapping:
+            return V_Type(mapping[self.arg])
+        else:
+            return self
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -440,7 +440,7 @@
             msg = "implicit %s shouldn't occur" % exc_cls.__name__
             w_type = Constant(AssertionError)
             w_value = Constant(AssertionError(msg))
-            link = Link([w_type, w_value], self.graph.exceptblock)
+            link = self.graph.new_raise_link(w_value, w_type)
             self.recorder.crnt_block.closeblock(link)
 
         except Raise as e:
@@ -448,7 +448,7 @@
             if w_exc.w_type == const(ImportError):
                 msg = 'import statement always raises %s' % e
                 raise ImportError(msg)
-            link = Link([w_exc.w_type, w_exc.w_value], self.graph.exceptblock)
+            link = self.graph.new_raise_link(w_exc.w_value, w_exc.w_type)
             self.recorder.crnt_block.closeblock(link)
 
         except StopFlowing:
diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -31,6 +31,9 @@
     def getreturnvar(self):
         return self.returnblock.inputargs[0]
 
+    def new_raise_link(self, v_exception, v_exc_type):
+        return Link([v_exc_type, v_exception], self.exceptblock)
+
     @property
     def source(self):
         if hasattr(self, "_source"):
@@ -206,13 +209,12 @@
         return uniqueitems([w for w in result if isinstance(w, Constant)])
 
     def renamevariables(self, mapping):
-        self.inputargs = [mapping.get(a, a) for a in self.inputargs]
-        for op in self.operations:
-            op.args = [mapping.get(a, a) for a in op.args]
-            op.result = mapping.get(op.result, op.result)
-        self.exitswitch = mapping.get(self.exitswitch, self.exitswitch)
+        self.inputargs = [a.replace(mapping) for a in self.inputargs]
+        self.operations = [op.replace(mapping) for op in self.operations]
+        if self.exitswitch is not None:
+            self.exitswitch = self.exitswitch.replace(mapping)
         for link in self.exits:
-            link.args = [mapping.get(a, a) for a in link.args]
+            link.args = [a.replace(mapping) for a in link.args]
 
     def closeblock(self, *exits):
         assert self.exits == [], "block already closed"
@@ -318,6 +320,8 @@
             newvar.concretetype = self.concretetype
         return newvar
 
+    def replace(self, mapping):
+        return mapping.get(self, self)
 
 
 class Constant(Hashable):
@@ -347,6 +351,9 @@
             # cannot count on it not mutating at runtime!
             return False
 
+    def replace(self, mapping):
+        return self
+
 
 class FSException(object):
     def __init__(self, w_type, w_value):
@@ -422,8 +429,8 @@
                                 ", ".join(map(repr, self.args)))
 
     def replace(self, mapping):
-        newargs = [mapping.get(arg, arg) for arg in self.args]
-        newresult = mapping.get(self.result, self.result)
+        newargs = [arg.replace(mapping) for arg in self.args]
+        newresult = self.result.replace(mapping)
         return type(self)(self.opname, newargs, newresult, self.offset)
 
 class Atom(object):
@@ -578,6 +585,8 @@
                     if isinstance(v, Variable):
                         if type(v) is Variable:
                             usevar(v)
+                        else:
+                            usevar(v.arg)
                     else:
                         assert v.value is not last_exception
                         #assert v.value != last_exc_value
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -74,8 +74,8 @@
         self.offset = -1
 
     def replace(self, mapping):
-        newargs = [mapping.get(arg, arg) for arg in self.args]
-        newresult = mapping.get(self.result, self.result)
+        newargs = [arg.replace(mapping) for arg in self.args]
+        newresult = self.result.replace(mapping)
         newop = type(self)(*newargs)
         newop.result = newresult
         newop.offset = self.offset
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -629,7 +629,7 @@
         assert len(links) == len(new_args)
         for link, args in zip(links, new_args):
             link.args = args
-    for block in graph.iterblocks():
+    for block in entrymap:
         block.renamevariables(renaming)
 
 def remove_identical_vars(graph):


More information about the pypy-commit mailing list