[pypy-svn] r52059 - in pypy/branch/jit-refactoring/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Mar 2 18:28:35 CET 2008
Author: arigo
Date: Sun Mar 2 18:28:35 2008
New Revision: 52059
Modified:
pypy/branch/jit-refactoring/pypy/annotation/binaryop.py
pypy/branch/jit-refactoring/pypy/annotation/test/test_annrpython.py
Log:
Experimental, to help in translating the rainbow interpreter:
reading from empty lists is not fatal
Modified: pypy/branch/jit-refactoring/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/annotation/binaryop.py (original)
+++ pypy/branch/jit-refactoring/pypy/annotation/binaryop.py Sun Mar 2 18:28:35 2008
@@ -16,7 +16,7 @@
from pypy.annotation.model import SomeSingleFloat
from pypy.annotation.model import unionof, UnionError, set, missing_operation
from pypy.annotation.model import isdegenerated, TLS
-from pypy.annotation.model import read_can_only_throw
+from pypy.annotation.model import read_can_only_throw, HarmlesslyBlocked
from pypy.annotation.model import add_knowntypedata, merge_knowntypedata
from pypy.annotation.model import lltype_to_annotation
from pypy.annotation.model import SomeGenericCallable
@@ -603,7 +603,10 @@
def getitem((lst1, int2)):
getbookkeeper().count("list_getitem", int2)
- return lst1.listdef.read_item()
+ s_item = lst1.listdef.read_item()
+ if isinstance(s_item, SomeImpossibleValue):
+ raise HarmlesslyBlocked("getitem on an empty list")
+ return s_item
getitem.can_only_throw = []
getitem_key = getitem
Modified: pypy/branch/jit-refactoring/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/branch/jit-refactoring/pypy/annotation/test/test_annrpython.py Sun Mar 2 18:28:35 2008
@@ -3040,6 +3040,25 @@
a.build_types(f, [str])
+ def test_empty_list_blocks_harmlessly(self):
+ class X:
+ pass
+ x = X()
+ x.foobar = []
+ def f(n):
+ if n < 0:
+ # this example shows up in cases where the next line is
+ # really unreachable, but in ways that the annotator cannot
+ # figure out
+ return x.foobar[~n]
+ else:
+ return 42
+
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [int])
+ assert s.const == 42
+
+
def g(n):
return [0,1,2,n]
More information about the pypy-svn
mailing list