Skip to content

Commit 00863e8

Browse files
authored
Merge branch 'main' into 145107-simplify-happy-eyeballs
2 parents 33a6756 + fd01372 commit 00863e8

4 files changed

Lines changed: 139 additions & 96 deletions

File tree

.github/workflows/jit.yml

Lines changed: 88 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: JIT
22
on:
33
pull_request:
4-
paths:
4+
paths: &paths
55
- '**jit**'
66
- 'Python/bytecodes.c'
77
- 'Python/optimizer*.c'
@@ -12,16 +12,7 @@ on:
1212
- '!**/*.md'
1313
- '!**/*.ini'
1414
push:
15-
paths:
16-
- '**jit**'
17-
- 'Python/bytecodes.c'
18-
- 'Python/optimizer*.c'
19-
- 'Python/executor_cases.c.h'
20-
- 'Python/optimizer_cases.c.h'
21-
- '**_testinternalcapi**'
22-
- '!Python/perf_jit_trampoline.c'
23-
- '!**/*.md'
24-
- '!**/*.ini'
15+
paths: *paths
2516
workflow_dispatch:
2617

2718
permissions:
@@ -33,12 +24,13 @@ concurrency:
3324

3425
env:
3526
FORCE_COLOR: 1
27+
LLVM_VERSION: 21
3628

3729
jobs:
3830
interpreter:
3931
name: Interpreter (Debug)
4032
runs-on: ubuntu-24.04
41-
timeout-minutes: 90
33+
timeout-minutes: 60
4234
steps:
4335
- uses: actions/checkout@v6
4436
with:
@@ -50,27 +42,22 @@ jobs:
5042
- name: Test tier two interpreter
5143
run: |
5244
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
53-
jit:
45+
46+
windows:
5447
name: ${{ matrix.target }} (${{ matrix.debug && 'Debug' || 'Release' }})
55-
needs: interpreter
48+
5649
runs-on: ${{ matrix.runner }}
57-
timeout-minutes: 90
50+
timeout-minutes: 60
5851
strategy:
5952
fail-fast: false
6053
matrix:
6154
target:
6255
- i686-pc-windows-msvc/msvc
6356
- x86_64-pc-windows-msvc/msvc
6457
- aarch64-pc-windows-msvc/msvc
65-
- x86_64-apple-darwin/clang
66-
- aarch64-apple-darwin/clang
67-
- x86_64-unknown-linux-gnu/gcc
68-
- aarch64-unknown-linux-gnu/gcc
6958
debug:
7059
- true
7160
- false
72-
llvm:
73-
- 21
7461
include:
7562
- target: i686-pc-windows-msvc/msvc
7663
architecture: Win32
@@ -81,131 +68,137 @@ jobs:
8168
- target: aarch64-pc-windows-msvc/msvc
8269
architecture: ARM64
8370
runner: windows-11-arm
84-
- target: x86_64-apple-darwin/clang
85-
architecture: x86_64
86-
runner: macos-15-intel
87-
- target: aarch64-apple-darwin/clang
88-
architecture: aarch64
89-
runner: macos-14
90-
- target: x86_64-unknown-linux-gnu/gcc
91-
architecture: x86_64
92-
runner: ubuntu-24.04
93-
- target: aarch64-unknown-linux-gnu/gcc
94-
architecture: aarch64
95-
runner: ubuntu-24.04-arm
9671
steps:
9772
- uses: actions/checkout@v6
9873
with:
9974
persist-credentials: false
10075
- uses: actions/setup-python@v6
10176
with:
10277
python-version: '3.11'
103-
10478
# PCbuild downloads LLVM automatically:
105-
- name: Windows
106-
if: runner.os == 'Windows'
79+
- name: Build
10780
run: |
10881
./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }}
109-
./PCbuild/rt.bat ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
110-
111-
- name: macOS
112-
if: runner.os == 'macOS'
82+
- name: Test
11383
run: |
114-
brew update
115-
brew install llvm@${{ matrix.llvm }}
116-
export SDKROOT="$(xcrun --show-sdk-path)"
117-
# Set MACOSX_DEPLOYMENT_TARGET and -Werror=unguarded-availability to
118-
# make sure we don't break downstream distributors (like uv):
119-
export CFLAGS_JIT='-Werror=unguarded-availability'
120-
export MACOSX_DEPLOYMENT_TARGET=10.15
121-
./configure --enable-experimental-jit --enable-universalsdk --with-universal-archs=universal2 ${{ matrix.debug && '--with-pydebug' || '' }}
122-
make all --jobs 4
123-
./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
84+
./PCbuild/rt.bat ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
12485
125-
- name: Linux
126-
if: runner.os == 'Linux'
127-
run: |
128-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
129-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
130-
./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '' }}
131-
make all --jobs 4
132-
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
86+
macos:
87+
name: ${{ matrix.target }} (${{ matrix.debug && 'Debug' || 'Release' }})
13388

134-
jit-with-disabled-gil:
135-
name: Free-Threaded (Debug)
136-
needs: interpreter
137-
runs-on: ubuntu-24.04
138-
timeout-minutes: 90
89+
runs-on: ${{ matrix.runner }}
90+
timeout-minutes: 60
13991
strategy:
14092
fail-fast: false
14193
matrix:
142-
llvm:
143-
- 21
94+
target:
95+
- x86_64-apple-darwin/clang
96+
- aarch64-apple-darwin/clang
97+
debug:
98+
- true
99+
- false
100+
include:
101+
- target: x86_64-apple-darwin/clang
102+
runner: macos-15-intel
103+
- target: aarch64-apple-darwin/clang
104+
runner: macos-14
144105
steps:
145106
- uses: actions/checkout@v6
146107
with:
147108
persist-credentials: false
148109
- uses: actions/setup-python@v6
149110
with:
150111
python-version: '3.11'
151-
- name: Build with JIT enabled and GIL disabled
112+
- name: Install LLVM
113+
run: |
114+
brew update
115+
brew install llvm@${{ env.LLVM_VERSION }}
116+
- name: Build
152117
run: |
153-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
154-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
155-
./configure --enable-experimental-jit --with-pydebug --disable-gil
118+
export SDKROOT="$(xcrun --show-sdk-path)"
119+
# Set MACOSX_DEPLOYMENT_TARGET and -Werror=unguarded-availability to
120+
# make sure we don't break downstream distributors (like uv):
121+
export CFLAGS_JIT='-Werror=unguarded-availability'
122+
export MACOSX_DEPLOYMENT_TARGET=10.15
123+
./configure --enable-experimental-jit --enable-universalsdk --with-universal-archs=universal2 ${{ matrix.debug && '--with-pydebug' || '' }}
156124
make all --jobs 4
157-
- name: Run tests
125+
- name: Test
158126
run: |
159-
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
160-
continue-on-error: true
127+
./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
161128
162-
no-opt-jit:
163-
name: JIT without optimizations (Debug)
164-
needs: interpreter
165-
runs-on: ubuntu-24.04
166-
timeout-minutes: 90
129+
linux:
130+
name: ${{ matrix.target }} (${{ matrix.debug && 'Debug' || 'Release' }})
131+
132+
runs-on: ${{ matrix.runner }}
133+
timeout-minutes: 60
167134
strategy:
168135
fail-fast: false
169136
matrix:
170-
llvm:
171-
- 21
137+
target:
138+
- x86_64-unknown-linux-gnu/gcc
139+
- aarch64-unknown-linux-gnu/gcc
140+
debug:
141+
- true
142+
- false
143+
include:
144+
- target: x86_64-unknown-linux-gnu/gcc
145+
runner: ubuntu-24.04
146+
- target: aarch64-unknown-linux-gnu/gcc
147+
runner: ubuntu-24.04-arm
172148
steps:
173149
- uses: actions/checkout@v6
174150
with:
175151
persist-credentials: false
176152
- uses: actions/setup-python@v6
177153
with:
178154
python-version: '3.11'
179-
- name: Build with JIT
155+
- name: Build
180156
run: |
181-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
182-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
183-
./configure --enable-experimental-jit --with-pydebug
157+
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ env.LLVM_VERSION }}
158+
export PATH="$(llvm-config-${{ env.LLVM_VERSION }} --bindir):$PATH"
159+
./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '' }}
184160
make all --jobs 4
185-
- name: Run tests without optimizations
161+
- name: Test
186162
run: |
187-
PYTHON_UOPS_OPTIMIZE=0 ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
163+
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
164+
165+
linux-extras:
166+
name: ${{ matrix.name }}
188167

189-
tail-call-jit:
190-
name: JIT with tail calling interpreter
191-
needs: interpreter
192168
runs-on: ubuntu-24.04
193-
timeout-minutes: 90
169+
timeout-minutes: 60
194170
strategy:
195171
fail-fast: false
196172
matrix:
197-
llvm:
198-
- 21
173+
include:
174+
- name: Free-Threaded (Debug)
175+
configure_flags: --enable-experimental-jit --with-pydebug --disable-gil
176+
continue_on_error: true
177+
- name: JIT without optimizations (Debug)
178+
configure_flags: --enable-experimental-jit --with-pydebug
179+
test_env: "PYTHON_UOPS_OPTIMIZE=0"
180+
- name: JIT with tail calling interpreter
181+
configure_flags: --enable-experimental-jit --with-tail-call-interp --with-pydebug
182+
use_clang: true
183+
run_tests: false
199184
steps:
200185
- uses: actions/checkout@v6
201186
with:
202187
persist-credentials: false
203188
- uses: actions/setup-python@v6
204189
with:
205190
python-version: '3.11'
206-
- name: Build with JIT and tailcall
191+
- name: Build
207192
run: |
208-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
209-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
210-
CC=clang-${{ matrix.llvm }} ./configure --enable-experimental-jit --with-tail-call-interp --with-pydebug
193+
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ env.LLVM_VERSION }}
194+
export PATH="$(llvm-config-${{ env.LLVM_VERSION }} --bindir):$PATH"
195+
if [ "${{ matrix.use_clang }}" = "true" ]; then
196+
export CC=clang-${{ env.LLVM_VERSION }}
197+
fi
198+
./configure ${{ matrix.configure_flags }}
211199
make all --jobs 4
200+
- name: Test
201+
if: matrix.run_tests != false
202+
run: |
203+
${{ matrix.test_env }} ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
204+
continue-on-error: ${{ matrix.continue_on_error }}

Lib/test/test_capi/test_opt.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,6 +4065,55 @@ def hot_loop():
40654065
self.assertNotIn('_PyJit_TryInitializeTracing', stderr,
40664066
f"JIT tracer memory leak detected:\n{stderr}")
40674067

4068+
def test_cold_exit_on_init_cleanup_frame(self):
4069+
4070+
result = script_helper.run_python_until_end('-c', textwrap.dedent("""
4071+
class A:
4072+
__slots__ = ('x', 'y', 'z', 'w')
4073+
def __init__(self):
4074+
self.x = self.y = -1
4075+
self.z = self.w = None
4076+
4077+
class B(A):
4078+
__slots__ = ('a', 'b', 'c', 'd', 'e')
4079+
def __init__(self):
4080+
super().__init__()
4081+
self.a = self.b = None
4082+
self.c = ""
4083+
self.d = self.e = False
4084+
4085+
class C(B):
4086+
__slots__ = ('name', 'flag')
4087+
def __init__(self, name):
4088+
super().__init__()
4089+
self.name = name
4090+
self.flag = False
4091+
4092+
funcs = []
4093+
for n in range(20, 80):
4094+
lines = [f"def f{n}(names, info):"]
4095+
for j in range(n):
4096+
lines.append(f" v{j} = names[{j % 3}]")
4097+
if j % 3 == 0:
4098+
lines.append(f" if v{j} in info:")
4099+
lines.append(f" v{j} = info[v{j}]")
4100+
elif j % 5 == 0:
4101+
lines.append(f" v{j} = len(v{j}) if isinstance(v{j}, str) else 0")
4102+
lines.append(" return C(names[0])")
4103+
ns = {'C': C}
4104+
exec("\\n".join(lines), ns)
4105+
funcs.append(ns[f"f{n}"])
4106+
4107+
names = ['alpha', 'beta', 'gamma']
4108+
info = {'alpha': 'x', 'beta': 'y', 'gamma': 'z'}
4109+
4110+
for f in funcs:
4111+
for _ in range(10):
4112+
f(names, info)
4113+
"""), PYTHON_JIT="1", PYTHON_JIT_STRESS="1",
4114+
PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE="1")
4115+
self.assertEqual(result[0].rc, 0, result)
4116+
40684117
def global_identity(x):
40694118
return x
40704119

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix JIT optimizer assertion failure during ``CALL_ALLOC_AND_ENTER_INIT`` side exit.

Python/optimizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ _PyJit_TryInitializeTracing(
995995
return 0;
996996
}
997997
PyObject *func = PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
998-
if (func == NULL) {
998+
if (func == NULL || !PyFunction_Check(func)) {
999999
return 0;
10001000
}
10011001
PyCodeObject *code = _PyFrame_GetCode(frame);

0 commit comments

Comments
 (0)