Author: Armin Rigo <[email protected]>
Branch:
Changeset: r85028:57689fe200ad
Date: 2016-06-08 16:17 +0200
http://bitbucket.org/pypy/pypy/changeset/57689fe200ad/
Log: Give an _attrs_ in the Resume class, so that if the corresponding
"yield" point is actually never reached, the Resume instance is
never created, but the "getattr" operations don't make blocked
blocks
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -4610,6 +4610,19 @@
a.build_types(fd, [])
py.test.raises(AnnotatorError, a.build_types, fb, [])
+ def test_annotate_generator_with_unreachable_yields(self):
+ def f(n):
+ if n < 0:
+ yield 42
+ yield n
+ yield n
+ def main(n):
+ for x in f(abs(n)):
+ pass
+ #
+ a = self.RPythonAnnotator()
+ a.build_types(main, [int])
+
def g(n):
return [0, 1, 2, n]
diff --git a/rpython/flowspace/generator.py b/rpython/flowspace/generator.py
--- a/rpython/flowspace/generator.py
+++ b/rpython/flowspace/generator.py
@@ -132,13 +132,14 @@
del block.operations[index]
newlink = split_block(block, index)
newblock = newlink.target
+ varnames = get_variable_names(newlink.args)
#
class Resume(AbstractPosition):
_immutable_ = True
+ _attrs_ = varnames
block = newblock
Resume.__name__ = 'Resume%d' % len(mappings)
mappings.append(Resume)
- varnames = get_variable_names(newlink.args)
#
_insert_reads(newblock, varnames)
#
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit