Граф коммитов

599 Коммитов

Автор SHA1 Сообщение Дата
Aaron Patterson 4faaa8e5dc Collect statistics about binding allocations / local variable set
This commit collects statistics about how many binding objects are
allocated as well as the number of local variables set on bindings.
Statistics are output along with other YJIT stats.  Here is an example
of the output:

```
***YJIT: Printing runtime counters from yjit.rb***
Number of Bindings Allocated: 195
Number of locals modified through binding: 0
opt_send_without_block exit reasons:
          ivar_get_method    7515891 (40.4%)
       se_cc_klass_differ    3081330 (16.6%)
       iseq_argc_mismatch    1564578 ( 8.4%)
     se_receiver_not_heap    1557663 ( 8.4%)
                 ic_empty    1407064 ( 7.6%)
         optimized_method     995823 ( 5.4%)
          iseq_not_simple     819413 ( 4.4%)
             alias_method     706972 ( 3.8%)
                  bmethod     685253 ( 3.7%)
      callsite_not_simple     225983 ( 1.2%)
                 kw_splat      25999 ( 0.1%)
          ivar_set_method        902 ( 0.0%)
       cfunc_toomany_args        394 ( 0.0%)
           refined_method         42 ( 0.0%)
    cfunc_ruby_array_varg         29 ( 0.0%)
              invalid_cme          4 ( 0.0%)
leave exit reasons:
    se_finish_frame    4067107 (100.0%)
       se_interrupt         24 ( 0.0%)
getinstancevariable exit reasons:
               undef     121177 (100.0%)
    idx_out_of_range          5 ( 0.0%)
opt_aref exit reasons:
    (all relevant counters are zero)
compiled_iseq_count:         3944
main_block_code_size:     1.1 MiB
side_block_code_size:     0.6 MiB
vm_insns_count:        1137268516
yjit_exec_insns_count:  414015644
ratio_in_yjit:              26.7%
avg_len_in_yjit:              7.5
total_exit_count:        55491789
most frequent exit op:
    opt_send_without_block:   18587628 (33.5%)
        opt_getinlinecache:   11075822 (20.0%)
                      send:    4949300 (8.9%)
                     leave:    4067131 (7.3%)
                   defined:    3975196 (7.2%)
       setinstancevariable:    3567315 (6.4%)
               invokesuper:    2982163 (5.4%)
        getblockparamproxy:    2168852 (3.9%)
                 opt_nil_p:    2104524 (3.8%)
                  opt_aref:    2013858 (3.6%)
```

Running RailsBench allocates 195 binding objects but doesn't set any
local variables.
2021-10-20 18:19:32 -04:00
S-H-GAMELINKS 9cd9eca379 Refactor rb_proc_call function 2021-10-10 09:31:25 +09:00
Nobuyoshi Nakada 10ebf87428
Assert not to be UNDEF visibility
Any defined methods, bound to any classes/modules and not being
UNDEFINED_METHOD_ENTRY_P, should not be METHOD_VISI_UNDEF.
2021-09-01 19:28:54 +09:00
Nobuyoshi Nakada 4c3140d60f
Add keyrest to ruby2_keywords parameters [Bug #18011] 2021-08-03 10:56:50 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
S-H-GAMELINKS d6b8819b79 Refactor rb_proc_call_with_block function 2021-07-22 14:02:54 +09:00
Benoit Daloze fd0df9c4fb Emit deprecatation warnings for rb_iterate()
* It is obsolete since 1.9, see
  https://github.com/ruby/ruby/blob/master/doc/extension.rdoc#label-Control+Structure
  and [Misc #18025]
2021-07-16 12:11:24 +02:00
Jeremy Evans be230615d0 Remove shift of ep when computing Proc#hash
The shift was causing far fewer unique values of hash than expected.

Fix pointed out by xtkoba (Tee KOBAYASHI)

Fixes [Bug #17951]
2021-06-24 12:25:33 -07:00
Nobuyoshi Nakada e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
Peter Zhu d8a13e5049 [Bug #17780] Fix Method#super_method for module alias
Method#super_method crashes for aliased module methods because they are
not defined on a class. This bug was introduced in
c60aaed185 as part of bug #17130.
2021-04-07 15:16:58 -04:00
Jean Boussier a03653d386 proc.c: make bind_call use existing callable method entry when possible
The most common use case for `bind_call` is to protect from core
methods being redefined, for instance a typical use:

```ruby
UNBOUND_METHOD_MODULE_NAME = Module.instance_method(:name)
def real_mod_name(mod)
  UNBOUND_METHOD_MODULE_NAME.bind_call(mod)
end
```

But it's extremely common that the method wasn't actually redefined.
In such case we can avoid creating a new callable method entry,
and simply delegate to the receiver.

This result in a 1.5-2X speed-up for the fast path, and little to
no impact on the slowpath:

```
compare-ruby: ruby 3.1.0dev (2021-02-05T06:33:00Z master b2674c1fd7) [x86_64-darwin19]
built-ruby: ruby 3.1.0dev (2021-02-15T10:35:17Z bind-call-fastpath d687e06615) [x86_64-darwin19]

|          |compare-ruby|built-ruby|
|:---------|-----------:|---------:|
|fastpath  |     11.325M|   16.393M|
|          |           -|     1.45x|
|slowpath  |     10.488M|   10.242M|
|          |       1.02x|         -|
```
2021-03-10 13:43:22 -08:00
Nobuyoshi Nakada 22b8ddfd10
Split `mnew` into unbound and callable
It always branches by `obj` is `Qundef` or not, which is invariant
for each functions; `obj_method` is the latter, and the other two
are the former.
2021-01-31 18:48:28 +09:00
卜部昌平 f8a117f858 kill CLONESETUP and DUPSETUP
They are no longer how Object#clone/Object#dup are defined.  In fact
DUPSETUP is not used from anywhere.  CLONESETUP has only one usage.
Let's not expose them to extension libraries.

cf https://github.com/ruby/ruby/pull/4100#discussion_r563481718
2021-01-27 09:30:15 +09:00
Nobuyoshi Nakada 8da7f4abc7
[DOC] Update Proc.new without a block [ci skip]
[Feature #10499]
[Feature #15554]
2021-01-04 15:54:09 +09:00
Marcus Stollsteimer 114840b0fe [DOC] Fix typo in proc.c 2020-12-26 22:49:23 +01:00
Jeremy Evans 1e215a66d2 Fix class of method in Method#inspect for singleton classes of classes
Previously, due to a change to fix bug 15608, Method#inspect output
changed for class methods:

Ruby 2.7
"#<Method: String.prepend(*)>"

Before change:
"#<Method: #<Class:Object>(Module)#prepend(*)>"

This is wrong because the Method object was created from String and
not Object. This is because the fix for bug 15608 assumed it was
being called on the singleton class of a instance, and would skip
the first singleton class until it got to the class itself.  For
class methods, this results in always using the superclass. Fix
behavior to not skip until the superclass if the singleton class
is the singleton class of a module or class.

After change:
"#<Method: #<Class:Object>(Module)#prepend(*)>"

Fixes [Bug #17428]
2020-12-23 19:29:19 -08:00
zverok 816bbfdc87 Document Proc#== 2020-12-21 19:22:38 -05:00
Koichi Sasada 124321e0c7 fix lambda's warning and tests
There are warning condition bugs and test bugs.
b53ccb9c69
2020-12-12 06:29:11 +09:00
Koichi Sasada b53ccb9c69 show deprecation warning correctly for lambda(&b)
lambda(&b) where b is given block of method (like: def foo(&b))
should warn correctly.
[Feature #17361]

Also labmda(&labmda_block) or lambda(&:to_s) (Symbol#to_proc)
should not warn (but I'm not sure who cares about it).
2020-12-11 11:57:25 +09:00
Tomás Coêlho 1ee8d4b0ac Fix typo on Proc docs 2020-11-16 12:38:10 -05:00
Aaron Patterson 67b2c21c32
Add `GC.auto_compact= true/false` and `GC.auto_compact`
* `GC.auto_compact=`, `GC.auto_compact` can be used to control when
  compaction runs.  Setting `auto_compact=` to true will cause
  compaction to occurr duing major collections.  At the moment,
  compaction adds significant overhead to major collections, so please
  test first!

[Feature #17176]
2020-11-02 14:42:48 -08:00
Koichi Sasada 07c03bc309 check isolated Proc more strictly
Isolated Proc prohibit to access outer local variables, but it was
violated by binding and so on, so they should be error.
2020-10-29 23:42:55 +09:00
Chris Seaton fef52122b0 Use proc_binding rather than rb_funcall
FIX
2020-10-06 15:41:47 -07:00
Nobuyoshi Nakada 68d24bc045
Moved rb_callable_receiver internal 2020-10-06 10:11:51 +09:00
Chris Seaton 8e173d8b27 Warn on a finalizer that captures the object to be finalized
Also improve specs and documentation for finalizers and more clearly
recommend a safe code pattern to use them.
2020-09-16 13:52:24 -07:00
Jeremy Evans c60aaed185
Fix Method#super_method for aliased methods
Previously, Method#super_method looked at the called_id to
determine the method id to use, but that isn't correct for
aliased methods, because the super target depends on the
original method id, not the called_id.

Additionally, aliases can reference methods defined in other
classes and modules, and super lookup needs to start in the
super of the defined class in such cases.

This adds tests for Method#super_method for both types of
aliases, one that uses VM_METHOD_TYPE_ALIAS and another that
does not.  Both check that the results for calling super
methods return the expected values.

To find the defined class for alias methods, add an rb_ prefix
to find_defined_class_by_owner in vm_insnhelper.c and make it
non-static, so that it can be called from method_super_method
in proc.c.

This bug was original discovered while researching [Bug #11189].

Fixes [Bug #17130]
2020-08-27 08:37:03 -07:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 2bfac015d3 proc_binding: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 3db159193e rb_obj_singleton_method: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 8b9b51bb3b rb_method_name_error: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 2390a8bd2e bind_local_variable_get: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada d1af2345c9
Removed space lines 2020-06-20 14:07:45 +09:00
Kazuki Tsujimoto e8b2578d31
Remove unused variables 2020-06-20 11:11:50 +09:00
Jeremy Evans 878af5147d Implement Proc#== and #eql?
Previously, these were not implemented, and Object#== and #eql?
were used.  This tries to check the proc internals to make sure
that procs created from separate blocks are treated as not equal,
but procs created from the same block are treated as equal, even
when the lazy proc allocation optimization is used.

Implements [Feature #14267]
2020-06-19 12:58:25 -07:00
卜部昌平 af6e63a9df rb_method_name_error: delete unused code
If you look at the code flow (break -> goto), this assignment never
makes any sense.  Should just remove.

I _guess_ this behaviour is unintended.  Original code at commit
4dc1a21809 did something.  It might be
the code flow that is buggy.  However rubyspec already includes this
particular edge case at ruby/core/module/undef_method_spec.rb.  I don't
think we can change the way it is any longer.
2020-06-17 10:06:01 +09:00
Jeremy Evans 2188d6d160 Warn when passing a non-literal block to Kernel#lambda
Implements [Feature #15973]
2020-06-11 07:30:48 -07:00
Jeremy Evans f3e927b0cc Make proc/Proc.new without block an error instead of warning
The warning for these was added in 2.7.
2020-06-10 17:49:54 -07:00
Jeremy Evans ad0eccf840
Work around infinite loop when overriding method visibility in prepended module (#3201)
For ZSUPER methods with no defined class for the method entry, start the next lookup at the superclass of the origin class of the method owner, instead of the superclass of the method owner.

Fixes [Bug #16942]
2020-06-09 16:30:55 -07:00
Nobuyoshi Nakada cf90df22c7
[DOC] Separated Method#[] from Method#call [Bug #16813] [ci skip] 2020-04-24 11:18:27 +09:00
Nobuyoshi Nakada ac2106acc2
[DOC] Fixed explanation for Method#>> [Bug #16813] [ci skip] 2020-04-24 11:16:19 +09:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
Jeremy Evans adecd43197
Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188
Correctly show defined class for aliases of aliases
2020-03-22 09:30:20 -07:00
Yusuke Endoh d514ba8e17 `Proc` made by `Hash#to_proc` should be a lambda [Bug #12671]
Like `Symbol#to_proc` (f0b815dc67)
2020-03-16 23:38:26 +09:00
Yusuke Endoh 47141797be hash.c: Do not use the fast path (rb_yield_values) for lambda blocks
As a semantics, Hash#each yields a 2-element array (pairs of keys and
values).  So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception
due to lambda's arity check.
However, the optimization that avoids Array allocation by using
rb_yield_values for blocks whose arity is more than 1 (introduced at
b9d2960337 and some commits), seemed to
overlook the lambda case, and wrongly allowed the code above to work.

This change experimentally attempts to make it strict; now the code
above raises an ArgumentError.  This is an incompatible change; if the
compatibility issue is bigger than our expectation, it may be reverted
(until Ruby 3.0 release).

[Bug #12706]
2020-03-16 23:17:12 +09:00
Yusuke Endoh ad10760b05 proc.c: Remove non-sense /* fall through */ 2020-03-16 11:01:08 +09:00
Jeremy Evans e02bd0e713
Don't display singleton class in Method#inspect unless method defined there
Previously, if an object has a singleton class, and you call
Object#method on the object, the resulting string would include
the object's singleton class, even though the method was not
defined in the singleton class.

Change this so the we only show the singleton class if the method
is defined in the singleton class.

Fixes [Bug #15608]
2020-03-09 07:57:16 -07:00
Nobuyoshi Nakada 5b29ea0845
Proc from Symbol needs a receiver
So its arity should be -2 instead of -1.

[Bug #16640]
https://bugs.ruby-lang.org/issues/16640#change-84337
2020-02-22 10:49:59 +09:00
Nobuyoshi Nakada 8c5ca318cb
`Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]
With refinements, too.
2020-02-22 00:45:05 +09:00
Nobuyoshi Nakada f0b815dc67
`Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260] 2020-02-19 15:46:26 +09:00
Nobuyoshi Nakada e3e96e3faa
Check if bindable against the refined target [Bug #16617] 2020-02-09 20:13:49 +09:00