[XLA:Python] Fix incorrect code source information under Python 3.11.

Do not multiply the result of PyFrame_GetLasti() by sizeof(_Py_CODEUNIT), because the CPython implementation already does this inside PyFrame_GetLasti().

* In CPython versions 3.9 or earlier, the f_lasti value in a PyFrameObject was in bytes.
* In CPython 3.10, f_lasti was changed to be in code units, which required multiplying it by sizeof(_Py_CODEUNIT) before passing it to functions like PyCode_Addr2Line(). https://docs.python.org/3/whatsnew/3.10.html#changes-in-the-c-api
* In CPython 3.11, direct access to the representation of the PyFrameObject was removed from the headers, requiring the use of PyFrame_GetLasti() (https://docs.python.org/3/whatsnew/3.11.html#pyframeobject-3-11-hiding). This function multiplies by sizeof(_Py_CODEUNIT) internally (deaf509e8f/Objects/frameobject.c (L1353)) so there is no need for the caller to do this multiplication.

It is difficult to write a good test for this, since the only symptom is slightly inaccurate code line information. This issue was found under a debug mode build of CPython (https://docs.python.org/3/using/configure.html#python-debug-build), where PyCode_Addr2Line() has additional checks for out of range lasti values.

PiperOrigin-RevId: 538847288
This commit is contained in:
Peter Hawkins 2023-06-08 11:41:47 -07:00 committed by jax authors
parent e598bc8e7e
commit a47aca8205

View File

@ -26,10 +26,14 @@ Remember to align the itemized text with the first line of an item within a list
## jaxlib 0.4.12
* Changes
* Include PTX/SASS for Hopper (SM version 9.0+) GPUs. Previous
* Includes PTX/SASS for Hopper (SM version 9.0+) GPUs. Previous
versions of jaxlib should work on Hopper but would have a long
JIT-compilation delay the first time a JAX operation was executed.
* Bug fixes
* Fixes incorrect source line information in JAX-generated Python tracebacks
under Python 3.11.
## jax 0.4.11 (May 31, 2023)
* Deprecations