[pypy-svn] r52553 - in pypy/dist/pypy/translator: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Mar 15 10:24:59 CET 2008
Author: arigo
Date: Sat Mar 15 10:24:59 2008
New Revision: 52553
Modified:
pypy/dist/pypy/translator/simplify.py
pypy/dist/pypy/translator/test/test_simplify.py
Log:
Test and fix.
Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py (original)
+++ pypy/dist/pypy/translator/simplify.py Sat Mar 15 10:24:59 2008
@@ -812,13 +812,15 @@
self.variable_families = variable_families
self.reachable_cache = {}
- def enum_blocks_from(self, fromblock, avoid):
+ def enum_blocks_with_vlist_from(self, fromblock, avoid):
found = {avoid: True}
pending = [fromblock]
while pending:
block = pending.pop()
if block in found:
continue
+ if not self.vlist_alive(block):
+ continue
yield block
found[block] = True
for exit in block.exits:
@@ -986,8 +988,9 @@
# This candidate loop is acceptable if the list is not escaping
# too early, i.e. in the loop header or in the loop body.
- loopheader = list(self.enum_blocks_from(newlistblock,
+ loopheader = list(self.enum_blocks_with_vlist_from(newlistblock,
avoid=loopnextblock))
+ assert loopheader[0] is newlistblock
escapes = False
for block in loopheader + loopbody.keys():
assert self.vlist_alive(block)
Modified: pypy/dist/pypy/translator/test/test_simplify.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_simplify.py (original)
+++ pypy/dist/pypy/translator/test/test_simplify.py Sat Mar 15 10:24:59 2008
@@ -202,47 +202,63 @@
e = py.test.raises(LLException, 'interp.eval_graph(graph, [])')
assert 'ValueError' in str(e)
-def test_detect_list_comprehension():
- def f1(l):
- return [x*17 for x in l]
-
- t = TranslationContext(list_comprehension_operations=True)
- graph = t.buildflowgraph(f1)
- if conftest.option.view:
- graph.show()
- assert summary(graph) == {
- 'newlist': 1,
- 'iter': 1,
- 'next': 1,
- 'mul': 1,
- 'getattr': 1,
- 'simple_call': 1,
- 'hint': 2,
- }
-
-def test_detect_list_comprehension_with_exc():
- def g(x):
- return x * 17
- def free_some_stuff():
- pass
- def f1(l):
- try:
- return [g(x) for x in l]
- finally:
- free_some_stuff()
-
- t = TranslationContext(list_comprehension_operations=True)
- graph = t.buildflowgraph(f1)
- if conftest.option.view:
- graph.show()
- assert summary(graph) == {
- 'newlist': 1,
- 'iter': 1,
- 'next': 1,
- 'getattr': 1,
- 'simple_call': 4,
- 'hint': 2,
- }
+class TestDetectListComprehension:
+ def check(self, f1, expected):
+ t = TranslationContext(list_comprehension_operations=True)
+ graph = t.buildflowgraph(f1)
+ if conftest.option.view:
+ graph.show()
+ assert summary(graph) == expected
+
+ def test_simple(self):
+ def f1(l):
+ return [x*17 for x in l]
+ self.check(f1, {
+ 'newlist': 1,
+ 'iter': 1,
+ 'next': 1,
+ 'mul': 1,
+ 'getattr': 1,
+ 'simple_call': 1,
+ 'hint': 2,
+ })
+
+ def test_with_exc(self):
+ def g(x):
+ return x * 17
+ def free_some_stuff():
+ pass
+ def f1(l):
+ try:
+ return [g(x) for x in l]
+ finally:
+ free_some_stuff()
+ self.check(f1, {
+ 'newlist': 1,
+ 'iter': 1,
+ 'next': 1,
+ 'getattr': 1,
+ 'simple_call': 4,
+ 'hint': 2,
+ })
+
+ def test_canraise_before_iter(self):
+ def g(l):
+ return l
+ def f1(l):
+ try:
+ return [x*17 for x in g(l)]
+ except ValueError:
+ return []
+ self.check(f1, {
+ 'newlist': 2,
+ 'iter': 1,
+ 'next': 1,
+ 'mul': 1,
+ 'getattr': 1,
+ 'simple_call': 2,
+ 'hint': 2,
+ })
class TestLLSpecializeListComprehension:
typesystem = 'lltype'
More information about the Pypy-commit
mailing list