Skip to content

gh-117680: make _PyInstructionSequence a PyObject and use it in tests #117629

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
merged 18 commits into from
Apr 17, 2024

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Apr 8, 2024

@iritkatriel iritkatriel requested a review from markshannon as a code owner April 8, 2024 09:23
@iritkatriel iritkatriel marked this pull request as draft April 8, 2024 09:23
@markshannon markshannon changed the title Make InsturctionSequence a PyObject. Simplify tests Make InstructionSequence a PyObject. Simplify tests Apr 8, 2024
@iritkatriel iritkatriel changed the title Make InstructionSequence a PyObject. Simplify tests gh-117680: make InstructionSequence a PyObject and use it in tests Apr 9, 2024
@iritkatriel iritkatriel changed the title gh-117680: make InstructionSequence a PyObject and use it in tests gh-117680: make _PyInstructionSequence a PyObject and use it in tests Apr 9, 2024
@iritkatriel iritkatriel marked this pull request as ready for review April 9, 2024 16:17
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.

Overall, this looks like a nice improvement, both in terms of separation of compiler passes and in debugability and introspection.

What is the purpose of the nested instruction sequences?
AFAICT they are only used in the tests.

Co-authored-by: Mark Shannon <[email protected]>
@iritkatriel
Copy link
Member Author

What is the purpose of the nested instruction sequences?

For tests, and also if you want to display (dis-like) the codegen output, then you need the nested instructions. Otherwise for a function you only get the top level function definition, not its body. And then again for nested functions.

@iritkatriel
Copy link
Member Author

iritkatriel commented Apr 17, 2024

What is the purpose of the nested instruction sequences?

For tests, and also if you want to display (dis-like) the codegen output, then you need the nested instructions. Otherwise for a function you only get the top level function definition, not its body. And then again for nested functions.

I have another PR coming where codegen populates the nested instruction sequences (optional - not happening in regular compilation).

@iritkatriel iritkatriel requested a review from markshannon April 17, 2024 11:22
@markshannon
Copy link
Member

For tests, and also if you want to display (dis-like) the codegen output, then you need the nested instructions.

I have another PR coming where codegen populates the nested instruction sequences (optional - not happening in regular compilation).

I'm a bit wary of tests that diverge from the things they are testing.

Would it make sense to create the nested sequences in the normal compiler and generated nested code objected directly from nested sequences in the assembler?

@iritkatriel
Copy link
Member Author

I'm a bit wary of tests that diverge from the things they are testing.

That's not what happens. The test is testing codegen output, and the test mode simply saves the nested sequences, whereas in normal compilation those sequences are discarded as soon as the codeobject is created. Nothing else is changing in test mode. The code objects are created in the same way.

Anyway, it's not in the PR so we can look at it in the next PR.

Would it make sense to create the nested sequences in the normal compiler and generated nested code objected directly from nested sequences in the assembler?

There are two issues with this. First, I am concerned it could consume more memory during normal compilation (for no benefit).

Second, the code object creation currently happens with a certain "compiler unit state". If we delay it to the end, the compiler unit is in a different state (or gone altogether). So we need to make sure we capture enough of this state for later. It's not a trivial change (and again, there doesn't seem to be any concrete benefit).

@iritkatriel iritkatriel merged commit c179c0e into python:main Apr 17, 2024
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants