exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
14.53k stars 504 forks source link

Bug Report: libc++abi error when using python decorator #138

Open bw-xu opened 1 year ago

bw-xu commented 1 year ago

Environment

MacOS 13.1, Python 3.8.3/3.11.0, codon 0.15, codon-jit

Description

After I installed codon via /bin/bash -c "$(curl -fsSL https://exaloop.io/install.sh)", I can run .py file correctly via codon run -release fib.py. However, when I tried the python decorator, it says

libc++abi: terminating with uncaught exception of type codon::exc::ParserException: cannot locate standard library

The code I ran is

import codon
from time import time

def is_prime_python(n):
    if n <= 1:
        return False
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

@codon.jit
def is_prime_codon(n):
    if n <= 1:
        return False
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

t0 = time()
ans = sum(1 for i in range(100000, 200000) if is_prime_python(i))
t1 = time()
print(f'[python] {ans} | took {t1 - t0} seconds')

t0 = time()
ans = sum(1 for i in range(100000, 200000) if is_prime_codon(i))
t1 = time()
print(f'[codon]  {ans} | took {t1 - t0} seconds')
arshajii commented 1 year ago

Will be fixed in next release, but for now you can set the CODON_PATH environment variable to the standard library path (~/.codon/lib/codon/stdlib by default). For example, for me it would be:

export CODON_PATH=/Users/arshajii/.codon/lib/codon/stdlib
bw-xu commented 1 year ago

Thanks for replying! I tried that, and it seemed to work. However, another error occurs in line 13 (def is_prime_codon(n):)

Exception has occurred: UnicodeEncodeError 'ascii' codec can't encode characters in position 26-27: ordinal not in range(128)

bw-xu commented 1 year ago

Thanks for replying! I tried that, and it seemed to work. However, another error occurs in line 13 (def is_prime_codon(n):)

Exception has occurred: UnicodeEncodeError 'ascii' codec can't encode characters in position 26-27: ordinal not in range(128)

This is the full traceback info:

Traceback (most recent call last): File "/Users/bowenxu/Codes/Codon学习/foo1.py", line 12, in @codon.jit ^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/Crypto/lib/python3.11/site-packages/codon/decorator.py", line 217, in jit return _decorate(fn) ^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/Crypto/lib/python3.11/site-packages/codon/decorator.py", line 187, in _decorate _jit.execute( File "codon/jit.pyx", line 27, in codon.codon_jit.JITWrapper.execute File "stringsource", line 15, in string.from_py.__pyx_convert_string_from_py_std__in_string UnicodeEncodeError: 'ascii' codec can't encode characters in position 26-27: ordinal not in range(128)

bw-xu commented 1 year ago

OH, I know the reason. This is because my path to the source file contains Unicode characters. If there aren't such characters, the solution above works.

inumanag commented 1 year ago

@bw-xu Thanks for the report. Will see if we can handle this.

bw-xu commented 1 year ago

@bw-xu Thanks for the report. Will see if we can handle this.

Let's see.

Also, I wonder if there is any guide for developer who would like to contribute to this project.

I feel like codon is a fancy project, and I hope to fix bugs and improve it if I could.