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

Caching for cython.inline() does not differentiate between different compiler configurations. #3419

Closed
will-ca opened this issue Mar 12, 2020 · 2 comments · Fixed by #3440
Closed

Comments

@will-ca
Copy link
Contributor

will-ca commented Mar 12, 2020

>>> cython.inline('def f(int a, int b):\n\treturn a/b\nreturn f', language_level=3)(5,2)
2.5
>>> cython.inline('def f(int a, int b):\n\treturn a/b\nreturn f', language_level=2)(5,2)
2
>>> cython.inline('def f(int a, int b):\n\treturn a/b\nreturn f', language_level=3)(5,2)
2
@scoder
Copy link
Contributor

scoder commented Mar 12, 2020

Interesting. I had added the language_level to the module hash, but it seems to have no effect.

key = orig_code, arg_sigs, sys.version_info, sys.executable, language_level, Cython.__version__
module_name = "_cython_inline_" + hashlib.sha1(_unicode(key).encode('utf-8')).hexdigest()

@will-ca
Copy link
Contributor Author

will-ca commented Mar 16, 2020

I think that hash is being skipped entirely by the fast path at the very start of the function, which only takes into account the code string and (unbound?) argument signature:

# Fast path if this has been called in this session.
_unbound_symbols = _cython_inline_cache.get(code)
if _unbound_symbols is not None:
_populate_unbound(kwds, _unbound_symbols, locals, globals)
args = sorted(kwds.items())
arg_sigs = tuple([(get_type(value, ctx), arg) for arg, value in args])
invoke = _cython_inline_cache.get((code, arg_sigs))
if invoke is not None:
arg_list = [arg[1] for arg in args]
return invoke(*arg_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants