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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: Allow calling iseq with mixed optional and keyword args and fix required kwarg check #5285

Merged
merged 3 commits into from
Dec 17, 2021

Conversation

jhawthorn
Copy link
Member

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 馃檪.

Copy link
Contributor

@kddnewton kddnewton left a 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.

@XrXr XrXr force-pushed the gen_send_iseq_refactor_and_fix branch from b914a1f to 4efe979 Compare December 17, 2021 16:58
yjit_codegen.c Show resolved Hide resolved
jhawthorn and others added 3 commits December 17, 2021 13:34
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.
@jhawthorn jhawthorn force-pushed the gen_send_iseq_refactor_and_fix branch from 805dbc1 to c3e5ee2 Compare December 17, 2021 21:35
Copy link
Member

@XrXr XrXr left a comment

Choose a reason for hiding this comment

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

Thank you!

@jhawthorn jhawthorn merged commit cc5fcae into ruby:master Dec 17, 2021
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
Labels
None yet
3 participants