ruby-changes:70215
From: John <ko1@a...>
Date: Wed, 15 Dec 2021 08:23:07 +0900 (JST)
Subject: [ruby-changes:70215] e307627b6c (master): Don't invalidate BOPs when aliases redefined
https://git.ruby-lang.org/ruby.git/commit/?id=e307627b6c From e307627b6cdafd830680ccf52bf8832c80326935 Mon Sep 17 00:00:00 2001 From: John Hawthorn <john@h...> Date: Tue, 14 Dec 2021 13:20:45 -0800 Subject: Don't invalidate BOPs when aliases redefined Previously when redefining an alias of a BOP, we would unnecessarily invalidate the bop. For example: class String alias len length private :len end This commit avoids this by checking that the called_id on the method entry matches the original_id on the definition. --- vm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vm.c b/vm.c index c5934d52a56..a405cd0a8cc 100644 --- a/vm.c +++ b/vm.c @@ -1863,8 +1863,13 @@ rb_vm_check_optimizable_mid(VALUE mid) https://github.com/ruby/ruby/blob/trunk/vm.c#L1863 } static int -vm_redefinition_check_method_type(const rb_method_definition_t *def) +vm_redefinition_check_method_type(const rb_method_entry_t *me) { + if (me->called_id != me->def->original_id) { + return FALSE; + } + + const rb_method_definition_t *def = me->def; switch (def->type) { case VM_METHOD_TYPE_CFUNC: case VM_METHOD_TYPE_OPTIMIZED: @@ -1882,7 +1887,7 @@ rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass) https://github.com/ruby/ruby/blob/trunk/vm.c#L1887 RB_TYPE_P(RBASIC_CLASS(klass), T_CLASS)) { klass = RBASIC_CLASS(klass); } - if (vm_redefinition_check_method_type(me->def)) { + if (vm_redefinition_check_method_type(me)) { if (st_lookup(vm_opt_method_def_table, (st_data_t)me->def, &bop)) { int flag = vm_redefinition_check_flag(klass); if (flag != 0) { @@ -1917,7 +1922,7 @@ add_opt_method(VALUE klass, ID mid, VALUE bop) https://github.com/ruby/ruby/blob/trunk/vm.c#L1922 { const rb_method_entry_t *me = rb_method_entry_at(klass, mid); - if (me && vm_redefinition_check_method_type(me->def)) { + if (me && vm_redefinition_check_method_type(me)) { st_insert(vm_opt_method_def_table, (st_data_t)me->def, (st_data_t)bop); st_insert(vm_opt_mid_table, (st_data_t)mid, (st_data_t)Qtrue); } -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/