Skip to content

Commit a11952d

Browse files
jemmaissrofftenderlove
authored andcommitted
Rename iv_count on shapes to next_iv_index
`iv_count` is a misleading name because when IVs are unset, the new shape doesn't decrement this value. `next_iv_count` is an accurate, and more descriptive name.
1 parent 13bd617 commit a11952d

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,7 +3434,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
34343434
VALUE klass = RBASIC_CLASS(obj);
34353435

34363436
// Increment max_iv_count if applicable, used to determine size pool allocation
3437-
uint32_t num_of_ivs = shape->iv_count;
3437+
uint32_t num_of_ivs = shape->next_iv_index;
34383438
if (RCLASS_EXT(klass)->max_iv_count < num_of_ivs) {
34393439
RCLASS_EXT(klass)->max_iv_count = num_of_ivs;
34403440
}

mjit_c.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def C.rb_shape
606606
"rb_shape", Primitive.cexpr!("SIZEOF(struct rb_shape)"),
607607
edges: [CType::Pointer.new { self.rb_id_table }, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), edges)")],
608608
edge_name: [self.ID, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), edge_name)")],
609-
iv_count: [self.attr_index_t, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), iv_count)")],
609+
next_iv_index: [self.attr_index_t, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), next_iv_index)")],
610610
type: [CType::Immediate.parse("uint8_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), type)")],
611611
parent_id: [self.shape_id_t, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), parent_id)")],
612612
)

shape.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,19 @@ get_next_shape_internal(rb_shape_t* shape, ID id, VALUE obj, enum shape_type sha
142142

143143
switch (shape_type) {
144144
case SHAPE_IVAR:
145-
new_shape->iv_count = rb_shape_get_shape_by_id(new_shape->parent_id)->iv_count + 1;
145+
new_shape->next_iv_index = rb_shape_get_shape_by_id(new_shape->parent_id)->next_iv_index + 1;
146146

147-
// Check if we should update max_iv_count on the object's class
147+
// Check if we should update next_iv_index on the object's class
148148
if (BUILTIN_TYPE(obj) == T_OBJECT) {
149149
VALUE klass = rb_obj_class(obj);
150-
if (new_shape->iv_count > RCLASS_EXT(klass)->max_iv_count) {
151-
RCLASS_EXT(klass)->max_iv_count = new_shape->iv_count;
150+
if (new_shape->next_iv_index > RCLASS_EXT(klass)->max_iv_count) {
151+
RCLASS_EXT(klass)->max_iv_count = new_shape->next_iv_index;
152152
}
153153
}
154154
break;
155155
case SHAPE_IVAR_UNDEF:
156156
case SHAPE_FROZEN:
157-
new_shape->iv_count = rb_shape_get_shape_by_id(new_shape->parent_id)->iv_count;
157+
new_shape->next_iv_index = rb_shape_get_shape_by_id(new_shape->parent_id)->next_iv_index;
158158
break;
159159
case SHAPE_ROOT:
160160
rb_bug("Unreachable");
@@ -244,8 +244,8 @@ rb_shape_get_iv_index(rb_shape_t * shape, ID id, attr_index_t *value)
244244

245245
switch (shape_type) {
246246
case SHAPE_IVAR:
247-
RUBY_ASSERT(shape->iv_count > 0);
248-
*value = shape->iv_count - 1;
247+
RUBY_ASSERT(shape->next_iv_index > 0);
248+
*value = shape->next_iv_index - 1;
249249
return true;
250250
case SHAPE_IVAR_UNDEF:
251251
case SHAPE_ROOT:
@@ -280,7 +280,7 @@ rb_shape_alloc_with_parent_id(ID edge_name, shape_id_t parent_id)
280280
rb_shape_t * shape = shape_alloc();
281281

282282
shape->edge_name = edge_name;
283-
shape->iv_count = 0;
283+
shape->next_iv_index = 0;
284284
shape->parent_id = parent_id;
285285

286286
return shape;
@@ -404,12 +404,12 @@ rb_shape_edge_name(VALUE self)
404404
}
405405

406406
static VALUE
407-
rb_shape_iv_count(VALUE self)
407+
rb_shape_next_iv_index(VALUE self)
408408
{
409409
rb_shape_t* shape;
410410
TypedData_Get_Struct(self, rb_shape_t, &shape_data_type, shape);
411411

412-
return INT2NUM(shape->iv_count);
412+
return INT2NUM(shape->next_iv_index);
413413
}
414414

415415
static VALUE
@@ -526,7 +526,7 @@ Init_shape(void)
526526
rb_define_method(rb_cShape, "parent", rb_shape_parent, 0);
527527
rb_define_method(rb_cShape, "edges", rb_shape_edges, 0);
528528
rb_define_method(rb_cShape, "edge_name", rb_shape_edge_name, 0);
529-
rb_define_method(rb_cShape, "iv_count", rb_shape_iv_count, 0);
529+
rb_define_method(rb_cShape, "next_iv_index", rb_shape_next_iv_index, 0);
530530
rb_define_method(rb_cShape, "depth", rb_shape_export_depth, 0);
531531
rb_define_method(rb_cShape, "id", rb_wrapped_shape_id, 0);
532532
rb_define_method(rb_cShape, "type", rb_shape_type, 0);

shape.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef uint16_t shape_id_t;
4545
struct rb_shape {
4646
struct rb_id_table * edges; // id_table from ID (ivar) to next shape
4747
ID edge_name; // ID (ivar) for transition from parent to rb_shape
48-
attr_index_t iv_count;
48+
attr_index_t next_iv_index;
4949
uint8_t type;
5050
shape_id_t parent_id;
5151
};
@@ -129,7 +129,7 @@ static inline uint32_t
129129
ROBJECT_IV_COUNT(VALUE obj)
130130
{
131131
RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
132-
uint32_t ivc = rb_shape_get_shape_by_id(ROBJECT_SHAPE_ID(obj))->iv_count;
132+
uint32_t ivc = rb_shape_get_shape_by_id(ROBJECT_SHAPE_ID(obj))->next_iv_index;
133133
RUBY_ASSERT(ivc <= ROBJECT_NUMIV(obj));
134134
return ivc;
135135
}

test/ruby/test_shapes.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ def test_shape_order
6565
def test_iv_index
6666
example = RemoveAndAdd.new
6767
shape = RubyVM::Shape.of(example)
68-
assert_equal 0, shape.iv_count
68+
assert_equal 0, shape.next_iv_index
6969

7070
example.add_foo # makes a transition
7171
new_shape = RubyVM::Shape.of(example)
7272
assert_equal([:@foo], example.instance_variables)
7373
assert_equal(shape.id, new_shape.parent.id)
74-
assert_equal(1, new_shape.iv_count)
74+
assert_equal(1, new_shape.next_iv_index)
7575

7676
example.remove # makes a transition
7777
remove_shape = RubyVM::Shape.of(example)
7878
assert_equal([], example.instance_variables)
7979
assert_equal(new_shape.id, remove_shape.parent.id)
80-
assert_equal(1, remove_shape.iv_count)
80+
assert_equal(1, remove_shape.next_iv_index)
8181

8282
example.add_bar # makes a transition
8383
bar_shape = RubyVM::Shape.of(example)
8484
assert_equal([:@bar], example.instance_variables)
8585
assert_equal(remove_shape.id, bar_shape.parent.id)
86-
assert_equal(2, bar_shape.iv_count)
86+
assert_equal(2, bar_shape.next_iv_index)
8787
end
8888

8989
def test_new_obj_has_root_shape

variable.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ generic_ivar_update(st_data_t *k, st_data_t *v, st_data_t u, int existing)
10181018
}
10191019
}
10201020
FL_SET((VALUE)*k, FL_EXIVAR);
1021-
ivtbl = gen_ivtbl_resize(ivtbl, ivup->shape->iv_count);
1021+
ivtbl = gen_ivtbl_resize(ivtbl, ivup->shape->next_iv_index);
10221022
// Reinsert in to the hash table because ivtbl might be a newly resized chunk of memory
10231023
*v = (st_data_t)ivtbl;
10241024
ivup->ivtbl = ivtbl;
@@ -1435,7 +1435,7 @@ rb_ensure_generic_iv_list_size(VALUE obj, uint32_t newsize)
14351435
void
14361436
rb_init_iv_list(VALUE obj)
14371437
{
1438-
uint32_t newsize = (uint32_t)(rb_shape_get_shape(obj)->iv_count * 2.0);
1438+
uint32_t newsize = (uint32_t)(rb_shape_get_shape(obj)->next_iv_index * 2.0);
14391439
uint32_t len = ROBJECT_NUMIV(obj);
14401440
rb_ensure_iv_list_size(obj, len, newsize < len ? len : newsize);
14411441
}
@@ -1450,7 +1450,7 @@ obj_ivar_set(VALUE obj, ID id, VALUE val)
14501450

14511451
if (!rb_shape_get_iv_index(shape, id, &index)) {
14521452
shape = rb_shape_get_next(shape, obj, id);
1453-
index = shape->iv_count - 1;
1453+
index = shape->next_iv_index - 1;
14541454
}
14551455

14561456
uint32_t len = ROBJECT_NUMIV(obj);
@@ -1615,7 +1615,7 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, VALUE* iv_list, rb_ivar_for
16151615
return;
16161616
case SHAPE_IVAR:
16171617
iterate_over_shapes_with_callback(rb_shape_get_shape_by_id(shape->parent_id), iv_list, callback, arg);
1618-
VALUE val = iv_list[shape->iv_count - 1];
1618+
VALUE val = iv_list[shape->next_iv_index - 1];
16191619
if (val != Qundef) {
16201620
callback(shape->edge_name, val, arg);
16211621
}
@@ -1753,7 +1753,7 @@ rb_ivar_count(VALUE obj)
17531753

17541754
switch (BUILTIN_TYPE(obj)) {
17551755
case T_OBJECT:
1756-
if (rb_shape_get_shape(obj)->iv_count > 0) {
1756+
if (rb_shape_get_shape(obj)->next_iv_index > 0) {
17571757
st_index_t i, count, num = ROBJECT_IV_COUNT(obj);
17581758
const VALUE *const ivptr = ROBJECT_IVPTR(obj);
17591759
for (i = count = 0; i < num; ++i) {

yjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub type shape_id_t = u32;
419419
pub struct rb_shape {
420420
pub edges: *mut rb_id_table,
421421
pub edge_name: ID,
422-
pub iv_count: attr_index_t,
422+
pub next_iv_index: attr_index_t,
423423
pub type_: u8,
424424
pub parent_id: shape_id_t,
425425
}

0 commit comments

Comments
 (0)