Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonsensical TypeError from "-X jit -m compile --static" #86

Open
belm0 opened this issue Jul 4, 2022 · 3 comments
Open

nonsensical TypeError from "-X jit -m compile --static" #86

belm0 opened this issue Jul 4, 2022 · 3 comments
Labels
sp-correctness static python correctness staticpython static python issues

Comments

@belm0
Copy link
Contributor

belm0 commented Jul 4, 2022

good (no options):

$ docker run -v $PWD:/vol -it --rm ghcr.io/facebookincubator/cinder-runtime:cinder-3.8 vol/cinder_typed_prim_bug.py
done 0.57

bad (-X jit -m compile --static):

$ docker run -v $PWD:/vol -it --rm ghcr.io/facebookincubator/cinder-runtime:cinder-3.8 -X jit -m compiler --static vol/cinder_typed_prim_bug.py
Traceback (most recent call last):
  File "/cinder/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/cinder/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/cinder/lib/python3.8/compiler/__main__.py", line 122, in <module>
    exec(codeobj, d, d)
  File "vol/cinder_typed_prim_bug.py", line 15, in __main__
    main()
  File "vol/cinder_typed_prim_bug.py", line 10, in main
    c += foo(.4, .97)
TypeError: unsupported operand type(s) for +=: 'float' and 'function'

The compiler is acting as if the written code were c += foo rather than c += foo(.4, .97).

The problem goes away by removing -X jit, --static, or use of the double primitives.

cinder_typed_prim_bug.py

from __static__ import double

def foo(a: double, b: double) -> double:
    return b - a

def main():
    c = 0.
    c += foo(.4, .97)
    print('done', c)

if __name__ == '__main__':
    main()

seen in cinder-3.8.6c2de94

@belm0
Copy link
Contributor Author

belm0 commented Jul 4, 2022

Here is a fix to main() to make it work (adding primitive type on var c):

def main():
    c: double = 0.
    c += foo(.4, .97)
    print('done', box(c))

Even if that's required, the error output is wrong.

@belm0
Copy link
Contributor Author

belm0 commented Jul 4, 2022

In a more complete program than this simple repro, I've seen it manifest more severely, namely a SIGSEGV. Fixing the primitive typing on c fixed that program as well. (I'm not sure how to have docker run show the trace, otherwise I'd share it.)

@carljm
Copy link
Contributor

carljm commented Jul 12, 2022

The explicit c: double should be required, we don't auto box or unbox within static code (only at function call boundaries between static and non-static code). But clearly there's a bug in the compiler on the way to delivering that error. Thanks for the report!

@carljm carljm added staticpython static python issues sp-correctness static python correctness labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sp-correctness static python correctness staticpython static python issues
Projects
None yet
Development

No branches or pull requests

2 participants