cinder
cinder copied to clipboard
nonsensical TypeError from "-X jit -m compile --static"
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
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.
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.)
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!