-
Notifications
You must be signed in to change notification settings - Fork 190
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
Conversation
…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.
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. |
There was a problem hiding this 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.
Merged with stacked PR. |
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.