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

Factor out expression codegen from function codegen #155

Merged
merged 18 commits into from
Dec 10, 2022

Conversation

ZibingZhang
Copy link
Contributor

@ZibingZhang ZibingZhang commented Dec 8, 2022

This PR does not add / remove any functionality, nor does it add / remove any tests. It's purely a refactor.

Overview

Split function_codegen into two files like so:

  • function_codegen that implements visiting module and statements nodes, and delegates to expression_codegen for expression nodes.
  • expression_codegen that implements visiting expression nodes (as well as ast.comprehension.

Considerations

How should we test function_codegen comprehensively? All tests that expression_codegen have will apply to function_codegen, at least for the time being.

References

Initial idea: #57 (comment)
Factor this change out of algorithmic codegen PR: #152 (comment)

Blocked by

None

@ZibingZhang ZibingZhang requested a review from odashi as a code owner December 8, 2022 12:05
Copy link
Collaborator

@odashi odashi left a comment

Choose a reason for hiding this comment

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

Thanks, I guessed it is the good time to refactor some related things (as I commented) as well.

src/latexify/codegen/codegen_utils.py Show resolved Hide resolved
@@ -0,0 +1,704 @@
"""Codegen for single expressions."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about splitting other objects than ExpressionCodegen into other files too in this PR? Maybe definitions in constants.py should also be integrated as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure yeah! maybe a bulitin_functions.py? this would essentially just turn into a rename of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought maybe save other splitting for another PR?

This PR is getting very big, and trying to solve merge conflicts is mildly painful. Would like to merge this in ASAP and further refactors can come in subsequent PRs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's fine to prepare a separate PR for this refactoring.

Copy link
Collaborator

Choose a reason for hiding this comment

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

bulitin_functions.py looks confusing. I guess simply rules.py or something else would be good.

src/latexify/codegen/expression_codegen.py Outdated Show resolved Hide resolved
src/latexify/codegen/expression_codegen.py Outdated Show resolved Hide resolved
src/latexify/codegen/expression_codegen.py Outdated Show resolved Hide resolved
src/latexify/codegen/expression_codegen_test.py Outdated Show resolved Hide resolved
src/latexify/codegen/function_codegen.py Outdated Show resolved Hide resolved
@odashi odashi mentioned this pull request Dec 9, 2022
@ZibingZhang ZibingZhang requested review from odashi December 9, 2022 15:10
Copy link
Collaborator

@odashi odashi left a comment

Choose a reason for hiding this comment

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

Maybe it's almost fine. several comments:

src/latexify/analyzers_test.py Show resolved Hide resolved
src/latexify/analyzers.py Outdated Show resolved Hide resolved
src/latexify/analyzers_test.py Outdated Show resolved Hide resolved
"3 / 4",
],
)
def test_reduce_stop_parameter_not_binop_with_op_add_or_sub(code: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • I think we don't need to separate test cases into 2 parts.
  • Shrink this king of long test names, which are not convenient to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, going to bring test case into one method, which solves the issue of long name

src/latexify/codegen/codegen_utils_test.py Show resolved Hide resolved
@@ -0,0 +1,704 @@
"""Codegen for single expressions."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's fine to prepare a separate PR for this refactoring.

@@ -0,0 +1,704 @@
"""Codegen for single expressions."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

bulitin_functions.py looks confusing. I guess simply rules.py or something else would be good.

@odashi odashi merged commit 05383ca into google:main Dec 10, 2022
@LakeBlair
Copy link
Contributor

@ZibingZhang @odashi
Hey guys, I noticed that there is a refactoring to the existing codebase. I think the changes made through PR #148 were not included in this refactor. It should probably be included in visit_call() function located in expression_codegen.py. Can you look into it?

@ZibingZhang
Copy link
Contributor Author

Thanks for the catch, apologies for that mistake I made when resolving merge conflicts.

@odashi
Copy link
Collaborator

odashi commented Dec 10, 2022

Great, thanks both! (this kind of collision often happens when we applied large changes, so please never mind. but we should fix it ASAP)

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