Author: Ronan Lamy <[email protected]>
Branch: annotator
Changeset: r68732:f70cd5a088d6
Date: 2014-01-17 01:18 +0000
http://bitbucket.org/pypy/pypy/changeset/f70cd5a088d6/
Log: Kill all consider_op_*() methods
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -611,19 +611,6 @@
def noreturnvalue(self, op):
return annmodel.s_ImpossibleValue # no return value (hook method)
- # XXX "contains" clash with SomeObject method
- def consider_op_contains(self, seq, elem):
- return seq.op_contains(elem)
-
- def consider_op_newtuple(self, *args):
- return annmodel.SomeTuple(items = args)
-
- def consider_op_newlist(self, *args):
- return self.bookkeeper.newlist(*args)
-
- def consider_op_newdict(self):
- return self.bookkeeper.newdict()
-
class BlockedInference(Exception):
"""This exception signals the type inference engine that the situation
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -14,6 +14,7 @@
from rpython.flowspace.model import (Constant, WrapException, const, Variable,
SpaceOperation)
from rpython.flowspace.specialcase import register_flow_sc
+from rpython.annotator.model import SomeTuple
NOT_REALLY_CONST = {
@@ -365,6 +366,37 @@
add_operator('newslice', 3)
add_operator('hint', None, dispatch=1)
+class Contains(PureOperation):
+ opname = 'contains'
+ arity = 2
+ pyfunc = staticmethod(operator.contains)
+
+ # XXX "contains" clash with SomeObject method
+ def consider(self, annotator, seq, elem):
+ return seq.op_contains(elem)
+
+
+class NewDict(HLOperation):
+ opname = 'newdict'
+ canraise = []
+ def consider(self, annotator, *args):
+ return annotator.bookkeeper.newdict()
+
+
+class NewTuple(PureOperation):
+ opname = 'newtuple'
+ pyfunc = staticmethod(lambda *args: args)
+ canraise = []
+ def consider(self, annotator, *args):
+ return SomeTuple(items=args)
+
+
+class NewList(HLOperation):
+ opname = 'newlist'
+ canraise = []
+ def consider(self, annotator, *args):
+ return annotator.bookkeeper.newlist(*args)
+
class Pow(PureOperation):
opname = 'pow'
diff --git a/rpython/flowspace/test/test_objspace.py
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -1258,6 +1258,19 @@
assert ops[1].opname == 'simple_call'
assert ops[1].args[0].value is os.unlink
+ def test_constfold_in(self):
+ def f():
+ if 'x' in "xyz":
+ return 5
+ else:
+ return 6
+ graph = self.codetest(f)
+ assert graph.startblock.operations == []
+ [link] = graph.startblock.exits
+ assert link.target is graph.returnblock
+ assert isinstance(link.args[0], Constant)
+ assert link.args[0].value == 5
+
DATA = {'x': 5,
'y': 6}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit