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
Make the restrict MSVC only for now
  • Loading branch information
Fidget-Spinner committed Oct 11, 2025
commit 35e96c17459519255648423fc162d36ae4c37578
2 changes: 1 addition & 1 deletion Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ PyAPI_FUNC(PyObject *)_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, Py
PyAPI_FUNC(void) _PyEval_MonitorRaise(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, _PyStackRef *sp);
PyAPI_FUNC(void) _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *restrict input, Py_ssize_t nargs);
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *input, Py_ssize_t nargs);

PyAPI_FUNC(void) _PyObjectArray_Free(_PyThreadStateImpl *_tstate, PyObject **array, Py_ssize_t nargs, PyObject **temp_arr);

Expand Down
8 changes: 7 additions & 1 deletion Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,18 @@ extern "C" {
# define Py_NO_INLINE
#endif

#if defined(_MSC_VER) && Py_TAIL_CALL_INTERP
#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

#if defined(_MSC_VER) && !defined(__clang__)
# define Py_MSVC_RESTRICT restrict
#else
# define Py_MSVC_RESTRICT
#endif

// Just a scope. Hints to the programmer
// That any local variable defined within this block MUST
// not escape from the current definition.
Expand Down
2 changes: 1 addition & 1 deletion Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
}

Py_NO_INLINE_MSVC_TAILCALL int
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **restrict result)
_PyEval_Mapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **Py_MSVC_RESTRICT result)
{
return PyMapping_GetOptionalItem(obj, key, result);
}
Expand Down
14 changes: 7 additions & 7 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ dummy_func(
}

inst(LOAD_BUILD_CLASS, ( -- bc)) {
PyObject *restrict bc_o;
PyObject *Py_MSVC_RESTRICT bc_o;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a more semantically meaningful name than Py_MSVC_RESTRICT here? "Unaliased" or "no escape"?

And possibly define it as a macro like #define UNALIASED(x) x Py_MSVC_RESTRICT to get UNALIASED(PyObject *) bc_o?

Just looking to reduce the sense of "oh I have to go look up this MSVC thing to know what's going on here" when reading the code. There may be other ways.

int err = _PyEval_Mapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
ERROR_IF(err < 0);
if (bc_o == NULL) {
Expand Down Expand Up @@ -1738,7 +1738,7 @@ dummy_func(

inst(LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
PyObject *restrict v_o;
PyObject *Py_MSVC_RESTRICT v_o;
int err = _PyEval_Mapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
PyStackRef_CLOSE(mod_or_class_dict);
ERROR_IF(err < 0);
Expand Down Expand Up @@ -1925,7 +1925,7 @@ dummy_func(
}

inst(LOAD_FROM_DICT_OR_DEREF, (class_dict_st -- value)) {
PyObject *restrict value_o;
PyObject *Py_MSVC_RESTRICT value_o;
PyObject *name;
PyObject *class_dict = PyStackRef_AsPyObjectBorrow(class_dict_st);

Expand Down Expand Up @@ -2115,7 +2115,7 @@ dummy_func(
}

inst(SETUP_ANNOTATIONS, (--)) {
PyObject *restrict ann_dict;
PyObject *Py_MSVC_RESTRICT ann_dict;
if (LOCALS() == NULL) {
_PyErr_Format(tstate, PyExc_SystemError,
"no locals found when setting up annotations");
Expand Down Expand Up @@ -2228,7 +2228,7 @@ dummy_func(
// handle any case whose performance we care about
PyObject *super;
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't require parentheses on macros like this, especially when they define a scope.

PyObject *restrict stack[] = {class, self};
PyObject *Py_MSVC_RESTRICT stack[] = {class, self};
super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
Py_END_LOCALS_MUST_NOT_ESCAPE();
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
Expand Down Expand Up @@ -2295,7 +2295,7 @@ dummy_func(
}
PyStackRef_CLOSE(self_st);
self_or_null = PyStackRef_NULL;

DECREF_INPUTS();

attr = PyStackRef_FromPyObjectSteal(attr_o);
Expand Down Expand Up @@ -3509,7 +3509,7 @@ dummy_func(
(void)lasti; // Shut up compiler warning if asserts are off
PyObject* res_o;
Py_BEGIN_LOCALS_MUST_NOT_ESCAPE();
PyObject *restrict stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
PyObject *Py_MSVC_RESTRICT 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);
Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ extern void _PyUOpPrint(const _PyUOpInstruction *uop);


PyObject **
_PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *input, Py_ssize_t nargs)
_PyObjectArray_FromStackRefArray(_PyThreadStateImpl *_tstate, _PyStackRef *Py_MSVC_RESTRICT input, Py_ssize_t nargs)
{
PyObject **result;
/* +1 because vectorcall might use -1 to write self */
Expand Down
8 changes: 4 additions & 4 deletions Python/executor_cases.c.h

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

14 changes: 7 additions & 7 deletions Python/generated_cases.c.h

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