-
Notifications
You must be signed in to change notification settings - Fork 5.4k
YJIT: Allow calling iseq with mixed optional and keyword args and fix required kwarg check #5285
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
Merged
jhawthorn
merged 3 commits into
ruby:master
from
jhawthorn:gen_send_iseq_refactor_and_fix
Dec 17, 2021
Merged
YJIT: Allow calling iseq with mixed optional and keyword args and fix required kwarg check #5285
jhawthorn
merged 3 commits into
ruby:master
from
jhawthorn:gen_send_iseq_refactor_and_fix
Dec 17, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kddnewton
approved these changes
Dec 17, 2021
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.
Nice work John! This looks really good, I love that this simplifies things a lot.
b914a1f
to
4efe979
Compare
XrXr
reviewed
Dec 17, 2021
Previously we mirrored the fast paths the interpreter had for having only one of kwargs or optional args. This commit aims to combine the cases and reduce complexity. Though this allows calling iseqs which have have both optional and keyword arguments, it requires that all optional arguments are specified when there are keyword arguments, since unspecified optional arguments appear before the kwargs. Support for this can be added a in a future PR.
Previously, YJIT would not check that all the required keywords were specified in the case that there were optional arguments specified. In this case YJIT would incorrectly call the method with invalid arguments.
Inline and remove iseq_supported_args_p(iseq) to remove a potentially dangerous double check on `iseq->body->param.flags.has_block` and `iseq->body->local_iseq == iseq`. Double checking should be fine at the moment as there should be no case where we perform a call to an iseq that takes a block but `local_iseq != iseq`, but such situation might be possible when we add support for calling into BMETHODs, for example. Inlining also has the benefit of mirroring the interpreter's code for blockarg setup in `setup_parameters_complex()`, making checking for parity easier. Extract `vm_ci_flag(ci) & VM_CALL_KWARG` into a const local for brevity. Constify `doing_kw_call` because we can.
805dbc1
to
c3e5ee2
Compare
XrXr
approved these changes
Dec 17, 2021
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.
Thank you!
noahgibbs
added a commit
to Shopify/ruby
that referenced
this pull request
Mar 7, 2022
noahgibbs
added a commit
to Shopify/ruby
that referenced
this pull request
Mar 7, 2022
maximecb
pushed a commit
to Shopify/ruby
that referenced
this pull request
Mar 7, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This started as a cleanup to combine the branches we had in
gen_send_iseq
Previously we mirrored the fast paths the interpreter has for having either kwargs or optional args. The first commit aims to combine those cases and reduce complexity.
Though this allows calling iseqs which have have both optional and keyword arguments, it requires that all optional arguments are specified when there are keyword arguments, since unspecified optional arguments appear before the kwargs. Support for this can be added a in a future PR.
The second commit fixes a bug found while adding additional tests to the changes to gen_send_iseq. Previously, YJIT would not check that all the required keywords were specified in the case that there were optional arguments specified. In
this case YJIT would incorrectly call the method with invalid arguments. This is solved by counting and verifying that all required kwargs are specified.
I'm pleased that this ended up with about 20 fewer lines of code 🙂.