10000 Reduce duplicated warnings for the change of Ruby 3 keyword arguments by mame · Pull Request #2458 · ruby/ruby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Reduce duplicated warnings for the change of Ruby 3 keyword arguments #2458

Merged
merged 1 commit into from
Nov 29, 2019

Conversation

mame
Copy link
Member
@mame mame commented Sep 13, 2019

By this change, the following code prints only one warning.

def foo(**opt); end
100.times { foo({kw:1}) }

A global variable st_table *caller_to_callee_to_warned is a map from
caller to a set of callee methods. It remembers that a warning is
already printed for each pair of caller and callee.

@mame mame force-pushed the reduce-duplicated-keyword-warnings branch from 3581029 to a5cdbda Compare September 13, 2019 08:19
@jeremyevans
Copy link
Contributor

In terms of idea, whether we want this feature depends on how annoying we want the warnings to be. If they warn every call, they are very annoying and it will push people to fixing the issue. If they only warn once, they are not that annoying, and people may be less inclined to fix the issue.

FYI, I've been working on changes to rb_scan_args to also issue warnings for cases where we may want to change behavior in Ruby 3, and since that doesn't use iseq, it couldn't use this feature. Then we would end up in a situation where certain warnings are only issued once, and other warnings are issued every time. Or alternatively, we use a different approach for tracking warnings for those calls.

Note that deduping warnings can already be done in Ruby with minimal code:

WARNINGS_SEEN = {}
def Warning.warn(str)
  unless WARNINGS_SEEN[str]
    WARNINGS_SEEN[str] = true
    super
  end
end

I think the implementation look fine. However, instead of passing through ec and cfp, maybe just pass ec, and access cfp via ec->cfp in rb_warn_check?

@mame mame force-pushed the reduce-duplicated-keyword-warnings branch from a5cdbda to 78e3c68 Compare September 15, 2019 02:33
@shyouhei
Copy link
Member

Huge +1. I don't understand why people can live without this patch.

@mame mame force-pushed the reduce-duplicated-keyword-warnings branch from 78e3c68 to b21386d Compare November 1, 2019 03:24
@mame
Copy link
Member Author
mame commented Nov 1, 2019

Rebased. I'll create a ticket in the redmine and hear opinions.

@mame
Copy link
Member Author
mame commented Nov 2, 2019

@jeremyevans

If they warn every call, they are very annoying and it will push people to fixing the issue.

It is a very good point. But I'm afraid if it is too annoying so that people don't use 2.7.

since that doesn't use iseq, it couldn't use this feature.

IMO, the check doesn't have to be perfect. It would be enough if it filters many redundant warnings.

Note that deduping warnings can already be done in Ruby with minimal code:

It removes not only keyword-related warnings but also other ones. I'm unsure if it is acceptable or not.

instead of passing through ec and cfp, maybe just pass ec, and access cfp via ec->cfp in rb_warn_check?

Fixed in the above force push. Thank you!

@eregon
Copy link
Member
eregon commented Nov 27, 2019

It removes not only keyword-related warnings but also other ones. I'm unsure if it is acceptable or not.

That actually seems a very useful feature: https://bugs.ruby-lang.org/issues/16345#note-32

By this change, the following code prints only one warning.

```
def foo(**opt); end
100.times { foo({kw:1}) }
```

A global variable `st_table *caller_to_callees` is a map from caller to
a set of callee methods.  It remembers that a warning is already printed
for each pair of caller and callee.

[Feature #16289]
@mame mame force-pushed the reduce-duplicated-keyword-warnings branch from b21386d to bc6fb28 Compare November 29, 2019 08:31
@mame mame merged commit 191ce53 into ruby:master Nov 29, 2019
@mame mame deleted the reduce-duplicated-keyword-warnings branch November 29, 2019 08:32
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.

4 participants
0