[pypy-commit] pypy online-transforms: apply variable renaming to V_Type

rlamy noreply at buildbot.pypy.org
Sun Nov 9 01:27:08 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: online-transforms
Changeset: r74413:40193595f3d6
Date: 2014-11-08 18:31 +0000
http://bitbucket.org/pypy/pypy/changeset/40193595f3d6/

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
@@ -465,7 +465,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:
@@ -473,7 +473,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"):
@@ -208,13 +211,12 @@
     def renamevariables(self, mapping):
         for a in mapping:
             assert isinstance(a, Variable), a
-        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"
@@ -320,6 +322,8 @@
             newvar.concretetype = self.concretetype
         return newvar
 
+    def replace(self, mapping):
+        return mapping.get(self, self)
 
 
 class Constant(Hashable):
@@ -349,6 +353,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):
@@ -424,8 +431,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):
@@ -580,6 +587,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
@@ -76,8 +76,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


More information about the pypy-commit mailing list