Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
82d1259
Brandt's changes
Fidget-Spinner Aug 21, 2025
3248658
Hulon's and mine changes
Fidget-Spinner Aug 21, 2025
9ac430d
push stackrefs into tstate
Fidget-Spinner Aug 21, 2025
085c1d7
Fix last few remaining problems
Fidget-Spinner Aug 21, 2025
0b12f2e
fix handling of recursion
Fidget-Spinner Aug 24, 2025
acf48f5
Changes by Chris to support clang-cl
Fidget-Spinner Oct 11, 2025
35e96c1
Make the restrict MSVC only for now
Fidget-Spinner Oct 11, 2025
d7737e9
Merge remote-tracking branch 'upstream/main' into msvc-tailcall-take-two
Fidget-Spinner Oct 11, 2025
86f19cf
Change restricts to MSVC only
Fidget-Spinner Oct 11, 2025
40013cc
📜🤖 Added by blurb_it.
blurb-it[bot] Oct 11, 2025
48db59e
Reduce diff
Fidget-Spinner Oct 11, 2025
bc9d23c
Merge branch 'msvc-tailcall-take-two' of github.com:Fidget-Spinner/cp…
Fidget-Spinner Oct 11, 2025
19e02c2
Work around specialization
Fidget-Spinner Oct 11, 2025
66ec774
Fix VS 2026
Fidget-Spinner Oct 11, 2025
50f8ff7
fix a typo
Fidget-Spinner Oct 11, 2025
5d908b4
Move to macros to internal header
Fidget-Spinner Oct 11, 2025
0786133
Merge branch 'msvc-tailcall-take-two' of github.com:Fidget-Spinner/cp…
Fidget-Spinner Oct 11, 2025
e699d40
Reduce number of restricts
Fidget-Spinner Oct 13, 2025
66d6c39
Merge branch 'msvc-tailcall-take-two' of https://github.com/Fidget-Sp…
Fidget-Spinner Oct 13, 2025
5584fec
Reduce restrict use even more, reduce usage
Fidget-Spinner Oct 13, 2025
7eeeaa8
Apply Chris' changes
Fidget-Spinner Oct 23, 2025
6f3d525
Merge remote-tracking branch 'upstream/main' into msvc-tailcall-take-two
Fidget-Spinner Nov 4, 2025
81618e2
Merge remote-tracking branch 'upstream/main' into msvc-tailcall-take-two
Fidget-Spinner Nov 11, 2025
2008d1d
Use choco for now to get VS 2026
Fidget-Spinner Nov 11, 2025
7c84388
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
68b41cf
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
c7316fc
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
9214d5b
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
52c6f9c
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
34d98d3
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
7ec626e
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
ad1c5a2
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
4155337
Update tail-call.yml
Fidget-Spinner Nov 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply Chris' changes
Co-Authored-By: Chris Eibl <[email protected]>
  • Loading branch information
Fidget-Spinner and chris-eibl committed Oct 23, 2025
commit 7eeeaa81bd6bf609e29997a8ade7b943f74e744c
22 changes: 0 additions & 22 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,28 +391,6 @@ _PyForIter_VirtualIteratorNext(PyThreadState* tstate, struct _PyInterpreterFrame
#define SPECIAL___AEXIT__ 3
#define SPECIAL_MAX 3

// Special counterparts of ceval functions for performance reasons
PyAPI_FUNC(int) _PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result);

#if defined(_MSC_VER) && !defined(__clang__) && _Py_TAIL_CALL_INTERP
# define Py_NO_INLINE_MSVC_TAILCALL Py_NO_INLINE
#else
# define Py_NO_INLINE_MSVC_TAILCALL
#endif

// Tells the compiler that this variable cannot be alised.
#if defined(_MSC_VER) && !defined(__clang__)
# define Py_UNALIASED(var) restrict var
#else
# define Py_UNALIASED(var) var
#endif

// Just a scope. Hints to the programmer and compiler
// That any local variable defined within this block MUST
// not escape from the current definition.
# define Py_BEGIN_LOCALS_MUST_NOT_ESCAPE {
# define Py_END_LOCALS_MUST_NOT_ESCAPE }

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 7 additions & 7 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ PyObject_GetItem(PyObject *o, PyObject *key)
return type_error("'%.200s' object is not subscriptable", o);
}

// MSVC fails during a tail call release build with loads of
// error C4737: Unable to perform required tail call.
// without using Py_NO_INLINE here, but PGO works fine.
#if defined(_MSC_VER) && !defined(__clang__) && _Py_TAIL_CALL_INTERP && !defined(_Py_USING_PGO)
Py_NO_INLINE
#endif
int
PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **restrict result)
{
if (PyDict_CheckExact(obj)) {
return PyDict_GetItemRef(obj, key, result);
Expand All @@ -224,12 +230,6 @@ PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
return 0;
}

Py_NO_INLINE_MSVC_TAILCALL int
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **Py_UNALIASED(result))
{
return PyMapping_GetOptionalItem(obj, key, result);
}

int
PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
{
Expand Down
2 changes: 1 addition & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ _PyDict_NewPresized(Py_ssize_t minused)
return dict_new_presized(minused, false);
}

Py_NO_INLINE_MSVC_TAILCALL PyObject *
PyObject *
_PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
PyObject *const *values, Py_ssize_t values_offset,
Py_ssize_t length)
Expand Down
42 changes: 21 additions & 21 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ dummy_func(

inst(LOAD_BUILD_CLASS, ( -- bc)) {
PyObject *bc_o;
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
int err = PyMapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
ERROR_IF(err < 0);
if (bc_o == NULL) {
_PyErr_SetString(tstate, PyExc_NameError,
Expand Down Expand Up @@ -1739,7 +1739,7 @@ dummy_func(
inst(LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
PyObject *v_o;
int err = _PyEval_Mapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
int err = PyMapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
PyStackRef_CLOSE(mod_or_class_dict);
ERROR_IF(err < 0);
if (v_o == NULL) {
Expand All @@ -1762,11 +1762,11 @@ dummy_func(
else {
/* Slow-path if globals or builtins is not a dict */
/* namespace 1: globals */
int err = _PyEval_Mapping_GetOptionalItem(GLOBALS(), name, &v_o);
int err = PyMapping_GetOptionalItem(GLOBALS(), name, &v_o);
ERROR_IF(err < 0);
if (v_o == NULL) {
/* namespace 2: builtins */
int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), name, &v_o);
int err = PyMapping_GetOptionalItem(BUILTINS(), name, &v_o);
ERROR_IF(err < 0);
if (v_o == NULL) {
_PyEval_FormatExcCheckArg(
Expand Down Expand Up @@ -1932,7 +1932,7 @@ dummy_func(
assert(class_dict);
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
int err = _PyEval_Mapping_GetOptionalItem(class_dict, name, &value_o);
int err = PyMapping_GetOptionalItem(class_dict, name, &value_o);
if (err < 0) {
ERROR_NO_POP();
}
Expand Down Expand Up @@ -2122,7 +2122,7 @@ dummy_func(
ERROR_IF(true);
}
/* check if __annotations__ in locals()... */
int err = _PyEval_Mapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
int err = PyMapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
ERROR_IF(err < 0);
if (ann_dict == NULL) {
ann_dict = PyDict_New();
Expand Down Expand Up @@ -2227,10 +2227,10 @@ dummy_func(
// we make no attempt to optimize here; specializations should
// handle any case whose performance we care about
PyObject *super;
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
PyObject *stack[] = {class, self};
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
Py_END_LOCALS_MUST_NOT_ESCAPE;
{
PyObject *stack[] = {class, self};
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
}
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
PyObject *arg = oparg & 2 ? class : &_PyInstrumentation_MISSING;
if (super == NULL) {
Expand Down Expand Up @@ -2290,11 +2290,11 @@ dummy_func(
PyTypeObject *cls = (PyTypeObject *)class;
int method_found = 0;
PyObject *attr_o;
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
int *method_found_ptr = &method_found;
attr_o = _PySuper_Lookup(cls, self, name,
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL);
Py_END_LOCALS_MUST_NOT_ESCAPE;
{
int *method_found_ptr = &method_found;
attr_o = _PySuper_Lookup(cls, self, name,
Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL);
}
if (attr_o == NULL) {
ERROR_NO_POP();
}
Expand Down Expand Up @@ -3518,12 +3518,12 @@ dummy_func(
assert(PyStackRef_IsTaggedInt(lasti));
(void)lasti; // Shut up compiler warning if asserts are off
PyObject* res_o;
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE;
PyObject *stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
int has_self = !PyStackRef_IsNull(exit_self);
res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
Py_END_LOCALS_MUST_NOT_ESCAPE;
{
PyObject *stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
int has_self = !PyStackRef_IsNull(exit_self);
res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
}
Py_XDECREF(original_tb);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
Expand Down
36 changes: 18 additions & 18 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 33 additions & 33 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading