Note that, as far as I know (the rpython/pypy team will confirm or infirm) RPython is not intended to be a general-purpose python-like language. For that you want cython or nim. RPython is a toolkit for building language VMs. I'm guessing that's why relatively little work has gone into error reporting.
Yep. RPython is not a language as designed, it's an arbitrary set of restrictions to the Python bytecode and standard library. These restrictions change as developers implement new features and as time goes on. For instance, one restriction I had when I was working with PyPy was "str.strip can only take one character", but this has been removed in subsequence PyPy versions.
I hadn't heard the word infirm before so I looked it up. It seems to me that it does not mean what you think it means. Thought you might want to know that. http://www.merriam-webster.com/dictionary/infirm
I always had the impression that the more "RPython-like" your Python code is, the better PyPy can optimize it. If that is true, then I see a lot of value in this post. However I'm unsure how much truth is in my belief.
I'd agree. The thing is: for stock Python, you want to minimize interpreter load. Use a lot of list comprehensions, that sort of thing. Whereas with PyPy you want to do the opposite.
For instance, I have the following two functions:
def atLeast2(a,b,num):
return sum(x==y for x,y in itertools.zip_longest(reversed(bin(a).partition('b')[-1]), reversed(bin(b).partition('b')[-1]), fillvalue='0')) >= num
def atLeast4(a,b,num):
count = 0
while a > 0 or b > 0:
x = a % 2
y = b % 2
if x == y:
count += 1
if count >= num:
return True
a //= 2
b //= 2
return count >= num
In Python, atLeast2 is ~2.7x faster than atLeast4. In Pypy, atLeast2 is 1.9x slower than atLeast4.
(The ordering is roughly, using relative numbers (lower = faster), and checking for at least 96 bits in common out of 128 for random inputs:
def atLeast(a, b, num):
count = 0
for x, y in zip(bin(a).partition('b')[-1], bin(b).partition('b')[-1]):
if x == y:
count += 1
if count >= num:
return True
return False
def atLeast3(a,b,num):
count = 0
while a > 0 or b > 0:
x = a % 2
y = b % 2
if x == y:
count += 1
a //= 2
b //= 2
return count >= num
)