- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
gh-128563: A new tail-calling interpreter #128718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
      
        
          +3,883
        
        
          −623
        
        
          
        
      
    
  
  
     Merged
                    Changes from 61 commits
      Commits
    
    
            Show all changes
          
          
            127 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      2443f21
              
                Add new configure.ac option --enable-tail-call-interp
              
              
                Fidget-Spinner fb72fcd
              
                sorta working
              
              
                Fidget-Spinner c120a98
              
                fix release builds
              
              
                Fidget-Spinner 6f753da
              
                split out cold error parts
              
              
                Fidget-Spinner 4db1853
              
                fix on release builds
              
              
                Fidget-Spinner 3bab1b7
              
                Garret gets credit for the idea of splitting exits
              
              
                Fidget-Spinner e545c55
              
                fix jit build
              
              
                Fidget-Spinner 166aab0
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 465467f
              
                force on
              
              
                Fidget-Spinner 52b7ece
              
                ignore out entire interp loop
              
              
                Fidget-Spinner b9bedb1
              
                Apply changes from Garret's branch
              
              
                Fidget-Spinner f1d3190
              
                Revert "Apply changes from Garret's branch"
              
              
                Fidget-Spinner 6132746
              
                Autoconf detection
              
              
                Fidget-Spinner 16db128
              
                cleanup
              
              
                Fidget-Spinner fc91ac8
              
                cleanup macros
              
              
                Fidget-Spinner 982c51d
              
                Make deopt more efficient
              
              
                Fidget-Spinner 9820340
              
                Cleanup
              
              
                Fidget-Spinner 5862338
              
                more cleanup
              
              
                Fidget-Spinner f5b1c93
              
                Generate everything
              
              
                Fidget-Spinner 637589e
              
                Revert "Make deopt more efficient"
              
              
                Fidget-Spinner 5615d6f
              
                Add unknown opcode handlers
              
              
                Fidget-Spinner 71eba58
              
                cleanup
              
              
                Fidget-Spinner e1d5f41
              
                Add to makefile
              
              
                Fidget-Spinner b577888
              
                fix debug
              
              
                Fidget-Spinner ac80cdd
              
                Fix up generation
              
              
                Fidget-Spinner 6ae3e03
              
                fix instrumented instructions partially
              
              
                Fidget-Spinner a27ee2d
              
                Fix instrumentation completely
              
              
                Fidget-Spinner 56c6349
              
                Fix tests, move entry_frame into frame
              
              
                Fidget-Spinner 34dd801
              
                Block tier2
              
              
                Fidget-Spinner aa67427
              
                Add tests in cases generator
              
              
                Fidget-Spinner 54cff79
              
                Leave assert in
              
              
                Fidget-Spinner 22bdf7d
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 75361d4
              
                Upstream changes
              
              
                Fidget-Spinner d93bdaa
              
                📜🤖 Added by blurb_it.
              
              
                blurb-it[bot] a68d891
              
                fix mypy
              
              
                Fidget-Spinner 1310b47
              
                Fix lint
              
              
                Fidget-Spinner 8a2423d
              
                Merge branch 'tail-call' of github.com:Fidget-Spinner/cpython into ta…
              
              
                Fidget-Spinner db110ff
              
                Fix builds, address review
              
              
                Fidget-Spinner e0d9e6c
              
                Update tail-call.yml
              
              
                Fidget-Spinner 5aec067
              
                fix name
              
              
                Fidget-Spinner 6f7934b
              
                Simplify
              
              
                Fidget-Spinner 142e56e
              
                Address review
              
              
                Fidget-Spinner 5bc7d14
              
                Address review again
              
              
                Fidget-Spinner 195ee87
              
                Address review
              
              
                Fidget-Spinner 9df3e75
              
                Update 2025-01-10-18-56-20.gh-issue-128563.baDvls.rst
              
              
                Fidget-Spinner 2b4851e
              
                fix configure auto detection
              
              
                Fidget-Spinner 1ae8fc0
              
                fix workflow
              
              
                Fidget-Spinner c58f285
              
                Test on macOS as well
              
              
                Fidget-Spinner dfa2af7
              
                Specify clang-19
              
              
                Fidget-Spinner 1fc4df5
              
                Try fix Apple
              
              
                Fidget-Spinner dec29ed
              
                add to PATH
              
              
                Fidget-Spinner 8d29895
              
                Fix on x86_64 Apple
              
              
                Fidget-Spinner b1ae570
              
                missing "
              
              
                Fidget-Spinner 7a95b7e
              
                allow computed gotos with tail calls
              
              
                Fidget-Spinner d26ef11
              
                add ceval.c to list of paths
              
              
                Fidget-Spinner 70db5e9
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner eac485f
              
                Fix upstream, fix warnings
              
              
                Fidget-Spinner 910bd88
              
                cleanup
              
              
                Fidget-Spinner c1a6652
              
                Partial GCC 15.0 support
              
              
                Fidget-Spinner e198894
              
                Fix test
              
              
                Fidget-Spinner 29b6237
              
                Fix JIT builds
              
              
                Fidget-Spinner 92411f0
              
                fix typo
              
              
                Fidget-Spinner 501f645
              
                half the runners
              
              
                Fidget-Spinner 7d33768
              
                Update tail-call.yml
              
              
                Fidget-Spinner 2a860a2
              
                remove unused macro
              
              
                Fidget-Spinner a5e7c2a
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner df5d01c
              
                catch up with main
              
              
                Fidget-Spinner 1b6f969
              
                Address Hugo's review
              
              
                Fidget-Spinner e13aab9
              
                Update 2025-01-10-18-56-20.gh-issue-128563.baDvls.rst
              
              
                Fidget-Spinner 60d0d9b
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 297f5b9
              
                Update generated_tail_call_handlers.c.h
              
              
                Fidget-Spinner e4f2147
              
                Make deopts significantly more efficient
              
              
                Fidget-Spinner aa3d408
              
                reduce diff
              
              
                Fidget-Spinner 8f1f0b9
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 82ed698
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner aa1a5f6
              
                Update generated_tail_call_handlers.c.h
              
              
                Fidget-Spinner fda19f4
              
                partial fix (waiting for #129112 )
              
              
                Fidget-Spinner 1a21607
              
                Make it opt-in
              
              
                Fidget-Spinner 15da9c7
              
                Squashed commit of the following:
              
              
                Fidget-Spinner 665c0f6
              
                Catch up with labels-as-dsl branch
              
              
                Fidget-Spinner 09065ee
              
                refactor
              
              
                Fidget-Spinner 08ce01a
              
                Address review
              
              
                Fidget-Spinner e7b791b
              
                fix test
              
              
                Fidget-Spinner f9fff87
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 7ea7ddc
              
                Update generated_tail_call_handlers.c.h
              
              
                Fidget-Spinner 627fb59
              
                Address review by Hugo
              
              
                Fidget-Spinner 368f60e
              
                Make mypy happy
              
              
                Fidget-Spinner 68cd6e5
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner b7f5faf
              
                Update generated_tail_call_handlers.c.h
              
              
                Fidget-Spinner 720a1d0
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 9f90bfe
              
                Update 2025-01-10-18-56-20.gh-issue-128563.baDvls.rst
              
              
                Fidget-Spinner db5114b
              
                Cleanup
              
              
                Fidget-Spinner 98a5070
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 5b79a66
              
                Update generated_tail_call_handlers.c.h
              
              
                Fidget-Spinner 7e1b8a5
              
                Address review partially
              
              
                Fidget-Spinner 21dfba0
              
                Fix tests
              
              
                Fidget-Spinner 158a4c4
              
                Cleanup
              
              
                Fidget-Spinner 1463132
              
                Apply review suggestions on type checking
              
              
                Fidget-Spinner f906c97
              
                Add start_frame label
              
              
                Fidget-Spinner 7fe53d8
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner fb1cc3f
              
                Rename tail_call_shim to tail_call_entry
              
              
                Fidget-Spinner 1dda505
              
                cleanup
              
              
                Fidget-Spinner c33f277
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 24df49f
              
                Merge upstream changes, remove complicated hack
              
              
                Fidget-Spinner bd97afa
              
                fixup
              
              
                Fidget-Spinner c6967c6
              
                add to generated
              
              
                Fidget-Spinner 587a433
              
                remove dual definition
              
              
                Fidget-Spinner a01caf1
              
                Fix
              
              
                Fidget-Spinner 2694800
              
                Remove unused code
              
              
                Fidget-Spinner 62a1a4f
              
                Add tests
              
              
                Fidget-Spinner da2b792
              
                fix configure description
              
              
                Fidget-Spinner f118729
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 85d5fc3
              
                regen changes from upstream
              
              
                Fidget-Spinner cf18981
              
                Remove opcode
              
              
                Fidget-Spinner 1be3e2a
              
                Merge the two interpreters into one
              
              
                Fidget-Spinner c65688d
              
                LINT
              
              
                Fidget-Spinner 22ea2e5
              
                Simplify
              
              
                Fidget-Spinner ddbddc1
              
                lint
              
              
                Fidget-Spinner 52fa072
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner 0190825
              
                Fix bugs from upstream
              
              
                Fidget-Spinner bbea58f
              
                Update optimizer_generator.py
              
              
                Fidget-Spinner 98e5e68
              
                Update ceval_macros.h
              
              
                Fidget-Spinner 45161c0
              
                Address review
              
              
                Fidget-Spinner 8dab8c1
              
                Merge remote-tracking branch 'upstream/main' into tail-call
              
              
                Fidget-Spinner d3f3b97
              
                Update tier1_generator.py
              
              
                Fidget-Spinner bac68a3
              
                Fix generated cases
              
              
                Fidget-Spinner 61d9247
              
                Fix non-computed-gotos
              
              
                Fidget-Spinner File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| name: Tail calling interpreter | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'Python/bytecodes.c' | ||
| - 'Python/ceval.c' | ||
| - 'Python/ceval_macros.h' | ||
| - 'Python/generated_tail_call_handlers.c.h' | ||
| push: | ||
| paths: | ||
| - 'Python/bytecodes.c' | ||
| - 'Python/ceval.c' | ||
| - 'Python/ceval_macros.h' | ||
| - 'Python/generated_tail_call_handlers.c.h' | ||
| workflow_dispatch: | ||
|  | ||
| permissions: | ||
| contents: read | ||
|  | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|  | ||
| jobs: | ||
| jit: | ||
| name: ${{ matrix.target }} (${{ matrix.debug && 'Debug' || 'Release' }}) | ||
| runs-on: ${{ matrix.runner }} | ||
| timeout-minutes: 90 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: | ||
| # Un-comment as we add support for more platforms for tail-calling interpreters. | ||
| # - i686-pc-windows-msvc/msvc | ||
| # - x86_64-pc-windows-msvc/msvc | ||
| # - aarch64-pc-windows-msvc/msvc | ||
| - x86_64-apple-darwin/clang | ||
| - aarch64-apple-darwin/clang | ||
| - x86_64-unknown-linux-gnu/gcc | ||
| - aarch64-unknown-linux-gnu/gcc | ||
| debug: | ||
| - true | ||
| - false | ||
| llvm: | ||
| - 19 | ||
| include: | ||
| # - target: i686-pc-windows-msvc/msvc | ||
| # architecture: Win32 | ||
| # runner: windows-latest | ||
| # - target: x86_64-pc-windows-msvc/msvc | ||
| # architecture: x64 | ||
| # runner: windows-latest | ||
| # - target: aarch64-pc-windows-msvc/msvc | ||
| # architecture: ARM64 | ||
| # runner: windows-latest | ||
| - target: x86_64-apple-darwin/clang | ||
| architecture: x86_64 | ||
| runner: macos-13 | ||
| - target: aarch64-apple-darwin/clang | ||
| architecture: aarch64 | ||
| runner: macos-14 | ||
| - target: x86_64-unknown-linux-gnu/gcc | ||
| architecture: x86_64 | ||
| runner: ubuntu-24.04 | ||
| - target: aarch64-unknown-linux-gnu/gcc | ||
| architecture: aarch64 | ||
| # Forks don't have access to our paid AArch64 runners. These jobs are skipped below: | ||
| runner: ${{ github.repository_owner == 'python' && 'ubuntu-24.04-aarch64' || 'ubuntu-24.04' }} | ||
|         
                  Fidget-Spinner marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|  | ||
| - name: Native Windows | ||
| if: runner.os == 'Windows' && matrix.architecture != 'ARM64' | ||
| run: | | ||
| choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0 | ||
| ./PCbuild/build.bat --tail-call-interp ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} | ||
| ./PCbuild/rt.bat ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3 | ||
|  | ||
| # No tests (yet): | ||
| - name: Emulated Windows | ||
| if: runner.os == 'Windows' && matrix.architecture == 'ARM64' | ||
| run: | | ||
| choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0 | ||
| ./PCbuild/build.bat --tail-call-interp ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} | ||
|  | ||
| # The `find` line is required as a result of https://github.com/actions/runner-images/issues/9966. | ||
| # This is a bug in the macOS runner image where the pre-installed Python is installed in the same | ||
| # directory as the Homebrew Python, which causes the build to fail for macos-13. This line removes | ||
| # the symlink to the pre-installed Python so that the Homebrew Python is used instead. | ||
| - name: Native macOS | ||
| if: runner.os == 'macOS' | ||
| run: | | ||
| brew update | ||
| find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete | ||
| brew install llvm@${{ matrix.llvm }} | ||
| export SDKROOT="$(xcrun --show-sdk-path)" | ||
| export PATH="/opt/homebrew/opt/llvm/bin:$PATH" | ||
| export PATH="/usr/local/opt/llvm/bin:$PATH" | ||
| CC=clang-19 ./configure --with-tail-call-interp ${{ matrix.debug && '--with-pydebug' || '' }} | ||
| make all --jobs 4 | ||
| ./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3 | ||
|  | ||
| - name: Native Linux | ||
| # Forks don't have access to our paid AArch64 runners. Skip those: | ||
| if: runner.os == 'Linux' && (matrix.architecture == 'x86_64' || github.repository_owner == 'python') | ||
|         
                  Fidget-Spinner marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| run: | | ||
| sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} | ||
| export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH" | ||
| CC=clang-19 ./configure --with-tail-call-interp ${{ matrix.debug && '--with-pydebug' || '' }} | ||
| make all --jobs 4 | ||
| ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3 | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            1 change: 1 addition & 0 deletions
          
          1 
        
  Misc/NEWS.d/next/Core_and_Builtins/2025-01-10-18-56-20.gh-issue-128563.baDvls.rst
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| A new type of interpreter has been added to CPython. This interpreter uses tail calls for its instruction handlers. Preliminary benchmark results suggest 7-14% geometric mean faster on pyperformance (depending on platform), and up to 45% faster on Python-intensive workloads. This interpreter currently only works on newer compilers, such as ``clang-19``. Other compilers will continue using the old interpreter. Patch by Ken Jin, with ideas by Garret Gu, Haoran Xu, and Josh Haberman. | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.