@@ -1300,7 +1300,7 @@ rb_free_generic_ivar(VALUE obj)
1300
1300
}
1301
1301
}
1302
1302
1303
- void
1303
+ static void
1304
1304
rb_obj_set_fields (VALUE obj , VALUE fields_obj , ID field_name , VALUE original_fields_obj )
1305
1305
{
1306
1306
ivar_ractor_check (obj , field_name );
@@ -1555,6 +1555,10 @@ rb_ivar_delete(VALUE obj, ID id, VALUE undef)
1555
1555
else {
1556
1556
val = rb_ivar_delete (fields_obj , id , undef );
1557
1557
}
1558
+ // TODO: What should we set as the T_CLASS shape_id?
1559
+ // In most case we can replicate the single `fields_obj` shape
1560
+ // but in namespaced case? Perhaps INVALID_SHAPE_ID?
1561
+ RBASIC_SET_SHAPE_ID (obj , RBASIC_SHAPE_ID (fields_obj ));
1558
1562
}
1559
1563
return val ;
1560
1564
}
@@ -1764,7 +1768,7 @@ imemo_fields_set(VALUE owner, VALUE fields_obj, shape_id_t target_shape_id, ID f
1764
1768
return fields_obj ;
1765
1769
}
1766
1770
1767
- static void
1771
+ static attr_index_t
1768
1772
generic_field_set (VALUE obj , shape_id_t target_shape_id , ID field_name , VALUE val )
1769
1773
{
1770
1774
if (!field_name ) {
@@ -1776,6 +1780,7 @@ generic_field_set(VALUE obj, shape_id_t target_shape_id, ID field_name, VALUE va
1776
1780
VALUE fields_obj = imemo_fields_set (obj , original_fields_obj , target_shape_id , field_name , val , false);
1777
1781
1778
1782
rb_obj_set_fields (obj , fields_obj , field_name , original_fields_obj );
1783
+ return rb_shape_too_complex_p (target_shape_id ) ? ATTR_INDEX_NOT_SET : RSHAPE_INDEX (target_shape_id );
1779
1784
}
1780
1785
1781
1786
static shape_id_t
@@ -1800,12 +1805,12 @@ generic_shape_ivar(VALUE obj, ID id, bool *new_ivar_out)
1800
1805
return target_shape_id ;
1801
1806
}
1802
1807
1803
- static void
1808
+ static attr_index_t
1804
1809
generic_ivar_set (VALUE obj , ID id , VALUE val )
1805
1810
{
1806
1811
bool dontcare ;
1807
1812
shape_id_t target_shape_id = generic_shape_ivar (obj , id , & dontcare );
1808
- generic_field_set (obj , target_shape_id , id , val );
1813
+ return generic_field_set (obj , target_shape_id , id , val );
1809
1814
}
1810
1815
1811
1816
void
@@ -1886,8 +1891,8 @@ obj_field_set(VALUE obj, shape_id_t target_shape_id, ID field_name, VALUE val)
1886
1891
}
1887
1892
}
1888
1893
1889
- attr_index_t
1890
- rb_obj_ivar_set (VALUE obj , ID id , VALUE val )
1894
+ static attr_index_t
1895
+ obj_ivar_set (VALUE obj , ID id , VALUE val )
1891
1896
{
1892
1897
bool dontcare ;
1893
1898
shape_id_t target_shape_id = generic_shape_ivar (obj , id , & dontcare );
@@ -1902,7 +1907,7 @@ VALUE
1902
1907
rb_vm_set_ivar_id (VALUE obj , ID id , VALUE val )
1903
1908
{
1904
1909
rb_check_frozen (obj );
1905
- rb_obj_ivar_set (obj , id , val );
1910
+ obj_ivar_set (obj , id , val );
1906
1911
return val ;
1907
1912
}
1908
1913
@@ -1922,26 +1927,25 @@ void rb_obj_freeze_inline(VALUE x)
1922
1927
}
1923
1928
}
1924
1929
1925
- static void
1930
+ static attr_index_t class_ivar_set (VALUE obj , ID id , VALUE val , bool * new_ivar );
1931
+
1932
+ static attr_index_t
1926
1933
ivar_set (VALUE obj , ID id , VALUE val )
1927
1934
{
1928
1935
RB_DEBUG_COUNTER_INC (ivar_set_base );
1929
1936
1930
1937
switch (BUILTIN_TYPE (obj )) {
1931
1938
case T_OBJECT :
1932
- {
1933
- rb_obj_ivar_set (obj , id , val );
1934
- break ;
1935
- }
1939
+ return obj_ivar_set (obj , id , val );
1936
1940
case T_CLASS :
1937
1941
case T_MODULE :
1938
- IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR (id );
1939
- rb_class_ivar_set (obj , id , val );
1940
-
1941
- break ;
1942
+ {
1943
+ IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR (id );
1944
+ bool dontcare ;
1945
+ return class_ivar_set (obj , id , val , & dontcare );
1946
+ }
1942
1947
default :
1943
- generic_ivar_set (obj , id , val );
1944
- break ;
1948
+ return generic_ivar_set (obj , id , val );
1945
1949
}
1946
1950
}
1947
1951
@@ -1953,6 +1957,12 @@ rb_ivar_set(VALUE obj, ID id, VALUE val)
1953
1957
return val ;
1954
1958
}
1955
1959
1960
+ attr_index_t
1961
+ rb_ivar_set_index (VALUE obj , ID id , VALUE val )
1962
+ {
1963
+ return ivar_set (obj , id , val );
1964
+ }
1965
+
1956
1966
void
1957
1967
rb_ivar_set_internal (VALUE obj , ID id , VALUE val )
1958
1968
{
@@ -1962,21 +1972,19 @@ rb_ivar_set_internal(VALUE obj, ID id, VALUE val)
1962
1972
ivar_set (obj , id , val );
1963
1973
}
1964
1974
1965
- void
1975
+ attr_index_t
1966
1976
rb_obj_field_set (VALUE obj , shape_id_t target_shape_id , ID field_name , VALUE val )
1967
1977
{
1968
1978
switch (BUILTIN_TYPE (obj )) {
1969
1979
case T_OBJECT :
1970
- obj_field_set (obj , target_shape_id , field_name , val );
1971
- break ;
1980
+ return obj_field_set (obj , target_shape_id , field_name , val );
1972
1981
case T_CLASS :
1973
1982
case T_MODULE :
1974
1983
// The only field is object_id and T_CLASS handle it differently.
1975
1984
rb_bug ("Unreachable" );
1976
1985
break ;
1977
1986
default :
1978
- generic_field_set (obj , target_shape_id , field_name , val );
1979
- break ;
1987
+ return generic_field_set (obj , target_shape_id , field_name , val );
1980
1988
}
1981
1989
}
1982
1990
@@ -4483,8 +4491,8 @@ rb_iv_set(VALUE obj, const char *name, VALUE val)
4483
4491
return rb_ivar_set (obj , id , val );
4484
4492
}
4485
4493
4486
- static bool
4487
- class_fields_ivar_set (VALUE klass , VALUE fields_obj , ID id , VALUE val , bool concurrent , VALUE * new_fields_obj )
4494
+ static attr_index_t
4495
+ class_fields_ivar_set (VALUE klass , VALUE fields_obj , ID id , VALUE val , bool concurrent , VALUE * new_fields_obj , bool * new_ivar_out )
4488
4496
{
4489
4497
const VALUE original_fields_obj = fields_obj ;
4490
4498
fields_obj = original_fields_obj ? original_fields_obj : rb_imemo_fields_new (klass , 1 );
@@ -4531,7 +4539,8 @@ class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool conc
4531
4539
}
4532
4540
4533
4541
* new_fields_obj = fields_obj ;
4534
- return new_ivar ;
4542
+ * new_ivar_out = new_ivar ;
4543
+ return index ;
4535
4544
4536
4545
too_complex :
4537
4546
{
@@ -4552,32 +4561,39 @@ class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool conc
4552
4561
}
4553
4562
4554
4563
* new_fields_obj = fields_obj ;
4555
- return new_ivar ;
4564
+ * new_ivar_out = new_ivar ;
4565
+ return ATTR_INDEX_NOT_SET ;
4556
4566
}
4557
4567
4558
- bool
4559
- rb_class_ivar_set (VALUE obj , ID id , VALUE val )
4568
+ static attr_index_t
4569
+ class_ivar_set (VALUE obj , ID id , VALUE val , bool * new_ivar )
4560
4570
{
4561
- RUBY_ASSERT (RB_TYPE_P (obj , T_CLASS ) || RB_TYPE_P (obj , T_MODULE ));
4562
- rb_check_frozen (obj );
4563
-
4564
4571
rb_class_ensure_writable (obj );
4565
4572
4566
4573
const VALUE original_fields_obj = RCLASS_WRITABLE_FIELDS_OBJ (obj );
4567
4574
VALUE new_fields_obj = 0 ;
4568
4575
4569
- bool new_ivar = class_fields_ivar_set (obj , original_fields_obj , id , val , rb_multi_ractor_p (), & new_fields_obj );
4576
+ attr_index_t index = class_fields_ivar_set (obj , original_fields_obj , id , val , rb_multi_ractor_p (), & new_fields_obj , new_ivar );
4570
4577
4571
4578
if (new_fields_obj != original_fields_obj ) {
4572
4579
RCLASS_WRITABLE_SET_FIELDS_OBJ (obj , new_fields_obj );
4573
4580
}
4574
4581
4575
4582
// TODO: What should we set as the T_CLASS shape_id?
4576
4583
// In most case we can replicate the single `fields_obj` shape
4577
- // but in namespaced case?
4578
- // Perhaps INVALID_SHAPE_ID?
4584
+ // but in namespaced case? Perhaps INVALID_SHAPE_ID?
4579
4585
RBASIC_SET_SHAPE_ID (obj , RBASIC_SHAPE_ID (new_fields_obj ));
4586
+ return index ;
4587
+ }
4580
4588
4589
+ bool
4590
+ rb_class_ivar_set (VALUE obj , ID id , VALUE val )
4591
+ {
4592
+ RUBY_ASSERT (RB_TYPE_P (obj , T_CLASS ) || RB_TYPE_P (obj , T_MODULE ));
4593
+ rb_check_frozen (obj );
4594
+
4595
+ bool new_ivar ;
4596
+ class_ivar_set (obj , id , val , & new_ivar );
4581
4597
return new_ivar ;
4582
4598
}
4583
4599
0 commit comments