Skip to content

Commit aaeb451

Browse files
committed
Include ivar name and class in class/module ivar-set isolation violation
The set-side warning now reports which instance variable and class triggered the violation (e.g. "@foo from Foo"), matching the format of the read-side warning and making each violation uniquely identifiable. Assisted-By: devx/1467c1c0-7d14-4cf6-926c-dd31cac15fdc
1 parent 243b326 commit aaeb451

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

variable.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,11 +1199,13 @@ rb_alias_variable(ID name1, ID name2)
11991199
}
12001200

12011201
static void
1202-
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(ID id)
1202+
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(VALUE obj, ID id)
12031203
{
12041204
if (UNLIKELY(rb_ractor_isolation_check_active())) {
12051205
if (rb_is_instance_id(id)) { // check only normal ivars
1206-
rb_ractor_isolation_violation("can not set instance variables of classes/modules by non-main Ractors");
1206+
/* Pass rb_class_path() rather than the class itself to avoid
1207+
* marking the class as shared while building the message. */
1208+
rb_ractor_isolation_violation("can not set instance variables of classes/modules by non-main Ractors (%"PRIsVALUE" from %"PRIsVALUE")", rb_id2str(id), rb_class_path(obj));
12071209
}
12081210
}
12091211
}
@@ -1674,7 +1676,7 @@ rb_ivar_delete(VALUE obj, ID id, VALUE undef)
16741676
switch(type) {
16751677
case T_CLASS:
16761678
case T_MODULE:
1677-
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(id);
1679+
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(obj, id);
16781680

16791681
fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
16801682
if (rb_multi_ractor_p()) {
@@ -2066,7 +2068,7 @@ ivar_set(VALUE obj, ID id, VALUE val)
20662068
case T_CLASS:
20672069
case T_MODULE:
20682070
{
2069-
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(id);
2071+
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(obj, id);
20702072
bool dontcare;
20712073
return class_ivar_set(obj, id, val, &dontcare);
20722074
}
@@ -2375,7 +2377,7 @@ rb_field_foreach(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
23752377
case T_CLASS:
23762378
case T_MODULE:
23772379
{
2378-
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(0);
2380+
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(obj, 0);
23792381
VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
23802382
if (fields_obj) {
23812383
imemo_fields_each(fields_obj, func, arg, ivar_only);

0 commit comments

Comments
 (0)