Author: Ronan Lamy <ronan.l...@gmail.com> Branch: online-transforms Changeset: r73969:c4383641f74f Date: 2014-10-15 20:46 +0100 http://bitbucket.org/pypy/pypy/changeset/c4383641f74f/
Log: Start work on performing annotation-dependent graph transformations during the annotation phase. diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py --- a/rpython/annotator/annrpython.py +++ b/rpython/annotator/annrpython.py @@ -399,12 +399,22 @@ def flowin(self, graph, block): try: - for i, op in enumerate(block.operations): + i = 0 + while i < len(block.operations): + op = block.operations[i] self.bookkeeper.enter((graph, block, i)) try: + new_ops = op.transform(self) + if new_ops is not None: + block.operations[i:i+1] = new_ops + if not new_ops: + continue + new_ops[-1].result = op.result + op = new_ops[0] self.consider_op(op) finally: self.bookkeeper.leave() + i += 1 except BlockedInference as e: if (e.op is block.operations[-1] and diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py --- a/rpython/annotator/unaryop.py +++ b/rpython/annotator/unaryop.py @@ -699,9 +699,6 @@ def next(self): return self._emulate_call('next') - def len(self): - return self._emulate_call('__len__') - def getslice(self, s_start, s_stop): return self._emulate_call('__getslice__', s_start, s_stop) diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py --- a/rpython/flowspace/operation.py +++ b/rpython/flowspace/operation.py @@ -104,6 +104,9 @@ def get_can_only_throw(self, annotator): return None + def transform(self, annotator): + pass + class PureOperation(HLOperation): pure = True @@ -603,6 +606,15 @@ return ArgumentsForTranslation.fromshape(args_s[0].const, list(args_s[1:])) +def transform_len(hlop, annotator): + from rpython.annotator.model import SomeInstance + s_arg = annotator.annotation(hlop.args[0]) + if isinstance(s_arg, SomeInstance): + get_len = op.getattr(hlop.args[0], const('__len__')) + return [get_len, op.simple_call(get_len.result)] + +op.len.transform = transform_len + # Other functions that get directly translated to SpaceOperators func2op[type] = op.type _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit