Commit graph

8535 commits

Author SHA1 Message Date
Donghee Na 2e7577b622
gh-111968: Use per-thread freelists for tuple in free-threading (gh-113921) 2024-01-12 03:46:28 +09:00
Serhiy Storchaka 8717f7b495
gh-113845: Fix a compiler warning in Python/suggestions.c (GH-113949) 2024-01-11 20:31:24 +02:00
Mark Shannon 55824d01f8
GH-113853: Guarantee forward progress in executors (GH-113854) 2024-01-11 18:20:42 +00:00
Irit Katriel 0d8fec79ca
gh-107901: jump leaving an exception handler doesn't need an eval break check (#113943) 2024-01-11 14:27:41 +00:00
Peter Lazorchak f653caa5a8
gh-89811: Check for valid tp_version_tag in specializer (GH-113558) 2024-01-11 13:33:05 +08:00
Donghee Na f728f7242c
gh-111968: Use per-thread freelists for float in free-threading (gh-113886) 2024-01-10 15:47:13 +00:00
Mark Shannon a0c9cf9456
GH-113860: All executors are now defined in terms of micro ops. Convert counter executor to use uops. (GH-113864) 2024-01-10 15:44:34 +00:00
Donghee Na 57bdc6c30d
gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584) 2024-01-10 08:04:41 +09:00
Guido van Rossum 65f8eb7119
Fix opcode name printing in debug mode (#113870)
Fix a few places where the lltrace debug output printed ``(null)`` instead of an opcode name, because it was calling ``_PyUOpName()`` on a Tier-1 opcode.
2024-01-09 18:18:11 +00:00
Yan Yanchii fda901a1ff
gh-113842: Add missing error check for PyIter_Next() in Python/symtable.c (GH-113843) 2024-01-09 12:43:58 +02:00
Pablo Galindo Salgado a03ec20bcd
gh-110721: Remove unused code from suggestions.c after moving PyErr_Display to use the traceback module (#113712) 2024-01-08 15:10:45 +00:00
Hugo van Kemenade e5d0316f35
gh-73965: Move PYTHON_HISTORY into the correct usage section (#113798)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-01-08 11:58:58 +02:00
Zackery Spytz f19b93fce0
gh-73965: New environment variable PYTHON_HISTORY (#13208)
It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <0xl3vi@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2024-01-06 22:30:12 -08:00
Irit Katriel d36a365118
gh-107901: synthetic jumps which are not at end of loop no longer check the eval breaker (#113721) 2024-01-06 14:20:08 +00:00
Sam Gross 99854ce170
gh-113688: Split up gcmodule.c (gh-113715)
This splits part of Modules/gcmodule.c of into Python/gc.c, which
now contains the core garbage collection implementation. The Python
module remain in the Modules/gcmodule.c file.
2024-01-05 12:17:16 -08:00
Sam Gross 0b7476080b
gh-112532: Tag mimalloc heaps and pages (#113742)
* gh-112532: Tag mimalloc heaps and pages

Mimalloc pages are data structures that contain contiguous allocations
of the same block size. Note that they are distinct from operating
system pages. Mimalloc pages are contained in segments.

When a thread exits, it abandons any segments and contained pages that
have live allocations. These segments and pages may be later reclaimed
by another thread. To support GC and certain thread-safety guarantees in
free-threaded builds, we want pages to only be reclaimed by the
corresponding heap in the claimant thread. For example, we want pages
containing GC objects to only be claimed by GC heaps.

This allows heaps and pages to be tagged with an integer tag that is
used to ensure that abandoned pages are only claimed by heaps with the
same tag. Heaps can be initialized with a tag (0-15); any page allocated
by that heap copies the corresponding tag.

* Fix conversion warning
2024-01-05 12:08:50 -08:00
Mark Shannon 0ae60b66de
GH-113486: Do not emit spurious PY_UNWIND events for optimized calls to classes. (GH-113680) 2024-01-05 09:45:22 +00:00
Sam Gross fcb3c2a444
gh-112532: Isolate abandoned segments by interpreter (#113717)
* gh-112532: Isolate abandoned segments by interpreter

Mimalloc segments are data structures that contain memory allocations along
with metadata. Each segment is "owned" by a thread. When a thread exits,
it abandons its segments to a global pool to be later reclaimed by other
threads. This changes the pool to be per-interpreter instead of process-wide.

This will be important for when we use mimalloc to find GC objects in the
`--disable-gil` builds. We want heaps to only store Python objects from a
single interpreter. Absent this change, the abandoning and reclaiming process
could break this isolation.

* Add missing '&_mi_abandoned_default' to 'tld_empty'
2024-01-04 22:21:40 +00:00
Brandt Bucher 35ef8cb259
GH-113689: Fix broken handling of invalid executors (GH-113694) 2024-01-04 11:14:15 +00:00
Irit Katriel 7d01fb4808
gh-113603: Compiler no longer tries to maintain the no-empty-block invariant (#113636) 2024-01-03 16:57:48 +00:00
Mark Shannon dc8df6e840
GH-113595: Don't enter invalid executor (GH-113596) 2024-01-03 11:01:13 +00:00
Brandt Bucher b0fb074d59
GH-113657: Add back missing _SET_IP uops in tier two (GH-113662) 2024-01-02 14:09:57 -08:00
Inada Naoki bfee2f77e1
gh-73427: deprecate _enablelegacywindowsfsencoding (#107729) 2023-12-28 17:31:19 +09:00
Sam Gross acf3bcc886
gh-112532: Use separate mimalloc heaps for GC objects (gh-113263)
* gh-112532: Use separate mimalloc heaps for GC objects

In `--disable-gil` builds, we now use four separate heaps in
anticipation of using mimalloc to find GC objects when the GIL is
disabled. To support this, we also make a few changes to mimalloc:

* `mi_heap_t` and `mi_tld_t` initialization is split from allocation.
  This allows us to have a `mi_tld_t` per-`PyThreadState`, which is
  important to keep interpreter isolation, since the same OS thread may
  run in multiple interpreters (using different PyThreadStates.)

* Heap abandoning (mi_heap_collect_ex) can now be called from a
  different thread than the one that created the heap. This is necessary
  because we may clear and delete the containing PyThreadStates from a
  different thread during finalization and after fork().

* Use enum instead of defines and guard mimalloc includes.

* The enum typedef will be convenient for future PRs that use the type.
* Guarding the mimalloc includes allows us to unconditionally include
  pycore_mimalloc.h from other header files that rely on things like
  `struct _mimalloc_thread_state`.

* Only define _mimalloc_thread_state in Py_GIL_DISABLED builds
2023-12-27 01:53:20 +09:00
Yilei Yang 48c49739f5
gh-106905: Use separate structs to track recursion depth in each PyAST_mod2obj call. (GH-113035)
Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2023-12-25 19:36:59 +02:00
Mark Shannon 9a35794fcb
GH-111485: Fix handling of FOR_ITER in Tier 2 (GH-113394) 2023-12-24 10:07:34 -08:00
Irit Katriel c31943af16
gh-113297: Fix segfault in compiler for with statement with 19 context managers (#113327) 2023-12-22 01:50:26 +00:00
Namhyung Kim 6b70c3dc5a
gh-113343: Fix error check on mmap(2) (#113342)
Fix error check on mmap(2)

It should check MAP_FAILED instead of NULL for error.

On mmap(2) man page:

  RETURN VALUE
       On success, mmap() returns a pointer to the mapped area.
       On error, the value MAP_FAILED (that is, (void *) -1) is
       returned, and errno is set to indicate the error.
2023-12-21 19:28:55 +00:00
Mark Shannon 723f4d6698
GH-111485: Delete the old generator code. (GH-113321) 2023-12-21 12:46:28 +00:00
Carey Metcalfe a2dd0e7038
gh-111375: Use NULL rather than None in the exception stack to indicate that an exception was handled (#113302) 2023-12-21 01:46:41 +00:00
Mark Shannon de8a4e52a5
GH-111485: Generate TARGET table for computed goto dispatch. (GH-113319) 2023-12-20 15:09:12 +00:00
Mark Shannon e96f26083b
GH-111485: Generate instruction and uop metadata (GH-113287) 2023-12-20 14:27:25 +00:00
Irit Katriel e51b400945
gh-113054: Compiler no longer replaces a redundant jump with no line number by a NOP (#113139) 2023-12-19 11:04:44 +00:00
Donghee Na d00dbf5415
gh-112535: Implement fallback implementation of _Py_ThreadId() (gh-113185)
---------

Co-authored-by: Sam Gross <colesbury@gmail.com>
2023-12-18 16:54:49 +00:00
Mark Shannon 70d378cdaa
GH-111485: Break up instructions with unused cache entries into component micro-ops (GH-113169) 2023-12-18 13:16:45 +00:00
Mark Shannon 771903596b
GH-111485: Test the new cases generator (GH-113252) 2023-12-18 11:14:40 +00:00
Sam Gross 5ae75e1be2
gh-111964: Add _PyRWMutex a "readers-writer" lock (gh-112859)
This adds `_PyRWMutex`, a "readers-writer" lock, which wil be used to
serialize global stop-the-world pauses with per-interpreter pauses.
2023-12-15 18:56:55 -07:00
Brandt Bucher 737d23ffcd
GH-111485: Mark some instructions as TIER_ONE_ONLY (GH-113155) 2023-12-15 13:03:17 +00:00
Mark Shannon 6873555955
GH-112354: Treat _EXIT_TRACE like an unconditional side exit (GH-113104) 2023-12-14 14:26:44 +00:00
Serhiy Storchaka 1161c14e8c
gh-112716: Fix SystemError when __builtins__ is not a dict (GH-112770)
It was raised in two cases:
* in the import statement when looking up __import__
* in pickling some builtin type when looking up built-ins iter, getattr, etc.
2023-12-14 14:24:24 +02:00
Mark Shannon 9263173280
Fix whitespace in generated code 2023-12-13 12:31:41 +00:00
Eric Snow c6e614fd81
gh-76785: Avoid Pickled TracebackException for Propagated Subinterpreter Exceptions (gh-113036)
We need the TracebackException of uncaught exceptions for a single purpose: the error display.  Thus we only need to pass the formatted error display between interpreters.  Passing a pickled TracebackException is overkill.
2023-12-13 00:31:30 +00:00
Sam Gross a3c031884d
gh-112723: Call PyThreadState_Clear() from the correct interpreter (#112776)
The `PyThreadState_Clear()` function must only be called with the GIL
held and must be called from the same interpreter as the passed in
thread state. Otherwise, any Python objects on the thread state may be
destroyed using the wrong interpreter, leading to memory corruption.

This is also important for `Py_GIL_DISABLED` builds because free lists
will be associated with PyThreadStates and cleared in
`PyThreadState_Clear()`.

This fixes two places that called `PyThreadState_Clear()` from the wrong
interpreter and adds an assertion to `PyThreadState_Clear()`.
2023-12-12 17:20:21 -07:00
Eric Snow 8a4c1f3ff1
gh-76785: Show the Traceback for Uncaught Subinterpreter Exceptions (gh-113034)
When an exception is uncaught in Interpreter.exec_sync(), it helps to show that exception's error display if uncaught in the calling interpreter.  We do so here by generating a TracebackException in the subinterpreter and passing it between interpreters using pickle.
2023-12-13 00:00:54 +00:00
Guido van Rossum 7316dfb0eb
gh-112320: Implement on-trace confidence tracking for branches (#112321)
We track the confidence as a scaled int.
2023-12-12 21:43:08 +00:00
Michael Droettboom dfaa9e060b
gh-113010: Don't decrement deferred in pystats (#113032)
This fixes a recently introduced bug where the deferred count is being unnecessarily decremented to counteract an increment elsewhere that is no longer happening. This caused the values to flip around to "very large" 64-bit numbers.
2023-12-12 21:17:08 +00:00
Mark Shannon 956023826a
GH-108866: Guarantee forward progress in executors. (GH-113006) 2023-12-12 19:02:24 +00:00
Eric Snow 86a77f4e1a
gh-76785: Fixes for test.support.interpreters (gh-112982)
This involves a number of changes for PEP 734.
2023-12-12 08:24:31 -07:00
Mark Shannon 0c55f27060
GH-111485: Factor out tier 2 code generation from the rest of the interpreter code generator (GH-112968) 2023-12-12 12:12:17 +00:00
Sam James c454e934d3
gh-112970: Detect and use closefrom() when available (#112969)
glibc-2.34 implements closefrom(3) using the same semantics as on BSD.
Check for closefrom() in configure and use the check result in
fileutils.c, rather than hardcoding a FreeBSD check.

Some implementations of closefrom() return an int. Explicitly discard 
the return value by casting it to void, to avoid future compiler
warnings.

Signed-off-by: Sam James <sam@gentoo.org>
2023-12-12 11:25:27 +01:00