Commit Graph

7953 Commits

Author SHA1 Message Date
Sebastian Berg 7a3b03509e
gh-104263: Rely on Py_NAN and introduce Py_INFINITY (GH-104202)
This PR removes `_Py_dg_stdnan` and `_Py_dg_infinity` in favour of
using the standard `NAN` and `INFINITY` macros provided by C99.
This change has the side-effect of fixing a bug on MIPS where the
hard-coded value used by `_Py_dg_stdnan` gave a signalling NaN
rather than a quiet NaN.
---------

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-05-10 17:44:52 +01:00
Carl Meyer c3b595e73e
gh-97933: (PEP 709) inline list/dict/set comprehensions (#101441)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-09 11:02:14 -06:00
Carl Meyer afe7703744
gh-104184: fix building --with-pydebug --enable-pystats (#104217) 2023-05-09 08:53:19 -06:00
Irit Katriel ca95edf177
gh-104240: return code unit metadata from codegen (#104300) 2023-05-09 14:33:40 +01:00
Eric Snow 5c9ee498c6
gh-99113: A Per-Interpreter GIL! (gh-104210)
This is the culmination of PEP 684 (and of my 8-year long multi-core Python project)!

Each subinterpreter may now be created with its own GIL (via Py_NewInterpreterFromConfig()).  If not so configured then the interpreter will share with the main interpreter--the status quo since subinterpreters were added decades ago.  The main interpreter always has its own GIL and subinterpreters from Py_NewInterpreter() will always share with the main interpreter.
2023-05-08 13:15:09 -06:00
Arthur Pastel 8d95012c95
gh-103650: Fix perf maps address format (#103651) 2023-05-07 20:42:26 +01:00
Irit Katriel 2c2dc61e8d
gh-104240: make _PyCompile_CodeGen support different compilation modes (#104241) 2023-05-07 18:47:28 +01:00
John Belmonte 69621d1b09
gh-104018: remove unused format "z" handling in string formatfloat() (#104107)
This is a cleanup overlooked in PR #104033.
2023-05-07 10:11:42 +05:30
Tomas R b35711d17a
gh-103886: Improve `builtins.__doc__` (#104179)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-06 19:05:34 -07:00
Eric Snow 92d8bfffbf
gh-99113: Make Sure the GIL is Acquired at the Right Places (gh-104208)
This is a pre-requisite for a per-interpreter GIL.  Without it this change isn't strictly necessary.  However, there is no real downside otherwise.
2023-05-06 15:59:30 -06:00
Nikita Sobolev 6616710731
gh-104233: Fix "unused variable" warning in `ceval_gil.c` (#104234) 2023-05-06 20:28:32 +05:30
Eric Snow f3e7eb48f8
gh-99113: Add PyInterpreterConfig.own_gil (gh-104204)
We also add PyInterpreterState.ceval.own_gil to record if the interpreter actually has its own GIL.

Note that for now we don't actually respect own_gil; all interpreters still share the one GIL.  However, PyInterpreterState.ceval.own_gil does reflect PyInterpreterConfig.own_gil.  That lie is a temporary one that we will fix when the GIL really becomes per-interpreter.
2023-05-05 15:59:20 -06:00
Eric Snow a9c6e0618f
gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)
Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules.  We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
2023-05-05 21:11:27 +00:00
Eric Snow 55671fe047
gh-99113: Share the GIL via PyInterpreterState.ceval.gil (gh-104203)
In preparation for a per-interpreter GIL, we add PyInterpreterState.ceval.gil, set it to the shared GIL for each interpreter, and use that rather than using _PyRuntime.ceval.gil directly.  Note that _PyRuntime.ceval.gil is still the actual GIL.
2023-05-05 13:23:00 -06:00
Mark Shannon a0df9ee8fc
GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque for users of PEP 523. (GH-96849) 2023-05-05 17:53:07 +01:00
Victor Stinner 45398ad512
gh-103323: Remove PyRuntimeState_GetThreadState() (#104171)
This function no longer makes sense, since its runtime parameter is
no longer used. Use directly _PyThreadState_GET() and
_PyInterpreterState_GET() instead.
2023-05-04 16:21:01 +02:00
Petr Viktorin cd9a56c2b0
gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-04 09:56:53 +02:00
Tian Gao bcea36f8db
gh-103845: Remove line & instruction instrumentations before adding them back (GH-103851) 2023-05-03 10:51:47 +01:00
Paul Ganssle 65c4a2b326 GH-84976: Move Lib/datetime.py to Lib/_pydatetime
This breaks the tests, but we are keeping it as a separate commit so
that the move operation and editing of the moved files are separate, for
a cleaner history.
2023-05-03 03:09:45 -06:00
Eric Snow 292076a9aa
gh-104109: Expose Py_NewInterpreterFromConfig() in the Public C-API (gh-104110)
We also expose PyInterpreterConfig. This is part of the PEP 684 (per-interpreter GIL) implementation.  We will add docs as soon as we can.

FYI, I'm adding the new config field for per-interpreter GIL in gh-99114.
2023-05-02 21:40:00 -06:00
Eric Snow f73abf8e03
gh-94673: Hide Objects in PyTypeObject Behind Accessors (gh-104074)
This makes it much cleaner to move more PyTypeObject fields to PyInterpreterState.
2023-05-01 20:34:43 -06:00
Eric Snow fdd878650d
gh-94673: Properly Initialize and Finalize Static Builtin Types for Each Interpreter (gh-104072)
Until now, we haven't been initializing nor finalizing the per-interpreter state properly.
2023-05-01 19:36:00 -06:00
Irit Katriel 80b714835d
gh-87092: Expose assembler to unit tests (#103988) 2023-05-01 22:29:30 +01:00
Eric Snow 59bc36aacd
gh-84436: Immortalize in _PyStructSequence_InitBuiltinWithFlags() (gh-104054)
This also does some cleanup.
2023-05-01 15:08:34 -06:00
Carey Metcalfe 487f55d580
gh-103895: Improve how invalid `Exception.__notes__` are displayed (#103897) 2023-05-01 08:32:04 +01:00
Ken Jin ed95e8cbd4
gh-98003: Inline call frames for CALL_FUNCTION_EX (GH-98004) 2023-04-30 21:08:26 +08:00
Irit Katriel fbf3596c3e
gh-87092: change assembler to use instruction sequence instead of CFG (#103933) 2023-04-29 12:06:04 +01:00
Mark Shannon 738c226786
GH-103082: Code cleanup in instrumentation code (#103474) 2023-04-29 04:51:55 +00:00
Barry Warsaw e1f14643dc
gh-98040: Remove just the `imp` module (#98573) 2023-04-28 16:17:58 -07:00
Carl Meyer ebf97c50f2
gh-103978: avoid using 'class' as an identifier (#103979) 2023-04-28 19:20:50 +00:00
Eric Snow d2e2e53f73
gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)
There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
2023-04-27 16:19:43 -06:00
Jelle Zijlstra 6c4124d11a
gh-103879: Fix refleak in super specialization (#103882) 2023-04-26 08:50:19 -07:00
Carl Meyer ef25febcf2
gh-87729: specialize LOAD_SUPER_ATTR_METHOD (#103809) 2023-04-25 17:45:51 +00:00
Eric Snow d8627999d8
gh-100227: Add a Granular Lock for _PyRuntime.imports.extensions.dict (gh-103460)
The lock is unnecessary as long as there's a GIL, but completely
necessary with a per-interpreter GIL.
2023-04-24 21:09:35 -06:00
Eric Snow df3173d28e
gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660)
This is strictly about moving the "obmalloc" runtime state from
`_PyRuntimeState` to `PyInterpreterState`.  Doing so improves isolation
between interpreters, specifically most of the memory (incl. objects)
allocated for each interpreter's use.  This is important for a
per-interpreter GIL, but such isolation is valuable even without it.

FWIW, a per-interpreter obmalloc is the proverbial
canary-in-the-coalmine when it comes to the isolation of objects between
interpreters.  Any object that leaks (unintentionally) to another
interpreter is highly likely to cause a crash (on debug builds at
least).  That's a useful thing to know, relative to interpreter
isolation.
2023-04-24 17:23:57 -06:00
Carl Meyer 0dc8b50d33
gh-87729: add LOAD_SUPER_ATTR instruction for faster super() (#103497)
This speeds up `super()` (by around 85%, for a simple one-level
`super().meth()` microbenchmark) by avoiding allocation of a new
single-use `super()` object on each use.
2023-04-24 22:22:14 +00:00
Eric Snow 19e4f757de
gh-100227: Only Use deepfreeze for the Main Interpreter (gh-103794)
Deep-frozen code objects are cannot be shared (currently) by
interpreters, due to how adaptive specialization can modify the
bytecodes. We work around this by only using the deep-frozen objects in
the main interpreter. This does incur a performance penalty for
subinterpreters, which we may be able to resolve later.
2023-04-24 21:48:05 +00:00
Shantanu ae25855045
gh-103492: Clarify SyntaxWarning with literal comparison (#103493) 2023-04-24 15:42:57 -06:00
Irit Katriel 1c01f8d797
gh-101517: fix line number propagation in code generated for except* (#103550) 2023-04-24 21:58:51 +01:00
Irit Katriel 6751a4af95
gh-87092: fix a few cases of incorrect error handling in compiler (#103456)
gh-87092: fix a few cases of incorrect error handling
2023-04-24 19:30:49 +01:00
Eric Snow f8abfa3314
gh-103323: Get the "Current" Thread State from a Thread-Local Variable (gh-103324)
We replace _PyRuntime.tstate_current with a thread-local variable. As part of this change, we add a _Py_thread_local macro in pyport.h (only for the core runtime) to smooth out the compiler differences. The main motivation here is in support of a per-interpreter GIL, but this change also provides some performance improvement opportunities.

Note that we do not provide a fallback to the thread-local, either falling back to the old tstate_current or to thread-specific storage (PyThread_tss_*()). If that proves problematic then we can circle back. I consider it unlikely, but will run the buildbots to double-check.

Also note that this does not change any of the code related to the GILState API, where it uses a thread state stored in thread-specific storage. I suspect we can combine that with _Py_tss_tstate (from here). However, that can be addressed separately and is not urgent (nor critical).

(While this change was mostly done independently, I did take some inspiration from earlier (~2020) work by @markshannon (main...markshannon:threadstate_in_tls) and @vstinner (#23976).)
2023-04-24 11:17:02 -06:00
Eddie Elizondo ea2c001650
gh-84436: Implement Immortal Objects (gh-19474)
This is the implementation of PEP683

Motivation:

The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime.

Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
2023-04-22 13:39:37 -06:00
Oleg Iarygin a4967d9d59
gh-103082: Fix shifted field initialization in `instrumentation.c` (GH-103561)
Fix shifted field initialization in instrumentation.c
2023-04-21 07:27:50 -06:00
Pablo Galindo Salgado 1ef61cf71a
gh-102856: Initial implementation of PEP 701 (#102855)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2023-04-19 11:18:16 -05:00
Nikita Sobolev 07804ce24c
GH-100530: Change the error message for non-class class patterns (GH-103576) 2023-04-18 10:41:14 -07:00
Benjamin Peterson 7b95d23591
Fix unused functions warnings in instrumentation.c (GH-103515) 2023-04-13 18:45:03 +01:00
Mark Shannon efb8a2553c
GH-103488: Use return-offset, not yield-offset. (GH-103502)
* Use return-offset, not yield-offset, so that instruction pointer is correct when sending to a generator or coroutine.
2023-04-13 16:19:07 +01:00
Mark Shannon 70e0a28bed
GH-103082: Turn on branch events for FOR_ITER instructions. (#103507)
Turn on branch events for FOR_ITER instructions.
2023-04-13 13:56:09 +01:00
Nikita Sobolev 7f3c106503
gh-103326: Remove `Python/importlib.h` (GH-103331)
Co-authored-by: Brett Cannon <brett@python.org>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-04-12 11:27:14 -07:00
Mark Shannon 411b169281
GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython (GH-103083)
* The majority of the monitoring code is in instrumentation.c

* The new instrumentation bytecodes are in bytecodes.c

* legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs
2023-04-12 12:04:55 +01:00