]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-115999: Specialize `STORE_ATTR` in free-threaded builds. (gh-127838)
authorNeil Schemenauer <nas-github@arctrix.com>
Thu, 19 Dec 2024 18:21:17 +0000 (10:21 -0800)
committerGitHub <noreply@github.com>
Thu, 19 Dec 2024 18:21:17 +0000 (10:21 -0800)
commit1b15c89a17ca3de6b05de5379b8717e9738c51ef
tree00a4ea63dec7879e81d2ea3d75f43cb8a03ee1b5
parentd2f1d917e8b3d2dd8f35495c7632a32688883332
gh-115999: Specialize `STORE_ATTR` in free-threaded builds. (gh-127838)

* 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`.
13 files changed:
Include/internal/pycore_dict.h
Include/internal/pycore_opcode_metadata.h
Include/internal/pycore_uop_ids.h
Include/internal/pycore_uop_metadata.h
Lib/test/test_free_threading/test_races.py
Lib/test/test_opcache.py
Modules/_testinternalcapi.c
Objects/dictobject.c
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h
Python/optimizer_cases.c.h
Python/specialize.c