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

Check for easy-to-handle cases of block param #24

Merged
merged 1 commit into from
May 6, 2021
Merged

Conversation

XrXr
Copy link
Contributor

@XrXr XrXr commented May 5, 2021

In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.

In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
iseq->body->param.flags.has_post == false &&
iseq->body->param.flags.has_kw == false &&
iseq->body->param.flags.has_kwrest == false &&
iseq->body->param.flags.accepts_no_kwarg == false;
Copy link
Contributor

@maximecb maximecb May 6, 2021

Choose a reason for hiding this comment

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

accepts_no_kwarg == false means the method accepts kwargs?

Copy link
Contributor Author

@XrXr XrXr May 6, 2021

Choose a reason for hiding this comment

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

Yea. For example, calling methods that only take position arguments with keywords is allowed:

def foo(a)
  p(a)
end

foo(key: 'word') # => {:key=>"word"}

We reject call kwarg call sites at the moment, though, just in case you are wondering how we deal with the kwargs to hash conversion.

The accepts_no_kwarg flag is for the **nil syntax:

def a(arg, **nil)
  p(arg)
end

a(key: 'word') # no keywords accepted (ArgumentError)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I will merge this but I think this is the sort of thing that could be better commented, because it's really not obvious for people not intimately familiar with specific parts of CRuby.

@maximecb maximecb merged commit 862ddf9 into main May 6, 2021
@maximecb maximecb deleted the simple-block-param branch May 6, 2021 16:24
noahgibbs pushed a commit that referenced this pull request Sep 30, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
noahgibbs pushed a commit that referenced this pull request Oct 1, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
noahgibbs pushed a commit that referenced this pull request Oct 1, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
noahgibbs pushed a commit that referenced this pull request Oct 1, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
noahgibbs pushed a commit that referenced this pull request Oct 11, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
noahgibbs pushed a commit that referenced this pull request Oct 18, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
XrXr added a commit that referenced this pull request Oct 19, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
XrXr added a commit that referenced this pull request Oct 20, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
XrXr added a commit to XrXr/yjit that referenced this pull request Oct 21, 2021
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
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