summaryrefslogtreecommitdiffstats
path: root/Python
Commit message (Collapse)AuthorAgeFilesLines
* gh-116968: Reimplement Tier 2 counters (#117144)Guido van Rossum2024-04-048-171/+117
| | | | | | | | | | | | Introduce a unified 16-bit backoff counter type (``_Py_BackoffCounter``), shared between the Tier 1 adaptive specializer and the Tier 2 optimizer. The API used for adaptive specialization counters is changed but the behavior is (supposed to be) identical. The behavior of the Tier 2 counters is changed: - There are no longer dynamic thresholds (we never varied these). - All counters now use the same exponential backoff. - The counter for ``JUMP_BACKWARD`` starts counting down from 16. - The ``temperature`` in side exits starts counting down from 64.
* gh-116168: Remove extra `_CHECK_STACK_SPACE` uops (#117242)Peter Lazorchak2024-04-034-17/+104
| | | This merges all `_CHECK_STACK_SPACE` uops in a trace into a single `_CHECK_STACK_SPACE_OPERAND` uop that checks whether there is enough stack space for all calls included in the entire trace.
* gh-76785: Raise InterpreterError, Not RuntimeError (gh-117489)Eric Snow2024-04-033-6/+22
| | | | | I had meant to switch everything to InterpreterError when I added it a while back. At the time I missed a few key spots. As part of this, I've added print-the-exception to _PyXI_InitTypes() and fixed an error case in `_PyStaticType_InitBuiltin().
* gh-76785: Fix a Refleak in _interpreters.new_config() (gh-117491)Eric Snow2024-04-031-0/+2
| | | This is a follow-up to gh-117170 and gh-117485.
* gh-76785: Add PyInterpreterConfig Helpers (gh-117170)Eric Snow2024-04-023-22/+305
| | | These helpers make it easier to customize and inspect the config used to initialize interpreters. This is especially valuable in our tests. I found inspiration from the PyConfig API for the PyInterpreterConfig dict conversion stuff. As part of this PR I've also added a bunch of tests.
* Fix successor opcode name printing in Tier 2 DEOPT debug message (#117471)Guido van Rossum2024-04-021-1/+1
|
* GH-115776: Embed the values array into the object, for "normal" Python ↵Mark Shannon2024-04-027-110/+106
| | | | objects. (GH-116115)
* gh-117411: move PyFutureFeatures to pycore_symtable.h and make it private ↵Irit Katriel2024-04-026-15/+16
| | | | (#117412)
* Silence compiler warnings in gc.c (#117422)Guido van Rossum2024-04-011-0/+3
|
* gh-91565: Replace bugs.python.org links with Devguide/GitHub ones (GH-91568)Steve (Gadget) Barnes2024-04-011-1/+1
| | | | | | Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
* gh-117303: Don't detach in `PyThreadState_DeleteCurrent()` (#117304)Sam Gross2024-03-291-2/+0
| | | | | | | | | | | This fixes a crash in `test_threading.test_reinit_tls_after_fork()` when running with the GIL disabled. We already properly handle the case where the thread state is `_Py_THREAD_ATTACHED` in `tstate_delete_common()` -- we just need to remove an assertion. Keeping the thread attached means that a stop-the-world pause, such as for a `fork()`, won't commence until we remove our thread state from the interpreter's linked list. This prevents a crash when the child process tries to clean up the dead thread states.
* gh-116664: In _warnings.c, make filters_version access thread-safe (#117374)Erlend E. Aasland2024-03-291-6/+9
| | | | - assert that the lock is held in already_warned() - protect 'filters_version' increment in warnings_filters_mutated_impl()
* gh-117300: Use stop the world to make `sys._current_frames` and ↵Sam Gross2024-03-291-0/+4
| | | | | | | | | | `sys._current_exceptions` thread-safe. (#117301) This adds a stop the world pause to make the two functions thread-safe when the GIL is disabled in the free-threaded build. Additionally, the main test thread may call `sys._current_exceptions()` as soon as `g_raised.set()` is called. The background thread may not yet reach the `leave_g.wait()` line.
* gh-117323: Make `cell` thread-safe in free-threaded builds (#117330)Sam Gross2024-03-294-36/+23
| | | Use critical sections to lock around accesses to cell contents. The critical sections are no-ops in the default (with GIL) build.
* gh-112529: Don't untrack tuples or dicts with zero refcount (#117370)Sam Gross2024-03-291-15/+18
| | | | | | | | The free-threaded GC sometimes sees objects with zero refcount. This can happen due to the delay in merging biased reference counting fields, and, in the future, due to deferred reference counting. We should not untrack these objects or they will never be collected. This fixes the refleaks in the free-threaded build.
* gh-116664: Fix unused var warnings in _warnings.c in non-free-threaded ↵Erlend E. Aasland2024-03-291-0/+8
| | | | | builds (#117373) The warnings were introduced by commit c1712ef06.
* GH-117121: Add pystats to JIT builds (GH-117346)Michael Droettboom2024-03-282-1/+3
|
* gh-116664: Make module state Py_SETREF's in _warnings thread-safe (#116959)Erlend E. Aasland2024-03-281-21/+37
| | | | | | Mark the swap operations as critical sections. Add an internal Py_BEGIN_CRITICAL_SECTION_MUT API that takes a PyMutex pointer instead of a PyObject pointer.
* gh-110481: Fix biased reference counting queue initialization. (#117271)Sam Gross2024-03-282-6/+18
| | | | | The biased reference counting queue must be initialized from the bound (active) thread because it uses `_Py_ThreadId()` as the key in a hash table.
* gh-117266: Fix crashes on user-created AST subclasses (GH-117276)Jelle Zijlstra2024-03-281-2/+13
| | | Fix crashes on user-created AST subclasses
* gh-114099: Additions to standard library to support iOS (GH-117052)Russell Keith-Magee2024-03-282-3/+11
| | | | | Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Malcolm Smith <smith@chaquo.com> Co-authored-by: Ned Deily <nad@python.org>
* gh-117288: Allocate fewer label IDs in _PyCfg_ToInstructionSequence (#117290)Irit Katriel2024-03-273-6/+36
|
* gh-115775: Compiler adds __static_attributes__ field to classes (#115913)Irit Katriel2024-03-261-1/+53
|
* GH-117108: Set the "old space bit" to "visited" for all young objects (#117213)Mark Shannon2024-03-261-17/+37
| | | | Change old space bit of young objects from 0 to gcstate->visited_space. This ensures that any object created *and* collected during cycle GC has the bit set correctly.
* GH-116422: Tier2 hot/cold splitting (GH-116813)Mark Shannon2024-03-269-751/+834
| | | | | Splits the "cold" path, deopts and exits, from the "hot" path, reducing the size of most jitted instructions, at the cost of slower exits.
* A few minor tweaks to get stats working and compiling cleanly. (#117219)Mark Shannon2024-03-252-6/+3
| | | | Fixes a compilation error when configured with `--enable-pystats`, an array size issue, and an unused variable.
* gh-117176: Fix compiler warning in Python/optimizer_bytecodes.c (GH-117199)Kirill Podoprigora2024-03-242-2/+2
|
* gh-117180: Complete call sequence when trace stack overflow (GH-117184)Ken Jin2024-03-231-0/+1
| | | | | | | --------- Co-authored-by: Peter Lazorchak <lazorchakp@gmail.com> Co-authored-by: Guido van Rossum <gvanrossum@users.noreply.github.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
* GH-117108: Change the size of the GC increment to about 1% of the total heap ↵Mark Shannon2024-03-222-16/+16
| | | | size. (GH-117120)
* gh-113024: C API: Add PyObject_GenericHash() function (GH-113025)Serhiy Storchaka2024-03-221-1/+7
|
* gh-105716: Fix _PyInterpreterState_IsRunningMain() For Embedders (gh-117140)Eric Snow2024-03-222-20/+19
| | | | | When I added _PyInterpreterState_IsRunningMain() and friends last year, I tried to accommodate applications that embed Python but don't call _PyInterpreterState_SetRunningMain() (not that they're expected to). That mostly worked fine until my recent changes in gh-117049, where the subtleties with the fallback code led to failures; the change ended up breaking test_tools.test_freeze, which exercises a basic embedding situation. The simplest fix is to drop the fallback code I originally added to _PyInterpreterState_IsRunningMain() (and later to _PyThreadState_IsRunningMain()). I've kept the fallback in the _xxsubinterpreters module though. I've also updated Py_FrozenMain() to call _PyInterpreterState_SetRunningMain().
* gh-117045: Add code object to function version cache (#117028)Guido van Rossum2024-03-214-38/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | Changes to the function version cache: - In addition to the function object, also store the code object, and allow the latter to be retrieved even if the function has been evicted. - Stop assigning new function versions after a critical attribute (e.g. `__code__`) has been modified; the version is permanently reset to zero in this case. - Changes to `__annotations__` are no longer considered critical. (This fixes gh-109998.) Changes to the Tier 2 optimization machinery: - If we cannot map a function version to a function, but it is still mapped to a code object, we continue projecting the trace. The operand of the `_PUSH_FRAME` and `_POP_FRAME` opcodes can be either NULL, a function object, or a code object with the lowest bit set. This allows us to trace through code that calls an ephemeral function, i.e., a function that may not be alive when we are constructing the executor, e.g. a generator expression or certain nested functions. We will lose globals removal inside such functions, but we can still do other peephole operations (and even possibly [call inlining](https://github.com/python/cpython/pull/116290), if we decide to do it), which only need the code object. As before, if we cannot retrieve the code object from the cache, we stop projecting.
* gh-116522: Refactor `_PyThreadState_DeleteExcept` (#117131)Sam Gross2024-03-213-22/+31
| | | | | | | | | | | Split `_PyThreadState_DeleteExcept` into two functions: - `_PyThreadState_RemoveExcept` removes all thread states other than one passed as an argument. It returns the removed thread states as a linked list. - `_PyThreadState_DeleteList` deletes those dead thread states. It may call destructors, so we want to "start the world" before calling `_PyThreadState_DeleteList` to avoid potential deadlocks.
* gh-116996: Add pystats about _Py_uop_analyse_and_optimize (GH-116997)Michael Droettboom2024-03-212-2/+22
|
* gh-76785: Drop PyInterpreterID_Type (gh-117101)Eric Snow2024-03-211-5/+0
| | | I added it quite a while ago as a strategy for managing interpreter lifetimes relative to the PEP 554 (now 734) implementation. Relatively recently I refactored that implementation to no longer rely on InterpreterID objects. Thus now I'm removing it.
* gh-115754: Add Py_GetConstant() function (#116883)Victor Stinner2024-03-211-0/+4
| | | | | | | | | | | | Add Py_GetConstant() and Py_GetConstantBorrowed() functions. In the limited C API version 3.13, getting Py_None, Py_False, Py_True, Py_Ellipsis and Py_NotImplemented singletons is now implemented as function calls at the stable ABI level to hide implementation details. Getting these constants still return borrowed references. Add _testlimitedcapi/object.c and test_capi/test_object.py to test Py_GetConstant() and Py_GetConstantBorrowed() functions.
* gh-105716: Update interp->threads.main After Fork (gh-117049)Eric Snow2024-03-212-0/+39
| | | | | I missed this in gh-109921. We also update Py_Exit() to call _PyInterpreterState_SetNotRunningMain(), if necessary.
* gh-76785: Clean Up Interpreter ID Conversions (gh-117048)Eric Snow2024-03-211-24/+79
| | | Mostly we unify the two different implementations of the conversion code (from PyObject * to int64_t. We also drop the PyArg_ParseTuple()-style converter function, as well as rename and move PyInterpreterID_LookUp().
* gh-116522: Stop the world before fork() and during shutdown (#116607)Sam Gross2024-03-212-0/+9
| | | | | | | | | | | This changes the free-threaded build to perform a stop-the-world pause before deleting other thread states when forking and during shutdown. This fixes some crashes when using multiprocessing and during shutdown when running with `PYTHON_GIL=0`. This also changes `PyOS_BeforeFork` to acquire the runtime lock (i.e., `HEAD_LOCK(&_PyRuntime)`) before forking to ensure that data protected by the runtime lock (and not just the GIL or stop-the-world) is in a consistent state before forking.
* GH-117066: Tier 2 optimizer: Don't throw away good traces if we can't ↵Mark Shannon2024-03-203-8/+16
| | | | optimize them perfectly. (GH-117067)
* gh-116908: Only write to `_pending_calls.calls_to_do` with atomic operations ↵Brett Simmers2024-03-201-2/+2
| | | | | | (#117044) These writes to `pending->calls_to_do` need to be atomic, because other threads can read (atomically) from `calls_to_do` without holding `pending->mutex`.
* GH-108362: Incremental Cycle GC (GH-116206)Mark Shannon2024-03-204-321/+512
|
* gh-117041: Add "-X gil" in the Python CLI help (GH-117042)Serhiy Storchaka2024-03-191-0/+5
|
* gh-90300: Improve the Python CLI help output (GH-115853)Serhiy Storchaka2024-03-191-78/+40
| | | | | | | | | * document equivalent command-line options for all environment variables * document equivalent environment variables for all command-line options * reduce the size of variable and option descriptions to minimum * remove the ending period in single-sentence descriptions Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
* GH-116017: Put JIT code and data on the same page (GH-116845)Brandt Bucher2024-03-191-29/+23
|
* gh-116808: Fix optimized trace length histogram (GH-116827)Michael Droettboom2024-03-191-1/+2
|
* gh-115756: make PyCode_GetFirstFree an unstable API (GH-115781)Bogdan Romanyuk2024-03-192-2/+2
|
* gh-108716: Cleanup remaining deepfreeze infrastructure (#116919)Guido van Rossum2024-03-182-34/+0
| | | | | Keep Tools/build/deepfreeze.py around (we may repurpose it for deepfreezing non-code objects), and keep basic "clean" targets that remove the output of former deep-freeze activities, to keep the build directories of current devs clean.
* gh-116916: Remove separate next_func_version counter (#116918)Guido van Rossum2024-03-181-1/+0
| | | | | Somehow we ended up with two separate counter variables tracking "the next function version". Most likely this was a historical accident where an old branch was updated incorrectly. This PR merges the two counters into a single one: `interp->func_state.next_version`.
* Cleanup tier2 debug output (#116920)Guido van Rossum2024-03-185-22/+50
| | | Various tweaks, including a slight refactor of the special cases for `_PUSH_FRAME`/`_POP_FRAME` to show the actual operand emitted.