Author: Ronan Lamy <[email protected]>
Branch: expressions-2
Changeset: r74560:4f0ff483dbfe
Date: 2014-11-11 00:51 +0000
http://bitbucket.org/pypy/pypy/changeset/4f0ff483dbfe/

Log:    remove op.assign hack

diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -21,10 +21,6 @@
                         if oper.dispatch == 1])
 UNARY_OPERATIONS.remove('contains')
 
[email protected](SomeObject)
-def assign(annotator, v_obj):
-    return annotator.annotation(v_obj)
-
 @op.bool.register(SomeObject)
 def bool_SomeObject(annotator, obj):
     r = SomeBool()
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -388,15 +388,19 @@
             return w_condition.value
         return self.recorder.guessbool(self, w_condition)
 
-    def record(self, spaceop):
+    def merge_point(self):
         recorder = self.recorder
         if getattr(recorder, 'final_state', None) is not None:
             self.mergeblock(recorder.crnt_block, recorder.final_state)
             raise StopFlowing
+
+    def record(self, spaceop):
+        recorder = self.recorder
         spaceop.offset = self.last_instr
         recorder.append(spaceop)
 
     def do_op(self, op):
+        self.merge_point()
         self.record(op)
         self.guessexception(op.canraise)
         return op.result
diff --git a/rpython/flowspace/generator.py b/rpython/flowspace/generator.py
--- a/rpython/flowspace/generator.py
+++ b/rpython/flowspace/generator.py
@@ -116,9 +116,8 @@
     #
     stopblock = Block([])
     op0 = op.simple_call(const(StopIteration))
-    op1 = op.assign(V_Type(op0.result))
-    stopblock.operations = [op0, op1]
-    stopblock.closeblock(Link([op1.result, op0.result], graph.exceptblock))
+    stopblock.operations = [op0]
+    stopblock.closeblock(Link([V_Type(op0.result), op0.result], 
graph.exceptblock))
     #
     for block in list(graph.iterblocks()):
         for exit in block.exits:
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -431,7 +431,6 @@
 add_operator('yield_', 1)
 add_operator('newslice', 3)
 add_operator('hint', None, dispatch=1)
-add_operator('assign', 1, dispatch=1)
 
 class Contains(SingleDispatchMixin, PureOperation):
     opname = 'contains'
@@ -453,10 +452,10 @@
         result = self.constfold()
         if result is not None:
             return result
+        ctx.merge_point()
         from rpython.annotator.expression import V_Type
         v_instance, = self.args
-        result = V_Type(v_instance)
-        return ctx.do_op(op.assign(result))
+        return V_Type(v_instance)
 
 
 class NewDict(HLOperation):
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -11,6 +11,7 @@
 from rpython.flowspace.model import (Variable, Constant,
                                      c_last_exception, checkgraph, mkentrymap)
 from rpython.flowspace.operation import OverflowingOperation, op
+from rpython.annotator.expression import V_Type
 from rpython.rlib import rarithmetic
 from rpython.translator import unsimplify
 from rpython.rtyper.lltypesystem import lloperation, lltype
@@ -72,6 +73,8 @@
             if not block1.exits:
                 break
             exit = block1.exits[0]
+            if any(isinstance(arg, V_Type) for arg in exit.args):
+                break
             assert block1 is not exit.target, (
                 "the graph contains an empty infinite loop")
             subst = dict(zip(block1.inputargs, link.args))
@@ -311,7 +314,8 @@
             for vprev, vtarg in zip(link.args, link.target.inputargs):
                 renaming[vtarg] = vprev
             def rename(v):
-                return renaming.get(v, v)
+                if v is not None:
+                    return v.replace(renaming)
             def rename_op(op):
                 op = op.replace(renaming)
                 # special case...
@@ -425,7 +429,7 @@
 # (they have no side effects, at least in R-Python)
 CanRemove = {}
 for _op in '''
-        newtuple newlist newdict bool assign
+        newtuple newlist newdict bool
         is_ id type issubtype repr str len hash getattr getitem
         pos neg abs hex oct ord invert add sub mul
         truediv floordiv div mod divmod pow lshift rshift and_ or_
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -8,6 +8,7 @@
 from rpython.flowspace.model import SpaceOperation
 from rpython.flowspace.model import Variable, Constant, Link
 from rpython.flowspace.model import c_last_exception, checkgraph
+from rpython.annotator.expression import V_Type
 from rpython.annotator import model as annmodel
 from rpython.rtyper.lltypesystem import lltype
 
@@ -134,15 +135,43 @@
                     s_dict = self.annotation(op.args[0])
                     s_dict.dictdef.generalize_key(self.binding(op.args[1]))
 
-def remove_assign(ann, block_subset):
+def remove_expr(ann, block_subset):
     for block in block_subset:
-        for i in range(len(block.operations)):
+        i = 0
+        while i < len(block.operations):
             op = block.operations[i]
-            if op.opname == 'assign':
-                new_op = op.args[0].as_operation()
-                new_op.result = op.result
-                block.operations[i] = new_op
-
+            if any(isinstance(arg, V_Type) for arg in op.args):
+                new_args = []
+                new_ops = []
+                for arg in op.args:
+                    if isinstance(arg, V_Type):
+                        new_op = arg.as_operation()
+                        new_op.result.annotation = arg.annotation
+                        new_ops.append(new_op)
+                        new_args.append(new_op.result)
+                    else:
+                        new_args.append(arg)
+                op.args = new_args
+                block.operations[i:i] = new_ops
+            else:
+                i += 1
+        for exit in block.exits:
+            if any(isinstance(arg, V_Type) for arg in exit.args):
+                new_args = []
+                new_ops = []
+                for arg in exit.args:
+                    if isinstance(arg, V_Type):
+                        new_op = arg.as_operation()
+                        new_op.result.annotation = arg.annotation
+                        new_ops.append(new_op)
+                        new_args.append(new_op.result)
+                    else:
+                        new_args.append(arg)
+                exit.args = new_args
+                if block.exitswitch == c_last_exception:
+                    block.operations[-1:-1] = new_ops
+                else:
+                    block.operations.extend(new_ops)
 
 
 def transform_dead_op_vars(self, block_subset):
@@ -259,7 +288,7 @@
     transform_extend_with_str_slice,
     transform_extend_with_char_count,
     transform_list_contains,
-    remove_assign,
+    remove_expr,
     ]
 
 def transform_graph(ann, extra_passes=None, block_subset=None):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to