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-87092: move assembler related code from compile.c to assemble.c #103277

Merged
merged 10 commits into from
Apr 11, 2023

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Apr 5, 2023

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.

Seems reasonable from a fairly quick scan.

There is no change in capability or optimizations, this is just a refactor. Correct?

Python/compile.c Outdated
@@ -7389,13 +6802,17 @@ add_return_at_end(struct compiler *c, int addNone)
return SUCCESS;
}

static int cfg_to_instr_sequence(cfg_builder *g, instr_sequence *seq);

static PyCodeObject *
assemble_code_unit(struct compiler_unit *u, PyObject *const_cache,
Copy link
Member

Choose a reason for hiding this comment

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

Is this name still correct? Was it ever?

It seems to do optimization and assembly.

Copy link
Member Author

Choose a reason for hiding this comment

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

There used to be just assemble(C) which takes the compiler and and does all the optimization and assembly. I split out assemble_code_unit (which takes just the c->u and not the whole c) and does most of what used to be in assemble(). So the name was always incorrect (assemble() called the optimizer). I think the reason it was done like this is that assemble() gets called from a number of places in the compiler (lambda, class, module, etc). So it was convenient to have one function that does opt+assemble and returns a code object.

We can rename assemble() and assemble_code_unit(). Any suggestions what to call it? something like instr_sequence_to_code_object()?

@markshannon markshannon self-requested a review April 11, 2023 10:13
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