-
Notifications
You must be signed in to change notification settings - Fork 217
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
Clean up temporary workarounds from templated code #2102
Conversation
Generate the c/h code for constant definitions and object initialization. We make sure the Rake task builds the required templates so we can compile the extension. Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Ultimately we want to separate the pure C implementation files (under `src/` and `include/`) from the Ruby extension files (under `ext/rbs_extension`). This change allow us to build the Ruby extension using files outside of the `ext/rbs_extension` directory. Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
We picked a longer named that’s prefixed with `_`, so it’s less likely to collide with any templated fields names (which end up as parameters to these functions).
This commit removes the `c_name` special cases from our templated code. Instead, we rename the C identifiers to always match their Ruby counterparts (which are the ones that matter, since they get exposed as keyword argument labels on the class’ constructors).
<%- node.fields.each do |field| -%> | ||
rb_hash_aset(<%= hash_var %>, ID2SYM(rb_intern("<%= field.name %>")), <%= field.c_name %>); | ||
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("<%= field.name %>")), <%= field.name %>); |
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.
We picked _init_kwargs
instead of a name like kwargs
, args
, etc. to make it less likely that it collides with the name of a parameter to this function.
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.
Thanks! Looks great. 👍
This PR is a follow-up built on top of #2098. It doesn't change any of its behaviour, but just removes the temporary workarounds that we used to minimize the diff of #2098.
Only the last 4 commits are new to this PR, the rest just come from #2098.
This PR is best reviewed commit-by-commit.