Skip to content

Commit 3038d60

Browse files
committed
Disable attribute setting call cache when ivar_set event is enabled
Ruby uses call cache for attribute setting, which means that the `ivar_set` event is only fired on the first call by default. By disabling the call cache, the `ivar_set` event is fired on every call. This is similar to the behavior of `call` and `return` events.
1 parent a1972e7 commit 3038d60

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

vm_insnhelper.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4760,7 +4760,10 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st
47604760
vm_cc_attr_index_initialize(cc, INVALID_SHAPE_ID);
47614761
VM_CALL_METHOD_ATTR(v,
47624762
vm_call_attrset_direct(ec, cfp, cc, calling->recv),
4763-
CC_SET_FASTPATH(cc, vm_call_attrset, !(vm_ci_flag(ci) & aset_mask)));
4763+
CC_SET_FASTPATH(cc, vm_call_attrset,
4764+
!(vm_ci_flag(ci) & aset_mask) &&
4765+
!(ruby_vm_event_flags & RUBY_EVENT_IVAR_SET) &&
4766+
!(ruby_vm_event_enabled_global_flags & RUBY_EVENT_IVAR_SET)));
47644767
}
47654768
else {
47664769
cc = &((struct rb_callcache) {
@@ -4780,7 +4783,10 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st
47804783

47814784
VM_CALL_METHOD_ATTR(v,
47824785
vm_call_attrset_direct(ec, cfp, cc, calling->recv),
4783-
CC_SET_FASTPATH(cc, vm_call_attrset, !(vm_ci_flag(ci) & aset_mask)));
4786+
CC_SET_FASTPATH(cc, vm_call_attrset,
4787+
!(vm_ci_flag(ci) & aset_mask) &&
4788+
!(ruby_vm_event_flags & RUBY_EVENT_IVAR_SET) &&
4789+
!(ruby_vm_event_enabled_global_flags & RUBY_EVENT_IVAR_SET)));
47844790
}
47854791

47864792
ID mid = vm_ci_mid(ci);

0 commit comments

Comments
 (0)