Commit Graph

5858 Commits

Author SHA1 Message Date
Mark Shannon 844596c09f
GH-131498: Cases generator: Allow input and 'peek' variables to be modified (GH-132506) 2025-04-14 12:19:53 +01:00
Tomas R. 3d08c8ad20
gh-131927: Prevent emitting optimizer warnings twice in the REPL (#131993) 2025-04-12 11:34:36 +01:00
Jelle Zijlstra 07b8d3117f
gh-132261: Store annotations at hidden internal keys in the class dict (#132345) 2025-04-10 21:13:26 -07:00
Neil Schemenauer d687900f98
gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)
Make `warnings.catch_warnings()` use a context variable for holding
the warning filtering state if the `sys.flags.context_aware_warnings`
flag is set to true.  This makes using the context manager thread-safe in
multi-threaded programs.

Add the `sys.flags.thread_inherit_context` flag.  If true, starting a new
thread with `threading.Thread` will use a copy of the context
from the caller of `Thread.start()`.

Both these flags are set to true by default for the free-threaded build
and false for the default build.

Move the Python implementation of warnings.py into _py_warnings.py.

Make _contextvars a builtin module.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-04-09 16:18:54 -07:00
Brandt Bucher 20926c73b5
GH-131798: Remove JIT guards for dict, frozenset, list, set, and tuple (GH-132289) 2025-04-09 14:32:21 -07:00
Hugo van Kemenade b6b5767e9b Post 3.14.0a7 2025-04-08 17:06:51 +03:00
Hugo van Kemenade 29af6cee02 Python 3.14.0a7 2025-04-08 14:20:51 +03:00
Irit Katriel 8c9ef8f1f8
gh-100239: more stats for BINARY_OP/SUBSCR specialization (#132230) 2025-04-08 08:50:51 +00:00
Pieter Eendebak dff8bcfa3c
gh-126703: Add freelist for range and range_iter objects (GH-128619) 2025-04-07 04:40:52 +08:00
Pablo Galindo Salgado 2067378e6d
gh-131591: Handle includes for iOS in remote_debugging.c (#132050) 2025-04-06 21:39:25 +01:00
Chris Eibl d827d4d018
gh-131591: Fix GENERATE_DEBUG_SECTION for clangcl on Windows (GH-132112) 2025-04-06 00:00:54 +08:00
Pieter Eendebak 29772b0647
gh-126703: Add PyCFunction freelist (GH-128692) 2025-04-05 23:51:05 +08:00
Mark Shannon 7099c75550
GH-131498: Cases generator: manage stacks automatically (GH-132074) 2025-04-04 17:59:36 +01:00
Irit Katriel df59226997
gh-100239: more refined specialisation stats for BINARY_OP/SUBSCR (#132068) 2025-04-04 15:33:31 +01:00
Chris Eibl 20098719df
GH-131288: Use `_AddressOfReturnAddress` for MSVC in pycore_ceval.h (gh-131289)
Use `_AddressOfReturnAddress` in `_Py_get_machine_stack_pointer` to silence MSVC warning in pycore_ceval.h for release builds.
2025-04-04 09:03:12 -04:00
Pablo Galindo Salgado 943cc1431e
gh-131591: Implement PEP 768 (#131937)
Co-authored-by: Ivona Stojanovic <stojanovic.i@hotmail.com>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
2025-04-03 16:20:01 +01:00
Mark Shannon 275056a7fd
GH-131904: Fix Py_STACKREF_DEBUG build (GH-132022) 2025-04-03 09:40:37 +01:00
Brandt Bucher 3a8cefba0b
GH-131726: Split up _CHECK_VALIDITY_AND_SET_IP (GH-131810) 2025-04-01 16:55:05 -07:00
Brandt Bucher 1a9d4a1fb3
GH-131798: Allow the JIT to remove more int/float/str guards (GH-131800) 2025-04-01 15:10:15 -07:00
mpage cd69d55f64
gh-131987: Bump the magic number (#131991)
This should have been done as part of 053c285 but got blown away
in a merge.
2025-04-01 14:53:49 -07:00
mpage 053c285f6b
gh-130704: Strength reduce `LOAD_FAST{_LOAD_FAST}` (#130708)
Optimize `LOAD_FAST` opcodes into faster versions that load borrowed references onto the operand stack when we can prove that the lifetime of the local outlives the lifetime of the temporary that is loaded onto the stack.
2025-04-01 10:18:42 -07:00
Vincent Fazio 03f6c8e239
gh-131675: Fix `mi_atomic_yield` in mimalloc on 32-bit ARM (gh-131784)
Use the standard `__ARM_ARCH` macro, which is supported by GCC and Clang.

The branching logic for of `__ARMEL__` has been removed so if the target
architecture supports v7+ instructions, a yield is emitted, otherwise a nop
is emitted. This covers both big and little endian scenarios.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
2025-03-31 18:29:12 +00:00
Amit Lavon 685fd74f81
GH-131798: Remove type checks for _TO_BOOL_STR (GH-131816) 2025-03-30 16:07:25 -07:00
Jelle Zijlstra 425f60b9eb
gh-130924: Do not create cells for usages of names in local annotations (#131843) 2025-03-29 21:15:48 +00:00
Dino Viehland 2984ff9e51
gh-130373: Avoid locking in _LOAD_ATTR_WITH_HINT (#130372)
Avoid locking in _LOAD_ATTR_WITH_HINT
2025-03-28 15:16:41 -07:00
Irit Katriel 2c8f329dc6
gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737) 2025-03-28 10:35:20 +00:00
Michael Droettboom 8614f86b71
gh-131525: Cache the result of tuple_hash (#131529)
* gh-131525: Cache the result of tuple_hash

* Fix debug builds

* Add blurb

* Fix formatting

* Pre-compute empty tuple singleton

* Mostly set the cache within tuple_alloc

* Fixes for TSAN

* Pre-compute empty tuple singleton

* Fix for 32-bit platforms

* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE

* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro

* Update Include/internal/pycore_tuple.h

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix alignment

* atomic load

* Update Objects/tupleobject.c

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-03-27 09:57:06 -04:00
Neil Schemenauer 316938bddf
Revise `pycore_stackref.h` comments. (#130601) 2025-03-27 14:00:25 +05:30
Neil Schemenauer c824d8e6f9
gh-131782: Fix cast to match type of `bits` in `_Py_TryIncrefCompareStackRef` (#131783) 2025-03-27 13:58:59 +05:30
Brandt Bucher 4b3d5b6042
GH-119866: Don't clear frame->stackpointer on release builds (GH-131750) 2025-03-26 19:00:16 +00:00
Sam Gross 67fbfb42bd
gh-131586: Avoid refcount contention in some "special" calls (#131588)
In the free threaded build, the `_PyObject_LookupSpecial()` call can lead to
reference count contention on the returned function object becuase it
doesn't use stackrefs. Refactor some of the callers to use
`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.

This fixes the scaling bottleneck in the "lookup_special" microbenchmark
in `ftscalingbench.py`. However, the are still some uses of
`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
2025-03-26 14:38:47 -04:00
Sam Gross 3d4ac1a2c2
gh-123358: Use `_PyStackRef` in `LOAD_DEREF` (gh-130064)
Concurrent accesses from multiple threads to the same `cell` object did not
scale well in the free-threaded build. Use `_PyStackRef` and optimistically
avoid locking to improve scaling.

With the locks around cell reads gone, some of the free threading tests were
prone to starvation: the readers were able to run in a tight loop and the
writer threads weren't scheduled frequently enough to make timely progress.
Adjust the tests to avoid this.

Co-authored-by: Donghee Na <donghee.na@python.org>
2025-03-26 12:08:20 -04:00
Mark Shannon 1b8bb1ed0c
GH-131729: Code-gen better liveness analysis (GH-131732)
* Rename 'defined' attribute to 'in_local' to more accurately reflect how it is used

* Make death of variables explicit even for array variables.

* Convert in_memory from boolean to stack offset

* Don't apply liveness analysis to optimizer generated code

* Fix RETURN_VALUE in optimizer
2025-03-26 15:21:35 +00:00
Jelle Zijlstra 898e6b395e
gh-130881: Handle conditionally defined annotations (#130935) 2025-03-26 03:48:19 +00:00
Victor Stinner 5fef4ff9ed
gh-111178: Fix function signature in pyexpat.c (#131674)
Move _Py_NO_SANITIZE_UNDEFINED macro from faulthandler.c to pyport.h.
2025-03-24 17:22:45 +00:00
Sam Gross da6730caa5
gh-128421: Avoid TSAN warnings in `sys._current_frames()` (gh-131548)
This tells TSAN not to sanitize `PyUnstable_InterpreterFrame_GetLine()`.
There's a possible data race on the access to the frame's `instr_ptr`
if the frame is currently executing. We don't really care about the
race. In theory, we could use relaxed atomics for every access to
`instr_ptr`, but that would create more code churn and current compilers
are overly conservative with optimizations around relaxed atomic
accesses.

We also don't sanitize `_PyFrame_IsIncomplete()` because it accesses
`instr_ptr` and is called from assertions within PyFrame_GetCode().
2025-03-24 09:49:39 -04:00
Petr Viktorin 0e53038ea8
gh-128715: Expose ctypes.CField, with info attributes (GH-128950)
- Restore max field size to sys.maxsize, as in Python 3.13 & below
- PyCField: Split out bit/byte sizes/offsets.
- Expose CField's size/offset data to Python code
- Add generic checks for all the test structs/unions, using the newly exposed attrs
2025-03-24 14:18:34 +01:00
Dino Viehland d9411ae3c2
gh-130312: SET_ADD should not lock (#130136)
SET_ADD should not lock
2025-03-21 15:58:32 -07:00
Victor Stinner 7101cba6bf
gh-131238: Move _Py_VISIT_STACKREF() to pycore_stackref.h (#131560)
* Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h.
* Remove pycore_interpframe.h include from pycore_genobject.h.
* Remove now useless includes from C files.
* Add pycore_interpframe_structs.h to Makefile.pre.in and
  pythoncore.vcxproj.
2025-03-21 23:24:14 +01:00
Savannah Ostrowski b92ee14b80
GH-130415: Optimize constant comparison in JIT builds (GH-131489) 2025-03-21 11:23:12 -07:00
Victor Stinner 61317074d4
gh-131238: Add pycore_interpframe_structs.h header (#131553)
Add an explicit include to pycore_interpframe_structs.h in
pycore_runtime_structs.h to fix a dependency cycle.
2025-03-21 17:19:47 +00:00
Victor Stinner 1a082085ae
gh-131238: Remove pycore_object_deferred.h from pycore_object.h (#131549)
Remove also pycore_function.h from pycore_typeobject.h.
2025-03-21 16:44:10 +00:00
Bénédikt Tran 883c2f682b
GH-131331: Rename "not" to "invert" (GH-131334) 2025-03-20 16:59:41 -07:00
Mark Shannon 684a759c20
GH-127705: Don't call _Py_ForgetReference before _Py_Dealloc (GH-131508) 2025-03-20 15:45:43 +00:00
Mark Shannon 7ebd71ee14
GH-131498: Remove conditional stack effects (GH-131499)
* Adds some missing #includes
2025-03-20 15:39:38 +00:00
Mark Shannon 83d54fa876
GH-130296: Remove `_PyOpcode_max_stack_effect` as it is no longer used (GH-131493) 2025-03-20 11:42:54 +00:00
Victor Stinner b69da006a4
gh-131238: Remove includes from pycore_interp.h (#131495)
Remove also now unused includes in C files.
2025-03-20 11:35:23 +00:00
Victor Stinner 6c776abb90
gh-131238: Cleanup pycore_runtime.h includes (#131486) 2025-03-20 00:47:30 +00:00
Victor Stinner 344f3c3fd4
gh-131238: Remove pycore_lock.h includes (#131483)
PyMutex type is now part of <Python.h>, it's no longer needed to
include <pycore_lock.h> to get it.
2025-03-19 23:46:25 +00:00
Victor Stinner 6827c5129c
gh-131238: Move pycore_obmalloc.h include to pycore_runtime_structs.h (#131482)
Move pycore_obmalloc.h include from pycore_interp_structs.h to
pycore_runtime_structs.h.

Add also comment explaining the purpose of each include in
pycore_interp_structs.h, pycore_runtime_structs.h and
pycore_structs.h.

Remove <stdbool.h> and <stddef.h> from pycore_structs.h.
2025-03-19 23:32:30 +00:00