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

Clean up temporary workarounds from templated code #2102

Merged
merged 7 commits into from
Nov 28, 2024

Conversation

amomchilov
Copy link
Contributor

@amomchilov amomchilov commented Nov 27, 2024

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.

amomchilov and others added 7 commits November 27, 2024 17:36
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 %>);
Copy link
Contributor Author

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.

@amomchilov amomchilov marked this pull request as ready for review November 27, 2024 23:06
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great. 👍

@soutaro soutaro added this pull request to the merge queue Nov 28, 2024
Merged via the queue into ruby:master with commit 6c77c6b Nov 28, 2024
18 checks passed
@amomchilov amomchilov mentioned this pull request Dec 6, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants