Skip to content

Remove unnecessary checks for empty kw splat #4404

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
merged 1 commit into from
Apr 23, 2021

Conversation

XrXr
Copy link
Member

@XrXr XrXr commented Apr 23, 2021

These two checks are surrounded by an if that ensures the
call site is not a kw splat call site.

These two checks are surrounded by an if that ensures the
callsite is not a kw splat.
@XrXr XrXr requested a review from jeremyevans April 23, 2021 21:12
@XrXr XrXr changed the title Remove unncessary checks for empty kw splat Remove unnecessary checks for empty kw splat Apr 23, 2021
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

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

This should be correct as long as the rb_callinfo VM_CALL_KW_SPLAT flag is always set if calling->kw_splat is true. Based on the comment in CALLER_REMOVE_EMPTY_KW_SPLAT, that isn't always true, but it should only be false in case CALLER_REMOVE_EMPTY_KW_SPLAT has already been called, and calling CALLER_REMOVE_EMPTY_KW_SPLAT is idempotent. So I think this is a correct fix.

Related to this, the part of the comment in CALLER_REMOVE_EMPTY_KW_SPLAT regarding adding empty hashes back has been inaccurate since Ruby 3.0 (it was true in Ruby 2.7), I'll fix that.

@XrXr XrXr merged commit a224ce8 into ruby:master Apr 23, 2021
@XrXr XrXr deleted the remove-double-check branch April 23, 2021 23:37
@XrXr
Copy link
Member Author

XrXr commented Apr 24, 2021

Hmm actually this change introduces a behavior change in the following script:

def foo; end
foo(*[Hash.ruby2_keywords_hash({})])

I guess one could also get an empty keywords hash by clearing the one passed in as argument to a ruby2_keywords method.
I'll revert and add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants