Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion .github/workflows/tail-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
# Un-comment as we add support for more platforms for tail-calling interpreters.
# - i686-pc-windows-msvc/msvc
- x86_64-pc-windows-msvc/msvc
- free-threading-msvc
# - aarch64-pc-windows-msvc/msvc
- x86_64-apple-darwin/clang
- aarch64-apple-darwin/clang
Expand All @@ -53,6 +54,9 @@ jobs:
- target: x86_64-pc-windows-msvc/msvc
architecture: x64
runner: windows-2025-vs2026
- target: free-threading-msvc
architecture: x64
runner: windows-2025-vs2026
# - target: aarch64-pc-windows-msvc/msvc
# architecture: ARM64
# runner: windows-2022
Expand Down Expand Up @@ -80,13 +84,21 @@ jobs:
python-version: '3.11'

- name: Native Windows MSVC (release)
if: runner.os == 'Windows' && matrix.architecture != 'ARM64'
if: runner.os == 'Windows' && matrix.architecture != 'ARM64' && matrix.target != 'free-threading-msvc'
shell: pwsh
run: |
$env:PlatformToolset = "v145"
./PCbuild/build.bat --tail-call-interp -c Release -p ${{ matrix.architecture }}
./PCbuild/rt.bat -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
# No tests:
- name: Native Windows MSVC with free-threading (release)
if: matrix.target == 'free-threading-msvc'
shell: pwsh
run: |
$env:PlatformToolset = "v145"
./PCbuild/build.bat --tail-call-interp --disable-gil -c Release -p ${{ matrix.architecture }}
# No tests (yet):
- name: Emulated Windows Clang (release)
if: runner.os == 'Windows' && matrix.architecture == 'ARM64'
Expand Down
5 changes: 5 additions & 0 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ _Py_assert_within_stack_bounds(
_PyInterpreterFrame *frame, _PyStackRef *stack_pointer,
const char *filename, int lineno);

PyAPI_FUNC(_PyStackRef)
_Py_LoadAttr_StackRefSteal(
PyThreadState *tstate, _PyStackRef owner,
PyObject *name, _PyStackRef *self_or_null);

// Like PyMapping_GetOptionalItem, but returns the PyObject* instead of taking
// it as an out parameter. This helps MSVC's escape analysis when used with
// tail calling.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix building the tail calling interpreter on Visual Studio 2026 with free-threading.
23 changes: 3 additions & 20 deletions Modules/_testinternalcapi/test_cases.c.h

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

28 changes: 3 additions & 25 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,31 +2364,9 @@ dummy_func(
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 1);
if (oparg & 1) {
/* Designed to work in tandem with CALL, pushes two values. */
_PyCStackRef method;
_PyThreadState_PushCStackRef(tstate, &method);
int is_meth = _PyObject_GetMethodStackRef(tstate, PyStackRef_AsPyObjectBorrow(owner), name, &method.ref);
if (is_meth) {
/* We can bypass temporary bound method object.
meth is unbound method and obj is self.
meth | self | arg1 | ... | argN
*/
assert(!PyStackRef_IsNull(method.ref)); // No errors on this branch
self_or_null[0] = owner; // Transfer ownership
DEAD(owner);
attr = _PyThreadState_PopCStackRefSteal(tstate, &method);
}
else {
/* meth is not an unbound method (but a regular attr, or
something was returned by a descriptor protocol). Set
the second element of the stack to NULL, to signal
CALL that it's not a method call.
meth | NULL | arg1 | ... | argN
*/
PyStackRef_CLOSE(owner);
self_or_null[0] = PyStackRef_NULL;
attr = _PyThreadState_PopCStackRefSteal(tstate, &method);
ERROR_IF(PyStackRef_IsNull(attr));
}
attr = _Py_LoadAttr_StackRefSteal(tstate, owner, name, self_or_null);
DEAD(owner);
ERROR_IF(PyStackRef_IsNull(attr));
}
else {
/* Classic, pushes one value. */
Expand Down
28 changes: 28 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,34 @@ _Py_BuildMap_StackRefSteal(
return res;
}

_PyStackRef
_Py_LoadAttr_StackRefSteal(
PyThreadState *tstate, _PyStackRef owner,
PyObject *name, _PyStackRef *self_or_null)
{
_PyCStackRef method;
_PyThreadState_PushCStackRef(tstate, &method);
int is_meth = _PyObject_GetMethodStackRef(tstate, PyStackRef_AsPyObjectBorrow(owner), name, &method.ref);
if (is_meth) {
/* We can bypass temporary bound method object.
meth is unbound method and obj is self.
meth | self | arg1 | ... | argN
*/
assert(!PyStackRef_IsNull(method.ref)); // No errors on this branch
self_or_null[0] = owner; // Transfer ownership
return _PyThreadState_PopCStackRefSteal(tstate, &method);
}
/* meth is not an unbound method (but a regular attr, or
something was returned by a descriptor protocol). Set
the second element of the stack to NULL, to signal
CALL that it's not a method call.
meth | NULL | arg1 | ... | argN
*/
PyStackRef_CLOSE(owner);
self_or_null[0] = PyStackRef_NULL;
return _PyThreadState_PopCStackRefSteal(tstate, &method);
}

#ifdef Py_DEBUG
void
_Py_assert_within_stack_bounds(
Expand Down
26 changes: 6 additions & 20 deletions Python/executor_cases.c.h

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

23 changes: 3 additions & 20 deletions Python/generated_cases.c.h

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

Loading