summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-141367: Use CALL_LIST_APPEND instruction only for lists, not for list ↵Mikhail Efimov2025-11-141-6/+11
| | | | | subclasses (GH-141398) Co-authored-by: Ken Jin <kenjin4096@gmail.com>
* gh-131253: free-threaded build support for pystats (gh-137189)Neil Schemenauer2025-11-031-420/+6
| | | | | | | | Allow the --enable-pystats build option to be used with free-threading. The stats are now stored on a per-interpreter basis, rather than process global. For free-threaded builds, the stats structure is allocated per-thread and then periodically merged into the per-interpreter stats structure (on thread exit or when the reporting function is called). Most of the pystats related code has be moved into the file Python/pystats.c.
* gh-139525: Don't specialize functions which have a modified vectorcall (#139524)Dino Viehland2025-10-031-0/+9
| | | Don't specialize functions which have a modified vectorcall
* gh-138302: Specialize int ops only if ints are compact (GH-138347)Tapeline2025-09-011-3/+3
|
* gh-137238: Fix data race in `_Py_slot_tp_getattr_hook` (gh-137240)Sam Gross2025-08-051-8/+1
| | | | | Replacing the slot isn't thread-safe if the GIL is disabled. Don't require that the slot has been replaced when specializing.
* gh-132815: Add support for JUMP_BACKWARD in specialization stats (#135606)PuQing2025-06-171-0/+1
|
* GH-132554: "Virtual" iterators (GH-132555)Mark Shannon2025-05-271-37/+41
| | | | | | * FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero * NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
* GH-131798: Split up and optimize CALL_ISINSTANCE (GH-133339)Tomas R.2025-05-081-1/+1
|
* Revert "gh-133395: add option for extension modules to specialize ↵Irit Katriel2025-05-061-31/+4
| | | | BINARY_OP/SUBSCR, apply to arrays (#133396)" (#133498)
* GH-131798: Split CALL_LEN into several uops (GH-133180)Diego Russo2025-05-051-1/+1
|
* gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, ↵Irit Katriel2025-05-051-4/+31
| | | | apply to arrays (#133396)
* gh-100239: specialize BINARY_OP/SUBSCR for list-slice (#132626)Irit Katriel2025-05-011-0/+4
|
* PyStats: Make sure that the `failure_kinds` array is big enough. (#133245)Mark Shannon2025-05-011-1/+3
|
* GH-132554: Add stats for GET_ITER (GH-132592)Mark Shannon2025-04-291-0/+49
| | | | | | | * Add stats for GET_ITER * Look for common iterable types, not iterator types * Add stats for self iter and fix naming in summary
* gh-132643: use atomic load for dict in specializer (#132653)Kumar Aditya2025-04-181-1/+2
|
* gh-132336: Mark a few "slow path" functions used by the interpreter loop as ↵mpage2025-04-101-14/+14
| | | | | | | | | noinline (#132337) Mark a few functions used by the interpreter loop as noinline These are all the slow path and should not be inlined into the interpreter loop. Unfortunately, they end up being inlined with LTO and the current PGO task.
* gh-100239: more stats for BINARY_OP/SUBSCR specialization (#132230)Irit Katriel2025-04-081-0/+30
|
* gh-100239: fix bug in comparison (#132093)Irit Katriel2025-04-041-2/+2
|
* gh-100239: more refined specialisation stats for BINARY_OP/SUBSCR (#132068)Irit Katriel2025-04-041-0/+35
|
* gh-130373: Avoid locking in _LOAD_ATTR_WITH_HINT (#130372)Dino Viehland2025-03-281-0/+3
| | | Avoid locking in _LOAD_ATTR_WITH_HINT
* gh-130931: Add pycore_interpframe.h internal header (#131249)Victor Stinner2025-03-191-1/+1
| | | | Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
* gh-131281: Add include for pystats builds (#131369)Ken Jin2025-03-171-0/+1
| | | Add include to for pystats builds
* GH-131238: More refactoring of core header files (GH-131351)Mark Shannon2025-03-171-0/+2
| | | | Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
* gh-115999: Add free-threaded specialization for FOR_ITER (#128798)T. Wouters2025-03-121-21/+32
| | | | Add free-threaded versions of existing specialization for FOR_ITER (list, tuples, fast range iterators and generators), without significantly affecting their thread-safety. (Iterating over shared lists/tuples/ranges should be fine like before. Reusing iterators between threads is not fine, like before. Sharing generators between threads is a recipe for significant crashes, like before.)
* gh-100239: replace BINARY_SUBSCR & family by BINARY_OP with oparg NB_SUBSCR ↵Irit Katriel2025-02-071-170/+128
| | | | (#129700)
* GH-129715: Remove _DYNAMIC_EXIT (GH-129716)Brandt Bucher2025-02-071-0/+1
|
* GH-128842: Collect JIT memory stats (GH-128941)Diego Russo2025-02-021-0/+8
|
* GH-128872: Remove unused argument from _PyCode_Quicken (GH-128873)Yan Yanchii2025-02-021-2/+1
| | | Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* gh-100239: specialize bitwise logical binary ops on ints (#128927)Irit Katriel2025-01-291-0/+54
|
* Revert "GH-128914: Remove conditional stack effects from `bytecodes.c` and ↵Sam Gross2025-01-231-76/+32
| | | | | | | the code generators (GH-128918)" (GH-129202) The commit introduced a ~2.5-3% regression in the free threading build. This reverts commit ab61d3f4303d14a413bc9ae6557c730ffdf7579e.
* GH-128914: Remove conditional stack effects from `bytecodes.c` and the code ↵Mark Shannon2025-01-201-32/+76
| | | | generators (GH-128918)
* gh-100239: Handle NaN and zero division in guards for `BINARY_OP_EXTEND` ↵Kirill Podoprigora2025-01-191-6/+24
| | | | | | (#128963) Co-authored-by: Tomas R. <tomas.roun8@gmail.com> Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* gh-100239: specialize long tail of binary operations (#128722)Irit Katriel2025-01-161-4/+105
|
* gh-115999: Specialize `LOAD_ATTR` for instance and class receivers in ↵mpage2025-01-141-90/+139
| | | | | | | free-threaded builds (#128164) Finish specialization for LOAD_ATTR in the free-threaded build by adding support for class and instance receivers.
* GH-128685: Specialize (rather than quicken) LOAD_CONST into ↵Mark Shannon2025-01-131-9/+0
| | | | LOAD_CONST_[IM]MORTAL (GH-128708)
* gh-115999: Add free-threaded specialization for COMPARE_OP (#126410)T. Wouters2025-01-071-10/+7
| | | | | Add free-threaded specialization for COMPARE_OP, and tests for COMPARE_OP specialization in general. Co-authored-by: Donghee Na <donghee.na92@gmail.com>
* gh-128262: Allow specialization of calls to classes with __slots__ (GH-128263)Ken Jin2024-12-311-4/+0
|
* gh-119786: Mention `InternalDocs/interpreter.md` instead of non-existing ↵Yan Yanchii2024-12-301-1/+1
| | | | | | | | `adaptive.md` (#128329) `Python/specialize.c`: Mention `InternalDocs/interpreter.md` instead of non-existing `adaptive.md` Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* gh-115999: Specialize `STORE_ATTR` in free-threaded builds. (gh-127838)Neil Schemenauer2024-12-191-107/+164
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add `_PyDictKeys_StringLookupSplit` which does locking on dict keys and use in place of `_PyDictKeys_StringLookup`. * Change `_PyObject_TryGetInstanceAttribute` to use that function in the case of split keys. * Add `unicodekeys_lookup_split` helper which allows code sharing between `_Py_dict_lookup` and `_PyDictKeys_StringLookupSplit`. * Fix locking for `STORE_ATTR_INSTANCE_VALUE`. Create `_GUARD_TYPE_VERSION_AND_LOCK` uop so that object stays locked and `tp_version_tag` cannot change. * Pass `tp_version_tag` to `specialize_dict_access()`, ensuring the version we store on the cache is the correct one (in case of it changing during the specalize analysis). * Split `analyze_descriptor` into `analyze_descriptor_load` and `analyze_descriptor_store` since those don't share much logic. Add `descriptor_is_class` helper function. * In `specialize_dict_access`, double check `_PyObject_GetManagedDict()` in case we race and dict was materialized before the lock. * Avoid borrowed references in `_Py_Specialize_StoreAttr()`. * Use `specialize()` and `unspecialize()` helpers. * Add unit tests to ensure specializing happens as expected in FT builds. * Add unit tests to attempt to trigger data races (useful for running under TSAN). * Add `has_split_table` function to `_testinternalcapi`.
* gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (gh-127737)Donghee Na2024-12-191-16/+19
|
* gh-115999: Specialize loading attributes from modules in free-threaded ↵mpage2024-12-131-36/+56
| | | | | | | | | builds (#127711) We use the same approach that was used for specialization of LOAD_GLOBAL in free-threaded builds: _CHECK_ATTR_MODULE is renamed to _CHECK_ATTR_MODULE_PUSH_KEYS; it pushes the keys object for the following _LOAD_ATTR_MODULE_FROM_KEYS (nee _LOAD_ATTR_MODULE). This arrangement avoids having to recheck the keys version. _LOAD_ATTR_MODULE is renamed to _LOAD_ATTR_MODULE_FROM_KEYS; it loads the value from the keys object pushed by the preceding _CHECK_ATTR_MODULE_PUSH_KEYS at the cached index.
* gh-115999: Specialize `CALL_KW` in free-threaded builds (#127713)mpage2024-12-111-13/+4
| | | | | | | | | | | | | * Enable specialization of CALL_KW * Fix bug pushing frame in _PY_FRAME_KW `_PY_FRAME_KW` pushes a pointer to the new frame onto the stack for consumption by the next uop. When pushing the frame fails, we do not want to push the result, `NULL`, to the stack because it is not a valid stackref. This works in the default build because `PyStackRef_NULL` and `NULL` are the same value, so the `PyStackRef_XCLOSE()` in the error handler ignores it. In the free-threaded build the values are not the same; `PyStackRef_XCLOSE()` will attempt to decref a null pointer.
* gh-125610: Fix `STORE_ATTR_INSTANCE_VALUE` specialization check (GH-125612)Sam Gross2024-12-061-1/+4
| | | | The `STORE_ATTR_INSTANCE_VALUE` opcode doesn't support objects with non-NULL managed dictionaries, so don't specialize to that op in that case.
* gh-115999: Enable specialization of `CALL` instructions in free-threaded ↵mpage2024-12-031-46/+66
| | | | | | | | | | | | | | | | | | | | | | builds (#127123) The CALL family of instructions were mostly thread-safe already and only required a small number of changes, which are documented below. A few changes were needed to make CALL_ALLOC_AND_ENTER_INIT thread-safe: Added _PyType_LookupRefAndVersion, which returns the type version corresponding to the returned ref. Added _PyType_CacheInitForSpecialization, which takes an init method and the corresponding type version and only populates the specialization cache if the current type version matches the supplied version. This prevents potentially caching a stale value in free-threaded builds if we race with an update to __init__. Only cache __init__ functions that are deferred in free-threaded builds. This ensures that the reference to __init__ that is stored in the specialization cache is valid if the type version guard in _CHECK_AND_ALLOCATE_OBJECT passes. Fix a bug in _CREATE_INIT_FRAME where the frame is pushed to the stack on failure. A few other miscellaneous changes were also needed: Use {LOCK,UNLOCK}_OBJECT in LIST_APPEND. This ensures that the list's per-object lock is held while we are appending to it. Add missing co_tlbc for _Py_InitCleanup. Stop/start the world around setting the eval frame hook. This allows us to read interp->eval_frame non-atomically and preserves the behavior of _CHECK_PEP_523 documented below.
* gh-115999: Add free-threaded specialization for `SEND` (gh-127426)Neil Schemenauer2024-12-031-11/+4
| | | | | No additional thread safety changes are required. Note that sending to a generator that is shared between threads is currently not safe in the free-threaded build.
* gh-115999: Specialize `LOAD_SUPER_ATTR` in free-threaded builds (gh-127128)Neil Schemenauer2024-12-031-14/+5
| | | | | | Use existing helpers to atomically modify the bytecode. Add unit tests to ensure specializing is happening as expected. Add test_specialize.py that can be used with ThreadSanitizer to detect data races. Fix thread safety issue with cell_set_contents().
* gh-127518: Fix pystats build after #127169 (#127526)Michael Droettboom2024-12-021-2/+3
| | | gh-127518: Fix pystats build after #127619
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-12-021-0/+2
| | | | | | | | | | | | | collection (GH-127110) * Mark almost all reachable objects before doing collection phase * Add stats for objects marked * Visit new frames before each increment * Update docs * Clearer calculation of work to do.
* gh-115999: Add partial free-thread specialization for BINARY_SUBSCR (gh-127227)Donghee Na2024-12-021-14/+11
|
* gh-115999: Add free-threaded specialization for `STORE_SUBSCR` (#127169)Sam Gross2024-11-261-62/+60
| | | | | | | | | The specialization only depends on the type, so no special thread-safety considerations there. STORE_SUBSCR_LIST_INT needs to lock the list before modifying it. `_PyDict_SetItem_Take2` already internally locks the dictionary using a critical section.