]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133171: Re-enable JUMP_BACKWARD to free-threading build (gh-137800)
authorDonghee Na <donghee.na@python.org>
Wed, 24 Sep 2025 05:19:17 +0000 (14:19 +0900)
committerGitHub <noreply@github.com>
Wed, 24 Sep 2025 05:19:17 +0000 (14:19 +0900)
.github/workflows/jit.yml
Include/internal/pycore_stackref.h
Python/bytecodes.c
Python/generated_cases.c.h
Python/optimizer.c
configure
configure.ac

index 52f7d0d2b3df95cdb552a1f2dc40ff7dd73f14b6..80e4ae603a2614cd450ff1bd0e0b19bb1543996d 100644 (file)
@@ -134,6 +134,34 @@ jobs:
           make all --jobs 4
           ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
 
+  jit-with-disabled-gil:
+    name: Free-Threaded (Debug)
+    needs: interpreter
+    runs-on: ubuntu-24.04
+    timeout-minutes: 90
+    strategy:
+      fail-fast: false
+      matrix:
+        llvm:
+          - 19
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          persist-credentials: false
+      - uses: actions/setup-python@v5
+        with:
+          python-version: '3.11'
+      - name: Build with JIT enabled and GIL disabled
+        run: |
+          sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
+          export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
+          ./configure --enable-experimental-jit --with-pydebug --disable-gil
+          make all --jobs 4
+      - name: Run tests
+        run: |
+          ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
+        continue-on-error: true
+
   no-opt-jit:
     name: JIT without optimizations (Debug)
     needs: interpreter
@@ -160,31 +188,3 @@ jobs:
       - name: Run tests without optimizations
         run: |
           PYTHON_UOPS_OPTIMIZE=0 ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
-
-  # XXX: GH-133171
-  # jit-with-disabled-gil:
-  #   name: Free-Threaded (Debug)
-  #   needs: interpreter
-  #   runs-on: ubuntu-24.04
-  #   timeout-minutes: 90
-  #   strategy:
-  #     fail-fast: false
-  #     matrix:
-  #       llvm:
-  #         - 19
-  #   steps:
-  #     - uses: actions/checkout@v4
-  #       with:
-  #         persist-credentials: false
-  #     - uses: actions/setup-python@v5
-  #       with:
-  #         python-version: '3.11'
-  #     - name: Build with JIT enabled and GIL disabled
-  #       run: |
-  #         sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
-  #         export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
-  #         ./configure --enable-experimental-jit --with-pydebug --disable-gil
-  #         make all --jobs 4
-  #     - name: Run tests
-  #       run: |
-  #         ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
index c4e8f10fe05276f844a357f423af8628db5cfec1..062834368bcd29cc43adb1c826262d703e45b0f0 100644 (file)
@@ -464,6 +464,12 @@ PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
     PyStackRef_CLOSE(ref);
 }
 
+static inline int
+PyStackRef_RefcountOnObject(_PyStackRef ref)
+{
+    return (ref.bits & Py_TAG_REFCNT) == 0;
+}
+
 static inline _PyStackRef
 PyStackRef_DUP(_PyStackRef stackref)
 {
index 9b993188fb73c753c305e8c8e96b31b0364e31cd..f9f14322df0a5e6c134ea3ac21ec613130e6fc41 100644 (file)
@@ -2940,9 +2940,10 @@ dummy_func(
         };
 
         tier1 op(_SPECIALIZE_JUMP_BACKWARD, (--)) {
-        #if ENABLE_SPECIALIZATION
+        #if ENABLE_SPECIALIZATION_FT
             if (this_instr->op.code == JUMP_BACKWARD) {
-                this_instr->op.code = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
+                uint8_t desired = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
+                FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, desired);
                 // Need to re-dispatch so the warmup counter isn't off by one:
                 next_instr = this_instr;
                 DISPATCH_SAME_OPARG();
index e33d15f2e51e1621ae6d3800bc67ba90c6111a13..79328a7b725613a88b3bd12796a762c81d80fb4f 100644 (file)
             /* Skip 1 cache entry */
             // _SPECIALIZE_JUMP_BACKWARD
             {
-                #if ENABLE_SPECIALIZATION
+                #if ENABLE_SPECIALIZATION_FT
                 if (this_instr->op.code == JUMP_BACKWARD) {
-                    this_instr->op.code = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
+                    uint8_t desired = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
+                    FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, desired);
                     next_instr = this_instr;
                     DISPATCH_SAME_OPARG();
                 }
index 53f1500f3989a4a6d0b2c3afead529dcea8d800e..7b76cddeabff44ef108f6b5ebaf479e4e788cd59 100644 (file)
@@ -119,6 +119,7 @@ _PyOptimizer_Optimize(
     PyInterpreterState *interp = _PyInterpreterState_GET();
     assert(interp->jit);
     assert(!interp->compiling);
+#ifndef Py_GIL_DISABLED
     interp->compiling = true;
     // The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must*
     // make progress in order to avoid infinite loops or excessively-long
@@ -160,6 +161,9 @@ _PyOptimizer_Optimize(
     assert((*executor_ptr)->vm_data.valid);
     interp->compiling = false;
     return 1;
+#else
+    return 0;
+#endif
 }
 
 static _PyExecutorObject *
index cd8f2f19c0b92cfabed7fa05463a93372c10ae0f..7624cbf0d2ae3d55af6185c2476f4f9fa98b093b 100755 (executable)
--- a/configure
+++ b/configure
@@ -10891,7 +10891,8 @@ printf "%s\n" "$tier2_flags $jit_flags" >&6; }
 if test "$disable_gil" = "yes" -a "$enable_experimental_jit" != "no"; then
   # GH-133171: This configuration builds the JIT but never actually uses it,
   # which is surprising (and strictly worse than not building it at all):
-  as_fn_error $? "--enable-experimental-jit cannot be used with --disable-gil." "$LINENO" 5
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: --enable-experimental-jit does not work correctly with --disable-gil." >&5
+printf "%s\n" "$as_me: WARNING: --enable-experimental-jit does not work correctly with --disable-gil." >&2;}
 fi
 
 case "$ac_cv_cc_name" in
index 8312dc55084333b44a71f00dbf63baa88a790735..7a7e32d42945b9fc27963c7806c266572155bb1d 100644 (file)
@@ -2799,7 +2799,7 @@ AC_MSG_RESULT([$tier2_flags $jit_flags])
 if test "$disable_gil" = "yes" -a "$enable_experimental_jit" != "no"; then
   # GH-133171: This configuration builds the JIT but never actually uses it,
   # which is surprising (and strictly worse than not building it at all):
-  AC_MSG_ERROR([--enable-experimental-jit cannot be used with --disable-gil.])
+  AC_MSG_WARN([--enable-experimental-jit does not work correctly with --disable-gil.])
 fi
 
 case "$ac_cv_cc_name" in