[ruby-core:95653] [Ruby master Feature#16289] Reduce duplicated warnings for the change of Ruby 3 keyword arguments
From:
eregontp@...
Date:
2019-11-02 12:56:05 UTC
List:
ruby-core #95653
Issue #16289 has been updated by Eregon (Benoit Daloze).
What's the performance with this patch for a call site that would warn?
```
$ chruby ruby-2.7.0-preview2
$ ruby -rbenchmark/ips -e 'def m(**kw); end; h =3D {a: 1}; Benchmark.ips { =
|x| x.report { m(h) } }' 2>/dev/null =
Warming up --------------------------------------
46.040k i/100ms
Calculating -------------------------------------
504.460k (=B1 7.0%) i/s - 2.532M in 5.050515s
$ chruby 2.6.2
$ ruby -rbenchmark/ips -e 'def m(**kw); end; h =3D {a: 1}; Benchmark.ips { =
|x| x.report { m(h) } }' =
Warming up --------------------------------------
322.637k i/100ms
Calculating -------------------------------------
5.925M (=B1 8.8%) i/s - 29.683M in 5.055851s
```
----------------------------------------
Feature #16289: Reduce duplicated warnings for the change of Ruby 3 keyword=
arguments
https://bugs.ruby-lang.org/issues/16289#change-82441
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: =
* Target version: =
----------------------------------------
## Problem
Currently, the interpreter emits 200 lines of warnings against the followin=
g program.
```ruby
def foo(**opt); end
100.times { foo({kw:1}) }
```
```
$ ./miniruby -e 'def foo(**opt); end; 100.times { foo({kw:1}) }'
-e:1: warning: The last argument is used as the keyword parameter
-e:1: warning: for `foo' defined here
-e:1: warning: The last argument is used as the keyword parameter
-e:1: warning: for `foo' defined here
-e:1: warning: The last argument is used as the keyword parameter
-e:1: warning: for `foo' defined here
...
```
In theory, the warnings are not harmful because they don't stop or interfer=
e the execution. But in practice, I'm afraid if they are annoying because =
they flush all console logs away.
I think that the warning is not needed if the call is already warned.
## Proposal
How about limiting the count of warnings to at most once for each pair of c=
aller and callee?
I've created [a pull request](https://github.com/ruby/ruby/pull/2458). It =
records all pairs of caller position and callee iseq when emitting a warnin=
g, and suppress the warning if the same pair of caller and callee is alread=
y warned.
What do you think?
-- =
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>