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-93678: reduce boilerplate and code repetition in the compiler #93682

Merged
merged 18 commits into from Jun 14, 2022

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Jun 10, 2022

It might be easier to review the individual commits separately.

The code generation part of the compiler has several functions which are slight variations of each other. Part of this is due to the evolution of the code when accurate line number information was added.

This PR tidies this up to simplify the code. Having just one basicblock_addop function that knows how to handle all the HAS_ARG, !HAS_ARG and JUMP cases is a step towards being able to feed bytecode instruction sequences and turn them into basicblocks (without having to differentiate between the three types).

@iritkatriel iritkatriel requested a review from markshannon as a code owner Jun 10, 2022
@iritkatriel iritkatriel added the 🔨 test-with-buildbots label Jun 10, 2022
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jun 10, 2022

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit f8a0767 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots label Jun 10, 2022
@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jun 10, 2022

Sorry but I'm clueless when it comes to the compiler, so I can't give a review.

@Fidget-Spinner Fidget-Spinner removed their request for review Jun 10, 2022
Copy link
Member

@markshannon markshannon left a comment

Seems like a nice improvement in the architecture of the compiler.

Python/compile.c Outdated Show resolved Hide resolved
@iritkatriel iritkatriel added interpreter-core 🔨 test-with-buildbots labels Jun 10, 2022
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jun 10, 2022

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 7670a7c 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots label Jun 10, 2022
Copy link
Member

@brandtbucher brandtbucher left a comment

Thanks, this looks nice.

One thing I noticed is that the new design creates lots of temporary location structs (at least one for every instruction emitted by the frontend, I think). Could we instead keep just one struct on the compiler unit, and maybe have a static "no location" struct, and just pass references to those into basicblock_addop instead?

@iritkatriel
Copy link
Member Author

@iritkatriel iritkatriel commented Jun 10, 2022

Thanks, this looks nice.

One thing I noticed is that the new design creates lots of temporary location structs (at least one for every instruction emitted by the frontend, I think). Could we instead keep just one struct on the compiler unit, and maybe have a static "no location" struct, and just pass references to those into basicblock_addop instead?

Yeah I guess we could pass them by reference.

I'm now working on replacing the four fields by the struct in the instr and compiler unit structs, will push that in a bit.

Python/compile.c Outdated Show resolved Hide resolved
@iritkatriel iritkatriel changed the title GH-93678: reduce boilerplate and code repetition in compiler's code-gen stage GH-93678: reduce boilerplate and code repetition in the compiler Jun 10, 2022
@iritkatriel iritkatriel added the 🔨 test-with-buildbots label Jun 10, 2022
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jun 10, 2022

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 9b5dc34 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots label Jun 10, 2022
@iritkatriel iritkatriel added the 🔨 test-with-buildbots label Jun 13, 2022
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jun 13, 2022

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 414e26a 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots label Jun 13, 2022
Copy link
Member

@markshannon markshannon left a comment

Nice improvement in clarity.

Copy link
Member

@sweeneyde sweeneyde left a comment

100 lines shorter 🎉

Python/compile.c Outdated Show resolved Hide resolved
@iritkatriel iritkatriel merged commit af15cc5 into python:main Jun 14, 2022
13 checks passed
@iritkatriel iritkatriel deleted the codegen-reduce-repetition branch Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants