GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Constant evaluate/propagate pure ops automatically · Issue #132732 · python/cpython

Constant evaluate/propagate pure ops automatically #132732

New issue
Copy link
New issue
Copy link
Closed
Closed
Constant evaluate/propagate pure ops automatically#132732
Copy link
Assignees
Fidget-Spinner
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancementA feature request or enhancement

Description

@Fidget-Spinner
Fidget-Spinner
opened on Apr 19, 2025
Issue body actions

Feature or enhancement

Proposal:

@brandtbucher pointed out that we could automatically evaluate pure ops in the JIT.

Back when I originally envisioned this in the JIT optimizer, it was way simpler. Right now we have stackrefs which complicate things a little.

The main idea is that fully pure bytecodes can just run their body in the JIT optimizer, allowing for automatic constant prop/evaluation. This also cuts down code duplication and also the amount of human error from manually writing constant propagation code.

We'd have to replace all the stackref functions with the appropriate sym accessing functions, either through macros or the cases generator.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-132732: Automatically constant evaluate pure operations #132733
  • gh-132732: Treat bytes as constants in _Py_uop_sym_is_safe_const #136033
  • gh-132732: JIT: Only allow compact ints in pure evaluation #136040
  • gh-132732: Clear errors in JIT optimizer on error #136048
  • gh-132732: Fix up pure types in JIT #136050
  • GH-132732: Use pure op machinery to optimize COMPARE_OP_INT/FLOAT/STR #137062
  • GH-132732: Use pure op machinery to optimize various instructions with _POP_TOP and _POP_TWO  #137577
  • GH-132732: Remove textwrap import #138933

Activity

Next
  1. Fidget-Spinner
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-JIT
    on Apr 19, 2025
  2. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Apr 19, 2025
  3. brandtbucher commented on Apr 24, 2025

    @brandtbucher
    brandtbucher
    on Apr 24, 2025
    Member
    More actions

    Two follow-ups to this:

    • pure_guard, which evaluates guards in the optimizer and removes the op if it doesn't deopt.
    • Wholesale replacing of pure instructions with _POP_TOP_*_LOAD_CONST_INLINE_BORROW or whatever if the result is immortal.
    • Replacing all constant outputs like above, even if they're not immortal (requires executors to hold references to this new constant pool).
  4. Fidget-Spinner
    added a commit that references this issue on Jun 27, 2025

    gh-132732: Automatically constant evaluate pure operations (GH-132733)

    695ab61
  5. sobolevn
    added a commit that references this issue on Jun 27, 2025

    pythongh-132732: Treat `bytes` as constants in `_Py_uop_sym_is_safe_c…

    1dce1aa
  6. Fidget-Spinner
    added a commit that references this issue on Jun 27, 2025

    gh-132732: JIT: Only allow compact ints in pure evaluation (GH-136040)

    c419af9
  7. brandtbucher commented on Jun 27, 2025

    @brandtbucher
    brandtbucher
    on Jun 27, 2025
    Member
    More actions

    Just talked with @savannahostrowski, she's going to modify the cases generator to replace the entire instruction when constant evaluation produces an immortal value.

    Reacted by Ken Jin
  8. brandtbucher
    assigned
    savannahostrowski
    on Jun 27, 2025
  9. Fidget-Spinner
    added a commit that references this issue on Jun 28, 2025

    gh-132732: Fix up pure types in JIT (GH-136050)

    ff7b5d4
  10. AndPuQing
    added 3 commits that reference this issue on Jul 11, 2025

    pythongh-132732: Automatically constant evaluate pure operations (pyt…

    a6a656f

    pythongh-132732: JIT: Only allow compact ints in pure evaluation (pyt…

    ce55d2c

    pythongh-132732: Fix up pure types in JIT (pythonGH-136050)

    f8c108c
  11. Pranjal095
    added 2 commits that reference this issue on Jul 12, 2025

    pythongh-132732: Automatically constant evaluate pure operations (pyt…

    836d9fa

    pythongh-132732: JIT: Only allow compact ints in pure evaluation (pyt…

    1b2d0d9
  12. 4 remaining items

  13. taegyunkim
    added a commit that references this issue on Aug 4, 2025

    pythongh-132732: Fix up pure types in JIT (pythonGH-136050)

    16ec67d
  14. Agent-Hellboy
    added 4 commits that reference this issue on Aug 19, 2025

    pythongh-132732: Automatically constant evaluate pure operations (pyt…

    73ffe50

    pythongh-132732: JIT: Only allow compact ints in pure evaluation (pyt…

    ca91acb

    pythongh-132732: Fix up pure types in JIT (pythonGH-136050)

    6869d45

    pythonGH-132732: Use pure op machinery to optimize `COMPARE_OP_INT/FL…

    be20104
  15. savannahostrowski
    added a commit that references this issue on Sep 15, 2025

    GH-132732: Use pure op machinery to optimize various instructions wit…

    9c9a0f7
  16. savannahostrowski commented on Sep 15, 2025

    @savannahostrowski
    savannahostrowski
    on Sep 15, 2025
    Member
    More actions

    @Fidget-Spinner @brandtbucher Are we good to close this out after #137577 or is there more I should work on here? 😈

  17. Fidget-Spinner commented on Sep 15, 2025

    @Fidget-Spinner
    Fidget-Spinner
    on Sep 15, 2025
    MemberAuthor
    More actions

    @savannahostrowski we still have this left #136048 . The problem is with these constant propagation, the optimizer can now error, and we need to handle that properly.

  18. savannahostrowski
    added a commit that references this issue on Sep 15, 2025

    GH-132732: Remove textwrap import (#138933)

    fa12c6b
  19. savannahostrowski
    assigned
    Fidget-Spinner
    and unassigned
    savannahostrowski
    on Sep 15, 2025
  20. savannahostrowski commented on Sep 15, 2025

    @savannahostrowski
    savannahostrowski
    on Sep 15, 2025
    Member
    More actions

    Ah! I missed that. I'll reassign this issue to you, and you can close it out when that lands.

  21. Fidget-Spinner
    added a commit that references this issue on Sep 15, 2025

    gh-132732: Clear errors in JIT optimizer on error (GH-136048)

    46f823b
  22. Fidget-Spinner commented on Sep 15, 2025

    @Fidget-Spinner
    Fidget-Spinner
    on Sep 15, 2025
    MemberAuthor
    More actions

    This is done! Thanks Savannah!

    Reacted by Savannah Ostrowski
  23. Fidget-Spinner
    closed this as completedon Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Fidget-Spinner
    Fidget-Spinner

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.