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

Codegen visitor functions #23

Closed
wants to merge 5 commits into from
Closed

Codegen visitor functions #23

wants to merge 5 commits into from

Conversation

DragonMinded
Copy link
Contributor

Summary

Implement codegen for visit_* and leave_* methods so that pyre can warn about incorrect overloads and incorrect types. This includes code which does the actual codegen, a test that verifies that the codegen isn't out of date with the LibCST repo, and a tox environment/helper script for performing the codegen in a roughly atomic manner.

Test Plan

tox, as well as creating scenarios that 1) caused codegen failure to verify that we do the right thing when failing to codegen and 2) make us need a codegen, thus triggering a test failure.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 13, 2019
@bgw bgw mentioned this pull request Aug 13, 2019
@DragonMinded DragonMinded requested a review from bgw August 14, 2019 00:42
libcst/codegen/gen_visitor_functions.py Outdated Show resolved Hide resolved
libcst/codegen/generate.py Show resolved Hide resolved
libcst/_typed_visitor.py Show resolved Hide resolved
Jennifer Taylor added 5 commits August 27, 2019 14:02
…sitor.

This allows Pyre to typecheck returns inside visitors for us.
We want to make sure that the generated function stubs stay in sync with
the node definitions. So, make a unit test that fails if codegen generates
a different file than the existing file, so that somebody modifying code
knows they need to re-run codegen.
Adds a BaseStatement type which can be used to specify in types that you can
accept either a compound statement or a simple statement line.
There are a lot of nodes that cannot be removed or converted to maybes, such as
most of the Op tokens. It would be a bit of a lie to codegen leave_* methods
that allow these nodes to be converted, only to throw a runtime error later. So,
upgrade the codegen to allow us to see whether certain nodes are used in conjunction
with a MaybeSentinel/None, or inside a Sequence, to inform ourselves as to when to
allow MaybeSentinel or RemovalSentinel.
@DragonMinded
Copy link
Contributor Author

I updated based on comments on PR #27 (a review of this code was mistakenly placed there) and added a bit more logic to generate better types. We have a BaseStatement now, and codegen can take into account the way nodes are used to correctly decide when to allow a MaybeSentinel or RemovalSentinel in a leave_* return. I don't think this is perfect, but if we run into cases that are wrong we can open up an issue and fix it. Having tighter types is more important IMO.

@DragonMinded DragonMinded requested review from jimmylai and removed request for bgw August 27, 2019 23:25
Copy link
Contributor

@jimmylai jimmylai left a comment

Choose a reason for hiding this comment

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

Other than the comments, LGTM.

@DragonMinded
Copy link
Contributor Author

Merged with stacked PR.

@DragonMinded DragonMinded deleted the codegen_visitor_nodes branch August 28, 2019 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants