-
Notifications
You must be signed in to change notification settings - Fork 6
Add SignatureTranslatorPrism and TypeParamsToParserNodesPrism #815
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
base: ac-add_methodtypetoparsernodeprism_for_rbs_method_signature_translation
Are you sure you want to change the base?
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
376f9e6 to
3a61f26
Compare
8914ab9 to
77219b7
Compare
3a61f26 to
ebf3230
Compare
77219b7 to
005a338
Compare
| rbs_string_t rbsString = makeRBSString(assertion.string); | ||
| const rbs_encoding_t *encoding = RBS_ENCODING_UTF_8_ENTRY; | ||
|
|
||
| Parser parser(rbsString, encoding); |
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.
Uniform initialization
| Parser parser(rbsString, encoding); | |
| Parser parser{rbsString, encoding}; |
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.
Likewise for the cases below
| rbs_string_t rbsString = makeRBSString(declaration.string); | ||
| const rbs_encoding_t *encoding = RBS_ENCODING_UTF_8_ENTRY; | ||
|
|
||
| Parser parser(rbsString, encoding); |
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.
This repeats 5 times, can you extract a private helper?
| auto nameStr = parser.resolveConstant(rbsTypeParam->name); | ||
| auto nameConstant = ctx.state.enterNameConstant(nameStr); | ||
|
|
||
| vector<pm_node_t *> args; |
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.
This will only have 0 or 1 elements. We can skip this heap allocation if we use an inlined vector on the stack:
| vector<pm_node_t *> args; | |
| absl::InlinedVector<pm_node_t *, 1> args; |
| pm_node_t *block = nullptr; | ||
| if (defaultType || upperBound || lowerBound) { | ||
| auto typeTranslator = TypeToParserNodePrism(ctx, {}, parser, prismParser); | ||
| vector<pm_node_t *> pairs; |
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.
Similar
| vector<pm_node_t *> pairs; | |
| absl::InlinedVector<pm_node_t *, 3> pairs; |
|
|
||
| private: | ||
| core::MutableContext ctx; | ||
| parser::Prism::Parser *parser; // For Prism node creation |
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.
Unused?
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.
Passed to a few translators:
auto methodTypeToParserNodePrism = MethodTypeToParserNodePrism(ctx, move(parser), *this->parser);
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.
Those are different, there's Parser parser local variables that shadow this->parser
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.
So if I'm understanding correctly the 2nd arg in the line of code above is the local variable parser but the 3rd arg is the member variable? So it is being used? I can also rename all the local variables to rbsParser to avoid this confusion.
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.
Yeah, in the context where we have both, it would be more clear to give one or both of them prefixes. Relying on variable shadowing to draw the distinction is pretty non-obvious
005a338 to
4536485
Compare
284ba10 to
820e412
Compare
Co-authored-by: Kaan Ozkan <kaan.ozkan@shopify.com>
4536485 to
388f9ab
Compare
82b09ef to
58b03c9
Compare

Motivation
Test plan
See included automated tests.