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

319 Коммитов

Автор SHA1 Сообщение Дата
k0kubun ed935aa5be mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.

This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.

This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).

Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.

I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.

common.mk: update dependencies for mjit_compile.c.

internal.h: declare `rb_vm_insn_addr2insn` for MJIT.

vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.

win32/mkexports.rb: export thread/ec functions, which are used by MJIT.

include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.

array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.

I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.

Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>

Part of [Feature #14235]

---

* Known issues
  * Code generated by gcc is faster than clang. The benchmark may be worse
    in macOS. Following benchmark result is provided by gcc w/ Linux.
  * Performance is decreased when Google Chrome is running
  * JIT can work on MinGW, but it doesn't improve performance at least
    in short running benchmark.
  * Currently it doesn't perform well with Rails. We'll try to fix this
    before release.

---

* Benchmark reslts

Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores

- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option

** Optcarrot fps

Benchmark: https://github.com/mame/optcarrot

|         |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:--------|:--------|:--------|:--------|:--------|
|fps      |37.32    |51.46    |51.31    |58.88    |
|vs 2.0.0 |1.00x    |1.38x    |1.37x    |1.58x    |

** MJIT benchmarks

Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)

|           |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:----------|:--------|:--------|:--------|:--------|
|aread      |1.00     |1.09     |1.07     |2.19     |
|aref       |1.00     |1.13     |1.11     |2.22     |
|aset       |1.00     |1.50     |1.45     |2.64     |
|awrite     |1.00     |1.17     |1.13     |2.20     |
|call       |1.00     |1.29     |1.26     |2.02     |
|const2     |1.00     |1.10     |1.10     |2.19     |
|const      |1.00     |1.11     |1.10     |2.19     |
|fannk      |1.00     |1.04     |1.02     |1.00     |
|fib        |1.00     |1.32     |1.31     |1.84     |
|ivread     |1.00     |1.13     |1.12     |2.43     |
|ivwrite    |1.00     |1.23     |1.21     |2.40     |
|mandelbrot |1.00     |1.13     |1.16     |1.28     |
|meteor     |1.00     |2.97     |2.92     |3.17     |
|nbody      |1.00     |1.17     |1.15     |1.49     |
|nest-ntimes|1.00     |1.22     |1.20     |1.39     |
|nest-while |1.00     |1.10     |1.10     |1.37     |
|norm       |1.00     |1.18     |1.16     |1.24     |
|nsvb       |1.00     |1.16     |1.16     |1.17     |
|red-black  |1.00     |1.02     |0.99     |1.12     |
|sieve      |1.00     |1.30     |1.28     |1.62     |
|trees      |1.00     |1.14     |1.13     |1.19     |
|while      |1.00     |1.12     |1.11     |2.41     |

** Discourse's script/bench.rb

Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb

NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
 to fix it. Please wait for the fix.)

*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 17
  75: 18
  90: 22
  99: 29
home_admin:
  50: 21
  75: 21
  90: 27
  99: 40
topic_admin:
  50: 17
  75: 18
  90: 22
  99: 32
categories:
  50: 35
  75: 41
  90: 43
  99: 77
home:
  50: 39
  75: 46
  90: 49
  99: 95
topic:
  50: 46
  75: 52
  90: 56
  99: 101

*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 19
  75: 21
  90: 25
  99: 33
home_admin:
  50: 24
  75: 26
  90: 30
  99: 35
topic_admin:
  50: 19
  75: 20
  90: 25
  99: 30
categories:
  50: 40
  75: 44
  90: 48
  99: 76
home:
  50: 42
  75: 48
  90: 51
  99: 89
topic:
  50: 49
  75: 55
  90: 58
  99: 99

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 11:22:28 +00:00
shyouhei b6a2d63eb3 explicit cast to void* required for %p
These functions take variadic arguments so no automatic type
promotion is expected.  You have to do it by hand.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:40 +00:00
nobu e973bde0d0 vm_method.c: fix super in refined module
* vm_method.c (rb_method_entry_complement_defined_class): clone
  the original method entry of refined module instance method with
  the active ICLASS, to track super method chain.
  [ruby-dev:50390] [Bug #14232]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-26 10:32:58 +00:00
nobu 3b060b22f9 vm_method.c: empty table
* vm_method.c (prepare_callable_method_entry): empty method table
  has no entries.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-17 05:35:28 +00:00
nobu 639fd0874d vm_method.c: debug message
* vm_method.c (method_definition_addref_complement): fix debug
  message, show complemented_count instead of alias_count.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-17 05:35:27 +00:00
marcandre 0c03a89ecd Make Module#{define|alias|undef|remove}_method public [#14133]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-29 17:47:59 +00:00
ko1 b453fc2cb9 make a func static.
* vm_method.c (rb_resolve_refined_method_callable): make it static.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 08:53:49 +00:00
ko1 8184cb2bc7 remove unused function.
* vm_method.c (rb_method_entry_with_refinements): removed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 07:46:05 +00:00
ko1 7fa4beba91 `th` -> `ec` for method management functions.
* vm_eval.c: `th` -> `ec` for the following functions:
  * check_funcall_respond_to
  * check_funcall_callable
  * check_funcall_missing
  * rb_method_call_status

* vm_method.c: ditto.
  * call_method_entry
  * basic_obj_respond_to_missing
  * basic_obj_respond_to
  * vm_respond_to

* vm_eval.c (stack_check): accepts `ec` instead of `th`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28 12:23:51 +00:00
ko1 0c6e5c7880 use `ec` directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28 11:22:15 +00:00
ko1 9c4542dbaa `th` -> `ec` for vm_set_*_stack.
* vm.c: `th` -> `ec` for the following functions:
  * vm_set_top_stack
  * vm_set_eval_stack
  * vm_set_main_stack
  * vm_cref_new_toplevel


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28 10:23:58 +00:00
ko1 f8a9d044f4 move fields from `th` to `ec`.
* vm_core.h: move rb_thread_t::passed_block_handler to
  rb_execution_context_t::passed_block_handler.
  Also move rb_thread_t::passed_bmethod_me to
  rb_execution_context_t::passed_bmethod_me.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28 10:01:54 +00:00
ko1 c96f809729 `vm_call_handler` and related functions accept `ec` instead of `th`.
* vm_core.h (vm_call_handler): fix to accept `ec` instead of `th`.

* vm_args.c: the following functions accept `ec` instead of `th`.
  * raise_argument_error
  * argument_arity_error
  * argument_kw_error
  * setup_parameters_complex

* vm_eval.c: ditto.
  * vm_call0
  * vm_call0_cfunc_with_frame
  * vm_call0_cfunc
  * vm_call0_body

* vm_insnhelper.c: ditto
  * vm_call_iseq_setup_tailcall_0start
  * vm_call_iseq_setup_normal_0start
  * vm_callee_setup_arg
  * vm_call_iseq_setup
  * vm_call_iseq_setup_2
  * vm_call_iseq_setup_normal
  * vm_call_iseq_setup_tailcall
  * vm_cfp_consistent_p
  * vm_call_cfunc_with_frame
  * vm_call_cfunc
  * vm_call_ivar
  * vm_call_attrset
  * vm_call_bmethod_body
  * vm_call_bmethod
  * vm_call_opt_send
  * vm_call_opt_call
  * vm_call_method_missing
  * vm_call_zsuper
  * current_method_entry
  * vm_call_method_each_type
  * vm_call_method_nome
  * vm_call_method
  * vm_call_general
  * vm_call_super_method

* tool/mk_call_iseq_optimized.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 02:49:30 +00:00
ko1 e95de48f1d some functions accept `ec` instead of `th`.
* vm.c (vm_make_env_object): accepts `ec`.

* vm.c (rb_vm_get_ruby_level_next_cfp): ditto.

* vm.c (rb_vm_make_proc): ditto.

* vm.c (rb_vm_make_proc_lambda): ditto.

* vm_core.h: some macros accept ec instead of th
  (and make them inline functions):
  * RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW
  * RUBY_VM_END_CONTROL_FRAME
  * RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P

* eval.c (frame_func_id): constify for the first parameter.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:41:34 +00:00
ko1 837fd5e494 Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038]

* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
  There are many code using `th` to represent execution context
  (such as cfp, VM stack and so on). To access `ec`, they need to
  use `th->ec->...` (adding one indirection) so that we need to
  replace them by passing `ec` instead of `th`.

* vm_core.h (GET_EC()): introduced to access current ec. Also
  remove `ruby_current_thread` global variable.

* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
  rb_context_t::thread_value.

* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.

* cont.c (ec_switch): added to switch ec explicitly.

* cont.c (rb_fiber_close): added to terminate fibers explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:32:49 +00:00
nobu a15028bc38 proc.c: super_method of included method
* proc.c (method_super_method): search the next super method along
  the included ancestor chain.  [ruby-core:83114] [Bug #13973]

* vm_method.c (rb_callable_method_entry_without_refinements):
  return the defined class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-06 05:55:11 +00:00
nobu 0db193f98d vm_method.c: alias warning at refined method
* vm_method.c (rb_method_entry_make): suppress a warning at
  refined method which will not be redefined.
  [ruby-core:82385] [Bug #13817]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-17 14:58:11 +00:00
nobu 2b582b7ca6 UNALIGNED_MEMBER_ACCESS
* eval_intern.h (UNALIGNED_MEMBER_ACCESS): suppress
  address-of-packed-member warnings by clang 4.0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-30 14:48:45 +00:00
ko1 478003f6df rename absolute_path to realpath internally and introduce pathobj.
* vm_core.h: rename absolute_path to realpath because it is expected name.
  external APIs (#absolute_path methods) are remained.

* vm_core.h: remove rb_iseq_location_struct::path and
  rb_iseq_location_struct::absolute_path and introduce pathobj.
  if given path equals to given absolute_path (and most of case
  it is true), pathobj is simply given path String. If it is not same,
  pathobj is Array and pathobj[0] is path and pathobj[1] is realpath.

  This size optimization reduce 8 bytes and
  sizeof(struct rb_iseq_constant_body) is 200 bytes -> 192 bytes
  on 64bit CPU.

  To support this change, the following functions are introduced:
    * pathobj_path() (defined in vm_core.h)
    * pathobj_realpath() (ditto)
    * rb_iseq_path() (decl. in vm_core.h)
    * rb_iseq_realpath() (ditto)
    * rb_iseq_pathobj_new() (ditto)
    * rb_iseq_pathobj_set() (ditto)

* vm_core.h (rb_binding_t): use pathobj instead of path. If binding
  is given at eval methods, realpath (absolute_path) was caller's
  realpath. However, they should use binding's realpath.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01 00:05:33 +00:00
normal 9d09240d9e rb_execution_context_t: move stack, stack_size and cfp from rb_thread_t
The goal is to reduce rb_context_t and rb_fiber_t size
by removing the need to store the entire rb_thread_t in
there.

[ruby-core:81045] Work-in-progress: soon, we will move more fields here.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-09 05:06:41 +00:00
ko1 76c4cca19c add performance counting mechanism for MRI debug/tuning purpose.
* How to enable this feature?
  * define USE_DEBUG_COUNTER as 1.
  * you can disable to output the result with
    RUBY_DEBUG_COUNTER_DISABLE environment variable
    even if USE_DEBUG_COUNTER == 1.

* How to add new counter?
  * add COUNTER(<name>) line on debug_counter.h.
  * include "debug_counter.h"
  * insert RB_DEBUG_COUNTER_INC(<name>) line on your favorite place.

* counter output example:
  [RUBY_DEBUG_COUNTER]    mc_inline_hit   999
  [RUBY_DEBUG_COUNTER]    mc_inline_miss  3
  [RUBY_DEBUG_COUNTER]    mc_global_hit   23
  [RUBY_DEBUG_COUNTER]    mc_global_miss  273
  [RUBY_DEBUG_COUNTER]    mc_global_state_miss    3
  [RUBY_DEBUG_COUNTER]    mc_class_serial_miss    0
  [RUBY_DEBUG_COUNTER]    mc_cme_complement       0
  [RUBY_DEBUG_COUNTER]    mc_cme_complement_hit   0
  [RUBY_DEBUG_COUNTER]    mc_search_super 1384
  [RUBY_DEBUG_COUNTER]    ivar_get_hit    0
  [RUBY_DEBUG_COUNTER]    ivar_get_miss   0
  [RUBY_DEBUG_COUNTER]    ivar_set_hit    0
  [RUBY_DEBUG_COUNTER]    ivar_set_miss   0
  [RUBY_DEBUG_COUNTER]    ivar_get        431
  [RUBY_DEBUG_COUNTER]    ivar_set        465

  * mc_... is related to method caching.
  * ivar_... is related to instance variable accesses.

* compare with dtrace/system tap features, there are completely
  no performacne penalties when it is disabled.

* This feature is supported only on __GNUC__ compilers.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 08:18:15 +00:00
nobu 556a1352e4 backward.h: 2.2 deprecated features
* include/ruby/backward.h (DECLARE_DEPRECATED_FEATURE): move
  features deprecated at 2.2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 05:17:41 +00:00
nobu 6877de73de DEPRECATED_INTERNAL_FEATURE
* error.c (ruby_deprecated_internal_feature): renamed, to
  explicitly represent deprecation.

* internal.h (DEPRECATED_INTERNAL_FEATURE): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-17 05:45:44 +00:00
naruse f34d0ba3eb More description about the protected attribute of a method
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-19 09:34:30 +00:00
nobu b38823ceca vm_method.c: resolve refined method to undef
* vm_method.c (rb_undef): resolve the method entry which refines a
  prepended method entry.  [ruby-core:78944] [Bug #13096]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-18 05:23:53 +00:00
rhe c54ede0560 proc.c: assume rb_iseq_location_t::first_lineno is always a Fixnum
Do not check for the value of rb_iseq_constant_body::line_info_table as
it is no longer related. The checks seem to be the remains from the day
before the dedicated 'first_lineno' field was introduced. Remove them.

Note, rb_iseq_constant_body::line_info_table can be NULL only when the
iseq does not contain any instructions that originate from Ruby code,
for example, an iseq created with 'proc {}' under a non-default compile
options where trace instructions are disabled.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20 05:26:07 +00:00
ktsj 8004ad33bc * eval.c, method.h, proc.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c:
TracePoint#method_id should return method_id, not callee_id.
  [ruby-core:77241] [Feature #12747]

* test/ruby/test_settracefunc.rb: change accordingly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 13:15:26 +00:00
nobu a23878c3f5 vm_method.c: update assertion [ci skip]
* vm_method.c (prepare_callable_method_entry): update assertion
  as defined_class may be T_MODULE not only I_ICLASS since r56213.
  [Feature #12534]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-09 02:57:29 +00:00
shugo 5a121a4f0b * vm_method.c (make_method_entry_refined): fix wrong use of ||.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-23 14:59:26 +00:00
shugo a463ab1f05 * eval.c (rb_mod_refine): refine modules as well.
[ruby-core:76199] [Feature #12534]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-23 11:46:33 +00:00
nobu c463366dfd rb_funcallv
* *.c: rename rb_funcall2 to rb_funcallv, except for extensions
  which are/will be/may be gems.  [Fix GH-1406]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-29 11:57:14 +00:00
ko1 9f60791a04 * vm_core.h: revisit the structure of frame, block and env.
[Bug #12628]

  This patch introduce many changes.

  * Introduce concept of "Block Handler (BH)" to represent
    passed blocks.

  * move rb_control_frame_t::flag to ep[0] (as a special local
    variable). This flags represents not only frame type, but also
    env flags such as escaped.

  * rename `rb_block_t` to `struct rb_block`.

  * Make Proc, Binding and RubyVM::Env objects wb-protected.

  Check [Bug #12628] for more details.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-28 11:02:30 +00:00
ko1 bebb62e01b * vm_method.c (method_entry_get_without_cache): check
undefined method even if ruby_running is FALSE.

  We haven't call "undef"ed methods before ruby_running.
  So that this issue does not make troubles.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-13 05:19:12 +00:00
nobu b51174a6b0 No respond_to? as if the default definition
* vm_method.c (vm_respond_to): try method_missing if respond_to?
  is undefined, as if it is the default definition.
  [ruby-core:75377] [Bug #12353]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-24 17:33:35 +00:00
nobu d226ce8dec internal.h: ONLY_FOR_INTERNAL_USE
* error.c (ruby_only_for_internal_use): raise fatal error when
  deprecated function only for internal use is called, not just a
  warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 05:29:49 +00:00
nobu 6cde2d359a vm_method.c: fix aliased original name
* vm_method.c (rb_alias): the original name should be properly
  available method_added method, set the name before calling the
  hook.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-08 15:29:48 +00:00
nobu 58f7563dc6 vm_method.c: fix assertion
* vm_method.c (prepare_callable_method_entry): assert same
  condition only once for each case, not twice for module instance
  method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-01 14:43:34 +00:00
nobu 0cd34e9639 vm_method.c: for hidden object
* vm_method.c (rb_method_basic_definition_p): methods of hidden
  objects cannot be overridden, return TRUE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-24 02:38:43 +00:00
hsbt 389a84fdbf * vm_method.c: fix grammar in respond_to? warning.
[fix GH-1047]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-19 00:39:12 +00:00
yui-knk 5cf9b65aa3 Use `rb_method_visibility_t` instead of `int` in `rb_print_undef`
* eval_error.c (rb_print_undef): Use `rb_method_visibility_t`
  instead of `int`.
* eval_intern.h (rb_print_undef): ditto
* proc.c (mnew_internal): ditto
* vm_method.c (rb_export_method): ditto
  [Misc #11649] [ruby-core:71311] [fix GH-1078]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-03 04:59:54 +00:00
shugo f211abcb9c * vm_method.c (rb_method_entry_make, check_override_opt_method):
should check whether a newly created method override a optimize
  method in case the method is defined in a prepended module of a
  built-in class.
  [ruby-core:72226] [Bug #11836]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-18 02:32:17 +00:00
ko1 fa3affad9a * vm_method.c (rb_class_clear_method_cache): should clear all
RCLASS_CALLABLE_M_TBLs of all sub-classes (T_ICLASS).

  RCLASS_CALLABLE_M_TBL() caches complemented method entries.
  It should be cleared when the modules are cleared.
  On previous version clears only for direct children.
  It is enough for normal modules because corresponding T_ICLASSes
  are direct children.

  However, refinements create complex data structure. So that
  we need to clear all children (and descendants).
  [ruby-core:71423] [Bug #11672]

* vm_method.c (rb_clear_method_cache_by_class): rb_mKernel
  doesn't call rb_class_clear_method_cache, so that
  clear child T_ICLASSes.

* test/ruby/test_refinement.rb: enable disabled test.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-18 13:59:57 +00:00
ko1 03efb7def9 * vm_method.c (prepare_callable_method_entry): use
RCLASS_CALLABLE_M_TBL() instead of accessing a filed directly.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-18 12:10:07 +00:00
ko1 3f7c0e9fd5 * method.h: introduce the folliwing field and macros.
* rb_method_definition_t::complemented_count to count shared method
    entries because of complemented method entries and separate from
    alias_count.

    Shared `def' only by complemented method entries should not prevent
    method re-definition warning.

  * METHOD_ENTRY_COMPLEMENTED(me) to represent complemented method entry.
  * METHOD_ENTRY_COMPLEMENTED_SET(me) to check it as  complemented me.

* vm_insnhelper.c (aliased_callable_method_entry): should also
  check me->def->complemented_count.

* vm_method.c (method_definition_addref_complement): add to count
  complemented method entries number.

* vm_method.c (rb_method_definition_release): release `def' iff
  alias_count == 0 and complemented_count == 0.

* test/ruby/test_module.rb: add a test.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-18 08:15:51 +00:00
ko1 6a533a3ecc revert r52614, r52615, r52617 because they cause serious errors
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17 13:18:19 +00:00
ko1 551ae37ba3 * method.h (METHOD_ENTRY_COMPLEMENTED(_SET)): introduced to recognize
complemented method entries or not. There are some cases that callabe
  method entries do not have defined_class.

* vm_method.c (rb_method_entry_complement_defined_class):
  use METHOD_ENTRY_COMPLEMENTED_SET().




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17 10:39:30 +00:00
ko1 fa4e516db9 * method.h: introduce rb_method_definition_t::complemented_count.
* vm_method.c (method_definition_addref_complement): introduced.

  def->alias_count is used to decide warn or do not warn at method
  redefinition. Complented methods should not prevent redefiniton
  warnings.

* vm_method.c (rb_method_definition_release): release def iff
  alias_count == 0 && complemented_count == 0.

* test/ruby/test_module.rb: add a test.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17 09:42:39 +00:00
nobu 4ea616b387 vm_method.c: check if frozen [Fix GH-1096]
* vm_method.c (set_method_visibility): should fail if the receiver
  is frozen.  [ruby-core:71489] [Bug #11687]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-15 09:28:45 +00:00
ko1 25f5dd6799 * vm.c (vm_define_method): do not use current CREF immediately,
but check CREF in environment or methods. Methods defined in methods
  should be public.
  [Bug #11571]

* vm_method.c (rb_scope_module_func_check): check CREF in env or me.
  if CREF is contained by `me', then return FALSE.

* test/ruby/test_method.rb: add a test.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-13 17:38:12 +00:00
ko1 dd4cec36ca * method.h: constify rb_cref_t::scope_visi;
* eval_intern.h (CREF_SCOPE_VISI_COPY): catch up this fix.

* vm_method.c: ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-13 17:20:11 +00:00