Skip to content
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

gh-128563: Move labels in ceval.c to bytecodes.c #129112

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jan 21, 2025

@markshannon
Copy link
Member

markshannon commented Jan 21, 2025

I don't think adding another code generator is the way to go.
The code in labels is part of the interpreter, so they should be handled similarly to instructions.

For code in labels we will, in the future, want to:

  • Spill the stack around escaping calls
  • Use the same dispatching mechanism as for instructions
  • Potentially access stack variables without cumbersome explicit pops and pushes.

I'm not suggesting that we do any of the above in this PR. The simple code you generate is fine for now, but it needs to be a bit more closely integrated into the interpreter/JIT generators.

Since labels exist outside the dispatch loop, we'll need to generate the dispatch loop as well. We can simply copy the few lines of code surrounding #include "generated_cases.c.h" into the tier1 code generator.

The tier 1 code generator would then generate:

  • The dispatch preamble (from /* Start instructions */ onwards)
  • The cases
  • The dispatch loop end including EXTRA_CASES up to Py_UNREACHABLE();
  • All the labels

@Fidget-Spinner
Copy link
Member Author

Fidget-Spinner commented Jan 21, 2025

Alright. I've moved the labels generator back into the tier 1 generator. We need to port over tier 2 in a separate PR as well.

I've combined the switch-case generator into the cases generator as well.

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

Mostly looks good. One thing doesn't look right

Tools/cases_generator/tier1_generator.py Outdated Show resolved Hide resolved
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

Adding the markers to the generated code for testing looks good, but the parsing in the test is a bit cumbersome.

@@ -253,6 +253,23 @@ def run_cases_test(self, input: str, expected: str):
lines.pop(0)
while lines and lines[-1].startswith(("#", "\n")):
lines.pop(-1)
while lines and tier1_generator.INSTRUCTION_START_MARKER not in lines[0]:
Copy link
Member

Choose a reason for hiding this comment

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

You can replace this line by line processing, including the start and end comment stripping, by splitting the whole file on INSTRUCTION_START_MARKER and INSTRUCTION_START_MARKER, discarding the first and last parts.

text = temp_output.read()
_, rest = text.split(INSTRUCTION_START_MARKER)
actual, _ = rest.split(LABEL_START_MARKER)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good observation. Thanks!

@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Fidget-Spinner added a commit to Fidget-Spinner/cpython that referenced this pull request Jan 25, 2025
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.

2 participants