On Fedora 40+ x86_64 and aarch64, build Python with the experimental JIT compiler

This commit is contained in:
Miro Hrončok 2024-05-12 19:32:37 +02:00
commit f1315eaf0b
2 changed files with 75 additions and 3 deletions

View file

@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Tue, 18 Jun 2024 15:25:31 +0200
Subject: [PATCH] 00429: GH-118943: Fix another race condition when generating
jit_stencils.h
Another process might have already moved jit_stencils.h.new
---
.../Build/2024-06-18-15-28-25.gh-issue-118943.aie7nn.rst | 3 +++
Tools/jit/_targets.py | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 Misc/NEWS.d/next/Build/2024-06-18-15-28-25.gh-issue-118943.aie7nn.rst
diff --git a/Misc/NEWS.d/next/Build/2024-06-18-15-28-25.gh-issue-118943.aie7nn.rst b/Misc/NEWS.d/next/Build/2024-06-18-15-28-25.gh-issue-118943.aie7nn.rst
new file mode 100644
index 0000000000..997c990a96
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2024-06-18-15-28-25.gh-issue-118943.aie7nn.rst
@@ -0,0 +1,3 @@
+Fix a possible race condition affecting parallel builds configured with
+``--enable-experimental-jit``, in which :exc:`FileNotFoundError` could be caused by
+another process already moving ``jit_stencils.h.new`` to ``jit_stencils.h``.
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py
index 5604c429bc..73d10a1287 100644
--- a/Tools/jit/_targets.py
+++ b/Tools/jit/_targets.py
@@ -221,7 +221,12 @@ def build(
file.write("\n")
for line in _writer.dump(stencil_groups):
file.write(f"{line}\n")
- jit_stencils_new.replace(jit_stencils)
+ try:
+ jit_stencils_new.replace(jit_stencils)
+ except FileNotFoundError:
+ # another process probably already moved the file
+ if not jit_stencils.is_file():
+ raise
finally:
jit_stencils_new.unlink(missing_ok=True)

View file

@ -17,7 +17,7 @@ URL: https://www.python.org/
%global prerel b2
%global upstream_version %{general_version}%{?prerel}
Version: %{general_version}%{?prerel:~%{prerel}}
Release: 3%{?dist}
Release: 4%{?dist}
License: Python-2.0.1
@ -138,6 +138,22 @@ Provides: bundled(python3dist(packaging)) = 24
# (the -freethreading subpackage)
%bcond_without freethreading_build
# PEP 744: JIT Compilation
# Whether to build with the experimental JIT compiler
# We can only have this on Fedora 40+, where clang 18+ is available
# And only on certain architectures: https://peps.python.org/pep-0744/#support
# The freethreading build (when enabled) does not support JIT yet
%bcond_with jit
%ifarch x86_64 aarch64
%if 0%{?fedora} >= 40 || 0%{?rhel} >= 10
%bcond_without jit
%endif
%endif
%if %{with jit}
# When built with JIT, it still needs to be enabled on runtime via PYTHON_JIT=1
%global jit_flag --enable-experimental-jit=yes-off
%endif
# Support for the GDB debugger
%bcond_without gdb_hooks
@ -299,6 +315,11 @@ BuildRequires: tcl-devel
BuildRequires: tk-devel
BuildRequires: tzdata
%if %{with jit}
BuildRequires: clang(major) = 18
BuildRequires: llvm(major) = 18
%endif
%if %{with valgrind}
BuildRequires: valgrind-devel
%endif
@ -373,6 +394,12 @@ Source11: idle3.appdata.xml
# pypa/distutils integration: https://github.com/pypa/distutils/pull/70
Patch251: 00251-change-user-install-location.patch
# 00429 # fa7831be5e5365646d4dd400e23e977f83f64923
# GH-118943: Fix another race condition when generating jit_stencils.h
#
# Another process might have already moved jit_stencils.h.new
Patch429: 00429-gh-118943-fix-another-race-condition-when-generating-jit_stencils-h.patch
# (New patches go here ^^^)
#
# When adding new patches to "python" and "python3" in Fedora, EL, etc.,
@ -906,12 +933,12 @@ BuildPython() {
# option produces too many warnings when compiling at the O0 optimization level.
# See also: https://bugzilla.redhat.com/show_bug.cgi?id=1818857
BuildPython debug \
"--without-ensurepip --with-pydebug" \
"--without-ensurepip --with-pydebug %{?jit_flag}" \
"%{optflags_debug}"
%endif # with debug_build
BuildPython optimized \
"--without-ensurepip %{optimizations_flag}" \
"--without-ensurepip %{?jit_flag} %{optimizations_flag}" \
"%{optflags_optimized}"
%if %{with freethreading_build} && %{with debug_build}
@ -1687,6 +1714,11 @@ CheckPython freethreading
# ======================================================
%changelog
* Tue Jun 18 2024 Miro Hrončok <mhroncok@redhat.com> - 3.13.0~b2-4
- On Fedora 40+ x86_64 and aarch64, build Python with the experimental JIT compiler
- To enable it on runtime, set the PYTHON_JIT environment variable to 1
- https://peps.python.org/pep-0744/
* Thu Jun 06 2024 Python Maint <python-maint@redhat.com> - 3.13.0~b2-3
- Rebuilt for Python 3.13