Skip to content

Constant evaluate/propagate pure ops automatically #132732

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

Open
Fidget-Spinner opened this issue Apr 19, 2025 · 1 comment
Open

Constant evaluate/propagate pure ops automatically #132732

Fidget-Spinner opened this issue Apr 19, 2025 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT type-feature A feature request or enhancement

Comments

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Apr 19, 2025

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

@Fidget-Spinner Fidget-Spinner added the type-feature A feature request or enhancement label Apr 19, 2025
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 19, 2025
@brandtbucher
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants