diff options
author | John Hawthorn <[email protected]> | 2021-12-14 13:20:45 -0800 |
---|---|---|
committer | John Hawthorn <[email protected]> | 2021-12-14 15:22:51 -0800 |
commit | e307627b6cdafd830680ccf52bf8832c80326935 (patch) | |
tree | 06e42da44b34399b89a933ef899517a78cf976d7 /vm.c | |
parent | b7ae08992f7e4c663b61a3895d29d066fa22e452 (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5271
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -1863,8 +1863,13 @@ rb_vm_check_optimizable_mid(VALUE mid) } 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) 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) { 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); } |