From 3563dbdd3100493f3d73260ae5cca330b63ed291 Mon Sep 17 00:00:00 2001 From: Zachary Ware Date: Fri, 13 Sep 2024 16:39:52 -0500 Subject: [PATCH] Revert "gh-121459: Deferred LOAD_GLOBAL (GH-123128)" This reverts commit 8810e286fa48876422d1b230208911decbead294. --- Include/internal/pycore_ceval.h | 2 +- Include/internal/pycore_dict.h | 3 -- Objects/dictobject.c | 74 --------------------------------- Python/bytecodes.c | 12 +++--- Python/ceval.c | 20 ++++----- Python/executor_cases.c.h | 9 ++-- Python/generated_cases.c.h | 9 ++-- Python/optimizer_cases.c.h | 8 ++-- 8 files changed, 29 insertions(+), 108 deletions(-) diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index a97b53028c8f59..e4af731be0e87f 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -271,7 +271,7 @@ PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyStackRef *input, Py_ PyAPI_FUNC(void) _PyObjectArray_Free(PyObject **array, PyObject **scratch); PyAPI_FUNC(PyObject *) _PyEval_GetANext(PyObject *aiter); -PyAPI_FUNC(void) _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name, _PyStackRef *writeto); +PyAPI_FUNC(PyObject *) _PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name); PyAPI_FUNC(PyObject *) _PyEval_GetAwaitable(PyObject *iterable, int oparg); PyAPI_FUNC(PyObject *) _PyEval_LoadName(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *name); diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h index f9a043b0208c8f..100250928d2064 100644 --- a/Include/internal/pycore_dict.h +++ b/Include/internal/pycore_dict.h @@ -10,7 +10,6 @@ extern "C" { #include "pycore_object.h" // PyManagedDictPointer #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_SSIZE_ACQUIRE -#include "pycore_stackref.h" // _PyStackRef // Unsafe flavor of PyDict_GetItemWithError(): no error checking extern PyObject* _PyDict_GetItemWithError(PyObject *dp, PyObject *key); @@ -101,12 +100,10 @@ extern void _PyDictKeys_DecRef(PyDictKeysObject *keys); */ extern Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr); extern Py_ssize_t _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr); -extern Py_ssize_t _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr); extern Py_ssize_t _PyDict_LookupIndex(PyDictObject *, PyObject *); extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key); PyAPI_FUNC(PyObject *)_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *); -PyAPI_FUNC(void) _PyDict_LoadGlobalStackRef(PyDictObject *, PyDictObject *, PyObject *, _PyStackRef *); /* Consumes references to key and value */ PyAPI_FUNC(int) _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value); diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 006bc593c2a754..b81ed189456ec1 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1496,45 +1496,6 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb return ix; } -Py_ssize_t -_Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr) -{ - PyDictKeysObject *dk = _Py_atomic_load_ptr(&mp->ma_keys); - if (dk->dk_kind == DICT_KEYS_UNICODE && PyUnicode_CheckExact(key)) { - Py_ssize_t ix = unicodekeys_lookup_unicode_threadsafe(dk, key, hash); - if (ix == DKIX_EMPTY) { - *value_addr = PyStackRef_NULL; - return ix; - } - else if (ix >= 0) { - PyObject **addr_of_value = &DK_UNICODE_ENTRIES(dk)[ix].me_value; - PyObject *value = _Py_atomic_load_ptr(addr_of_value); - if (value == NULL) { - *value_addr = PyStackRef_NULL; - return DKIX_EMPTY; - } - if (_Py_IsImmortal(value) || _PyObject_HasDeferredRefcount(value)) { - *value_addr = (_PyStackRef){ .bits = (uintptr_t)value | Py_TAG_DEFERRED }; - return ix; - } - if (_Py_TryIncrefCompare(addr_of_value, value)) { - *value_addr = PyStackRef_FromPyObjectSteal(value); - return ix; - } - } - } - - PyObject *obj; - Py_ssize_t ix = _Py_dict_lookup_threadsafe(mp, key, hash, &obj); - if (ix >= 0 && obj != NULL) { - *value_addr = PyStackRef_FromPyObjectSteal(obj); - } - else { - *value_addr = PyStackRef_NULL; - } - return ix; -} - #else // Py_GIL_DISABLED Py_ssize_t @@ -1545,15 +1506,6 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb return ix; } -Py_ssize_t -_Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr) -{ - PyObject *val; - Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &val); - *value_addr = val == NULL ? PyStackRef_NULL : PyStackRef_FromPyObjectNew(val); - return ix; -} - #endif int @@ -2468,32 +2420,6 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key) return value; } -void -_PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObject *key, _PyStackRef *res) -{ - Py_ssize_t ix; - Py_hash_t hash; - - hash = _PyObject_HashFast(key); - if (hash == -1) { - *res = PyStackRef_NULL; - return; - } - - /* namespace 1: globals */ - ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res); - if (ix == DKIX_ERROR) { - *res = PyStackRef_NULL; - } - if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) { - return; - } - - /* namespace 2: builtins */ - ix = _Py_dict_lookup_threadsafe_stackref(builtins, key, hash, res); - assert(ix >= 0 || PyStackRef_IsNull(*res)); -} - /* Consumes references to key and value */ static int setitem_take2_lock_held(PyDictObject *mp, PyObject *key, PyObject *value) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 846404e28bb18f..078f06d697cc3c 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1469,8 +1469,8 @@ dummy_func( && PyDict_CheckExact(BUILTINS())) { v_o = _PyDict_LoadGlobal((PyDictObject *)GLOBALS(), - (PyDictObject *)BUILTINS(), - name); + (PyDictObject *)BUILTINS(), + name); if (v_o == NULL) { if (!_PyErr_Occurred(tstate)) { /* _PyDict_LoadGlobal() returns NULL without raising @@ -1526,12 +1526,12 @@ dummy_func( #endif /* ENABLE_SPECIALIZATION */ } - // res[1] because we need a pointer to res to pass it to _PyEval_LoadGlobalStackRef - op(_LOAD_GLOBAL, ( -- res[1], null if (oparg & 1))) { + op(_LOAD_GLOBAL, ( -- res, null if (oparg & 1))) { PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1); - _PyEval_LoadGlobalStackRef(GLOBALS(), BUILTINS(), name, res); - ERROR_IF(PyStackRef_IsNull(*res), error); + PyObject *res_o = _PyEval_LoadGlobal(GLOBALS(), BUILTINS(), name); + ERROR_IF(res_o == NULL, error); null = PyStackRef_NULL; + res = PyStackRef_FromPyObjectSteal(res_o); } macro(LOAD_GLOBAL) = diff --git a/Python/ceval.c b/Python/ceval.c index 6236c668ee65eb..252833a6243293 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3110,14 +3110,15 @@ _PyEval_GetANext(PyObject *aiter) return awaitable; } -void -_PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name, _PyStackRef *writeto) +PyObject * +_PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name) { + PyObject *res; if (PyDict_CheckExact(globals) && PyDict_CheckExact(builtins)) { - _PyDict_LoadGlobalStackRef((PyDictObject *)globals, + res = _PyDict_LoadGlobal((PyDictObject *)globals, (PyDictObject *)builtins, - name, writeto); - if (PyStackRef_IsNull(*writeto) && !PyErr_Occurred()) { + name); + if (res == NULL && !PyErr_Occurred()) { /* _PyDict_LoadGlobal() returns NULL without raising * an exception if the key doesn't exist */ _PyEval_FormatExcCheckArg(PyThreadState_GET(), PyExc_NameError, @@ -3127,16 +3128,13 @@ _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name else { /* Slow-path if globals or builtins is not a dict */ /* namespace 1: globals */ - PyObject *res; if (PyMapping_GetOptionalItem(globals, name, &res) < 0) { - *writeto = PyStackRef_NULL; - return; + return NULL; } if (res == NULL) { /* namespace 2: builtins */ if (PyMapping_GetOptionalItem(builtins, name, &res) < 0) { - *writeto = PyStackRef_NULL; - return; + return NULL; } if (res == NULL) { _PyEval_FormatExcCheckArg( @@ -3144,8 +3142,8 @@ _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name NAME_ERROR_MSG, name); } } - *writeto = PyStackRef_FromPyObjectSteal(res); } + return res; } PyObject * diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 93ab068f9de949..b36fff9961febe 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -1661,14 +1661,15 @@ } case _LOAD_GLOBAL: { - _PyStackRef *res; + _PyStackRef res; _PyStackRef null = PyStackRef_NULL; oparg = CURRENT_OPARG(); - res = &stack_pointer[0]; PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1); - _PyEval_LoadGlobalStackRef(GLOBALS(), BUILTINS(), name, res); - if (PyStackRef_IsNull(*res)) JUMP_TO_ERROR(); + PyObject *res_o = _PyEval_LoadGlobal(GLOBALS(), BUILTINS(), name); + if (res_o == NULL) JUMP_TO_ERROR(); null = PyStackRef_NULL; + res = PyStackRef_FromPyObjectSteal(res_o); + stack_pointer[0] = res; if (oparg & 1) stack_pointer[1] = null; stack_pointer += 1 + (oparg & 1); assert(WITHIN_STACK_BOUNDS()); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 6d902e2c1d9ba8..3e9f0396e495b7 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -5674,7 +5674,7 @@ PREDICTED(LOAD_GLOBAL); _Py_CODEUNIT *this_instr = next_instr - 5; (void)this_instr; - _PyStackRef *res; + _PyStackRef res; _PyStackRef null = PyStackRef_NULL; // _SPECIALIZE_LOAD_GLOBAL { @@ -5696,12 +5696,13 @@ /* Skip 1 cache entry */ // _LOAD_GLOBAL { - res = &stack_pointer[0]; PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1); - _PyEval_LoadGlobalStackRef(GLOBALS(), BUILTINS(), name, res); - if (PyStackRef_IsNull(*res)) goto error; + PyObject *res_o = _PyEval_LoadGlobal(GLOBALS(), BUILTINS(), name); + if (res_o == NULL) goto error; null = PyStackRef_NULL; + res = PyStackRef_FromPyObjectSteal(res_o); } + stack_pointer[0] = res; if (oparg & 1) stack_pointer[1] = null; stack_pointer += 1 + (oparg & 1); assert(WITHIN_STACK_BOUNDS()); diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index a6cfa271ae6758..e89c969ad0df67 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -829,13 +829,11 @@ } case _LOAD_GLOBAL: { - _Py_UopsSymbol **res; + _Py_UopsSymbol *res; _Py_UopsSymbol *null = NULL; - res = &stack_pointer[0]; - for (int _i = 1; --_i >= 0;) { - res[_i] = sym_new_not_null(ctx); - } + res = sym_new_not_null(ctx); null = sym_new_null(ctx); + stack_pointer[0] = res; if (oparg & 1) stack_pointer[1] = null; stack_pointer += 1 + (oparg & 1); assert(WITHIN_STACK_BOUNDS()); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy