Skip to content

gh-120619: Tier 2 partial evaluator foundations #124910

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

Closed
wants to merge 54 commits into from

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Oct 2, 2024

This PR sets up a tier 2 partial evaluation pass' foundations. It does the following:

  1. Introduce binding-time analysis of instructions and locals.
  2. Virtualized stack values (This was why we need a local slot now to indicate if the stack value is pointing to a virtualized instruction).
  3. A new abstract interpreter -- one for partial evaluation.
  4. Symbolic stack reification -- reconstructing the stack when we need to/hit a non-static instruction. This is done by telling the originating instruction to devirtualize itself.

As a litmus test, it does simple dead store elimination by tracking locals. For example, the code x = x is now optimized to a nop.

This is different than the previous PR at #123652. The main difference is that we create the residual in-place. By "looking backwards" at the originating instruction and marking that as virtual/non-virtual. If you want a visualization of how this will work. See Mark's talk at EuroPython 2023 here https://youtu.be/dgrtgtT-UXM?t=1198.

Also up for discussion: the generator for the partial evaluator is exactly the same as the specializer. Should I just remove it?

@Fidget-Spinner
Copy link
Member Author

@markshannon I split it out into its own files, and own symbols, so it doesn't share the type information too. This simplifies the lattice quite a bit.

@erlend-aasland erlend-aasland removed their request for review October 14, 2024 08:07
Comment on lines +306 to +308
if (length <= 0) {
return length;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (length <= 0) {
return length;
}

We'll anyway return length in line 310

@@ -0,0 +1,303 @@
"""Generate the cases for the tier 2 partial evaluator.
Reads the instruction definitions from bytecodes.c, optimizer_bytecodes.c and partial_evaluator_bytecodes.c
Writes the cases to partial_evaluator_cases.c.h, which is #included in Python/optimizer_analysis.c.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Writes the cases to partial_evaluator_cases.c.h, which is #included in Python/optimizer_analysis.c.
Writes the cases to partial_evaluator_cases.c.h, which is #included in Python/partial_evaluator.c.

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@Fidget-Spinner
Copy link
Member Author

I have a different approach in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants