Skip to content

Commit 7eeeaa8

Browse files
Apply Chris' changes
Co-Authored-By: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
1 parent 5584fec commit 7eeeaa8

File tree

6 files changed

+80
-102
lines changed

6 files changed

+80
-102
lines changed

Include/internal/pycore_ceval.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -391,28 +391,6 @@ _PyForIter_VirtualIteratorNext(PyThreadState* tstate, struct _PyInterpreterFrame
391391
#define SPECIAL___AEXIT__ 3
392392
#define SPECIAL_MAX 3
393393

394-
// Special counterparts of ceval functions for performance reasons
395-
PyAPI_FUNC(int) _PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result);
396-
397-
#if defined(_MSC_VER) && !defined(__clang__) && _Py_TAIL_CALL_INTERP
398-
# define Py_NO_INLINE_MSVC_TAILCALL Py_NO_INLINE
399-
#else
400-
# define Py_NO_INLINE_MSVC_TAILCALL
401-
#endif
402-
403-
// Tells the compiler that this variable cannot be alised.
404-
#if defined(_MSC_VER) && !defined(__clang__)
405-
# define Py_UNALIASED(var) restrict var
406-
#else
407-
# define Py_UNALIASED(var) var
408-
#endif
409-
410-
// Just a scope. Hints to the programmer and compiler
411-
// That any local variable defined within this block MUST
412-
// not escape from the current definition.
413-
# define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE {
414-
# define Py_END_LOCALS_MUST_NOT_ESCAPE }
415-
416394
#ifdef __cplusplus
417395
}
418396
#endif

Objects/abstract.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ PyObject_GetItem(PyObject *o, PyObject *key)
205205
return type_error("'%.200s' object is not subscriptable", o);
206206
}
207207

208+
// MSVC fails during a tail call release build with loads of
209+
// error C4737: Unable to perform required tail call.
210+
// without using Py_NO_INLINE here, but PGO works fine.
211+
#if defined(_MSC_VER) && !defined(__clang__) && _Py_TAIL_CALL_INTERP && !defined(_Py_USING_PGO)
212+
Py_NO_INLINE
213+
#endif
208214
int
209-
PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
215+
PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **restrict result)
210216
{
211217
if (PyDict_CheckExact(obj)) {
212218
return PyDict_GetItemRef(obj, key, result);
@@ -224,12 +230,6 @@ PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
224230
return 0;
225231
}
226232

227-
Py_NO_INLINE_MSVC_TAILCALL int
228-
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **Py_UNALIASED(result))
229-
{
230-
return PyMapping_GetOptionalItem(obj, key, result);
231-
}
232-
233233
int
234234
PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
235235
{

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ _PyDict_NewPresized(Py_ssize_t minused)
22252225
return dict_new_presized(minused, false);
22262226
}
22272227

2228-
Py_NO_INLINE_MSVC_TAILCALL PyObject *
2228+
PyObject *
22292229
_PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
22302230
PyObject *const *values, Py_ssize_t values_offset,
22312231
Py_ssize_t length)

Python/bytecodes.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ dummy_func(
15351535

15361536
inst(LOAD_BUILD_CLASS, ( -- bc)) {
15371537
PyObject *bc_o;
1538-
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
1538+
int err = PyMapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
15391539
ERROR_IF(err < 0);
15401540
if (bc_o == NULL) {
15411541
_PyErr_SetString(tstate, PyExc_NameError,
@@ -1739,7 +1739,7 @@ dummy_func(
17391739
inst(LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
17401740
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
17411741
PyObject *v_o;
1742-
int err = _PyEval_Mapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
1742+
int err = PyMapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
17431743
PyStackRef_CLOSE(mod_or_class_dict);
17441744
ERROR_IF(err < 0);
17451745
if (v_o == NULL) {
@@ -1762,11 +1762,11 @@ dummy_func(
17621762
else {
17631763
/* Slow-path if globals or builtins is not a dict */
17641764
/* namespace 1: globals */
1765-
int err = _PyEval_Mapping_GetOptionalItem(GLOBALS(), name, &v_o);
1765+
int err = PyMapping_GetOptionalItem(GLOBALS(), name, &v_o);
17661766
ERROR_IF(err < 0);
17671767
if (v_o == NULL) {
17681768
/* namespace 2: builtins */
1769-
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), name, &v_o);
1769+
int err = PyMapping_GetOptionalItem(BUILTINS(), name, &v_o);
17701770
ERROR_IF(err < 0);
17711771
if (v_o == NULL) {
17721772
_PyEval_FormatExcCheckArg(
@@ -1932,7 +1932,7 @@ dummy_func(
19321932
assert(class_dict);
19331933
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
19341934
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
1935-
int err = _PyEval_Mapping_GetOptionalItem(class_dict, name, &value_o);
1935+
int err = PyMapping_GetOptionalItem(class_dict, name, &value_o);
19361936
if (err < 0) {
19371937
ERROR_NO_POP();
19381938
}
@@ -2122,7 +2122,7 @@ dummy_func(
21222122
ERROR_IF(true);
21232123
}
21242124
/* check if __annotations__ in locals()... */
2125-
int err = _PyEval_Mapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
2125+
int err = PyMapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
21262126
ERROR_IF(err < 0);
21272127
if (ann_dict == NULL) {
21282128
ann_dict = PyDict_New();
@@ -2227,10 +2227,10 @@ dummy_func(
22272227
// we make no attempt to optimize here; specializations should
22282228
// handle any case whose performance we care about
22292229
PyObject *super;
2230-
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
2231-
PyObject *stack[] = {class, self};
2232-
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
2233-
Py_END_LOCALS_MUST_NOT_ESCAPE;
2230+
{
2231+
PyObject *stack[] = {class, self};
2232+
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
2233+
}
22342234
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
22352235
PyObject *arg = oparg & 2 ? class : &_PyInstrumentation_MISSING;
22362236
if (super == NULL) {
@@ -2290,11 +2290,11 @@ dummy_func(
22902290
PyTypeObject *cls = (PyTypeObject *)class;
22912291
int method_found = 0;
22922292
PyObject *attr_o;
2293-
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
2294-
int *method_found_ptr = &method_found;
2295-
attr_o = _PySuper_Lookup(cls, self, name,
2296-
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL);
2297-
Py_END_LOCALS_MUST_NOT_ESCAPE;
2293+
{
2294+
int *method_found_ptr = &method_found;
2295+
attr_o = _PySuper_Lookup(cls, self, name,
2296+
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL);
2297+
}
22982298
if (attr_o == NULL) {
22992299
ERROR_NO_POP();
23002300
}
@@ -3518,12 +3518,12 @@ dummy_func(
35183518
assert(PyStackRef_IsTaggedInt(lasti));
35193519
(void)lasti; // Shut up compiler warning if asserts are off
35203520
PyObject* res_o;
3521-
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
3522-
PyObject *stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
3523-
int has_self = !PyStackRef_IsNull(exit_self);
3524-
res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
3525-
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
3526-
Py_END_LOCALS_MUST_NOT_ESCAPE;
3521+
{
3522+
PyObject *stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
3523+
int has_self = !PyStackRef_IsNull(exit_self);
3524+
res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
3525+
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
3526+
}
35273527
Py_XDECREF(original_tb);
35283528
ERROR_IF(res_o == NULL);
35293529
res = PyStackRef_FromPyObjectSteal(res_o);

Python/executor_cases.c.h

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)