tonybaloney/Pyjion

Unexcepted results when enabling jit

Mskxn opened this issue · 2 comments

version:
pyjion 2.0.0 (compile with latest source code)
ubuntu 20.04
python 3.10.12

This code behavior is different when enabling jit, x.fn = lambda x, y: x + y seems be ignored:

class A:
    def __init__(self):
        pass

    def fn(self, x, y):
        return x * y

def f(x, y):
    return x.fn(y, y)

for i in range(10000):
    x = A()
    r = f(x, i)

x.fn = lambda x, y: x + y
r = f(x, 1)
print(r)
# excepted 2 but 1

version:
pyjion 2.0.0 (compile with latest source code)
ubuntu 20.04
python 3.10.12

This code triggers a crash instead of something like a cold exit.

import pyjion; pyjion.enable()

def compare(a, b):
    return a + b - b

for i in range(100000):
    r = compare(1.1, 1.1)

r = compare(1, 1.1)
print(r)

"""
Traceback (most recent call last):
  File "/root/work/src/temp.py", line 9, in <module>
    r = compare(1, 1.1)
  File "/root/work/src/temp.py", line 4, in compare
    return a + b - b
pyjion.PyjionUnboxingError: Optimizations are invalid. Pyjion PGC expected float, but 1 is a int. Try disabling PGC pyjion.config(pgc=False) or lowering the optimization level to avoid hitting this error.
"""

The following code returns 0 instead of UnboundLocalError:

import pyjion; pyjion.enable()

def f():
    it = range(0)
    for i in it:
        pass
    return i

r = f()
print(r)