Skip to content

Commit ea77250

Browse files
committed
Rename RB_OBJ_SHAPE -> rb_obj_shape
As well as `RB_OBJ_SHAPE_ID` -> `rb_obj_shape_id` and `RSHAPE` is now a simple alias for `rb_shape_lookup`. I tried to turn all these into `static inline` but I'm having trouble with `RUBY_EXTERN rb_shape_tree_t *rb_shape_tree_ptr;` not being exposed as I'd expect.
1 parent 0b81359 commit ea77250

14 files changed

Lines changed: 68 additions & 67 deletions

File tree

ext/objspace/objspace_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ dump_object(VALUE obj, struct dump_config *dc)
414414
dump_append(dc, obj_type(obj));
415415
dump_append(dc, "\"");
416416

417-
size_t shape_id = RB_OBJ_SHAPE_ID(obj);
417+
size_t shape_id = rb_obj_shape_id(obj);
418418
dump_append(dc, ", \"shape_id\":");
419419
dump_append_sizet(dc, shape_id);
420420

gc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ rb_gc_shutdown_call_finalizer_p(VALUE obj)
367367
uint32_t
368368
rb_gc_get_shape(VALUE obj)
369369
{
370-
return (uint32_t)RB_OBJ_SHAPE_ID(obj);
370+
return (uint32_t)rb_obj_shape_id(obj);
371371
}
372372

373373
void
@@ -379,7 +379,7 @@ rb_gc_set_shape(VALUE obj, uint32_t shape_id)
379379
uint32_t
380380
rb_gc_rebuild_shape(VALUE obj, size_t heap_id)
381381
{
382-
shape_id_t orig_shape_id = RB_OBJ_SHAPE_ID(obj);
382+
shape_id_t orig_shape_id = rb_obj_shape_id(obj);
383383
if (rb_shape_id_too_complex_p(orig_shape_id)) {
384384
return (uint32_t)orig_shape_id;
385385
}
@@ -1815,7 +1815,7 @@ static VALUE
18151815
object_id(VALUE obj)
18161816
{
18171817
VALUE id = Qfalse;
1818-
rb_shape_t *shape = RB_OBJ_SHAPE(obj);
1818+
rb_shape_t *shape = rb_obj_shape(obj);
18191819
unsigned int lock_lev;
18201820

18211821
// We could avoid locking if the object isn't shareable

marshal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,18 +713,18 @@ has_ivars(VALUE obj, VALUE encname, VALUE *ivobj)
713713
static void
714714
w_ivar_each(VALUE obj, st_index_t num, struct dump_call_arg *arg)
715715
{
716-
shape_id_t shape_id = RB_OBJ_SHAPE_ID(arg->obj);
716+
shape_id_t shape_id = rb_obj_shape_id(arg->obj);
717717
struct w_ivar_arg ivarg = {arg, num};
718718
if (!num) return;
719719
rb_ivar_foreach(obj, w_obj_each, (st_data_t)&ivarg);
720720

721-
shape_id_t actual_shape_id = RB_OBJ_SHAPE_ID(arg->obj);
721+
shape_id_t actual_shape_id = rb_obj_shape_id(arg->obj);
722722
if (shape_id != actual_shape_id) {
723723
// If the shape tree got _shorter_ then we probably removed an IV
724724
// If the shape tree got longer, then we probably added an IV.
725725
// The exception message might not be accurate when someone adds and
726726
// removes the same number of IVs, but they will still get an exception
727-
if (rb_shape_depth(shape_id) > rb_shape_depth(RB_OBJ_SHAPE_ID(arg->obj))) {
727+
if (rb_shape_depth(shape_id) > rb_shape_depth(rb_obj_shape_id(arg->obj))) {
728728
rb_raise(rb_eRuntimeError, "instance variable removed from %"PRIsVALUE" instance",
729729
CLASS_OF(arg->obj));
730730
}

object.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ rb_class_allocate_instance(VALUE klass)
132132
T_OBJECT | ROBJECT_EMBED | (RGENGC_WB_PROTECTED_OBJECT ? FL_WB_PROTECTED : 0), size, 0);
133133
VALUE obj = (VALUE)o;
134134

135-
RUBY_ASSERT(RB_OBJ_SHAPE(obj)->type == SHAPE_ROOT);
135+
RUBY_ASSERT(rb_obj_shape(obj)->type == SHAPE_ROOT);
136136

137137
// Set the shape to the specific T_OBJECT shape.
138138
ROBJECT_SET_SHAPE_ID(obj, (shape_id_t)(rb_gc_heap_id_for_size(size) + FIRST_T_OBJECT_SHAPE_ID));
@@ -335,7 +335,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
335335
return;
336336
}
337337

338-
rb_shape_t *src_shape = RB_OBJ_SHAPE(obj);
338+
rb_shape_t *src_shape = rb_obj_shape(obj);
339339

340340
if (rb_shape_too_complex_p(src_shape)) {
341341
// obj is TOO_COMPLEX so we can copy its iv_hash
@@ -350,7 +350,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
350350
}
351351

352352
rb_shape_t *shape_to_set_on_dest = src_shape;
353-
rb_shape_t *initial_shape = RB_OBJ_SHAPE(dest);
353+
rb_shape_t *initial_shape = rb_obj_shape(dest);
354354

355355
if (initial_shape->heap_index != src_shape->heap_index || !rb_shape_canonical_p(src_shape)) {
356356
RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT);

shape.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ rb_shape_each_shape(each_shape_callback callback, void *data)
340340
}
341341

342342
RUBY_FUNC_EXPORTED rb_shape_t *
343-
RSHAPE(shape_id_t shape_id)
343+
rb_shape_lookup(shape_id_t shape_id)
344344
{
345345
RUBY_ASSERT(shape_id != INVALID_SHAPE_ID);
346346

@@ -352,7 +352,7 @@ shape_id_t rb_generic_shape_id(VALUE obj);
352352
#endif
353353

354354
RUBY_FUNC_EXPORTED shape_id_t
355-
RB_OBJ_SHAPE_ID(VALUE obj)
355+
rb_obj_shape_id(VALUE obj)
356356
{
357357
if (RB_SPECIAL_CONST_P(obj)) {
358358
return SPECIAL_CONST_SHAPE_ID;
@@ -388,12 +388,6 @@ rb_shape_depth(shape_id_t shape_id)
388388
return depth;
389389
}
390390

391-
rb_shape_t *
392-
RB_OBJ_SHAPE(VALUE obj)
393-
{
394-
return RSHAPE(RB_OBJ_SHAPE_ID(obj));
395-
}
396-
397391
static rb_shape_t *
398392
shape_alloc(void)
399393
{
@@ -641,7 +635,7 @@ remove_shape_recursive(rb_shape_t *shape, ID id, rb_shape_t **removed_shape)
641635
bool
642636
rb_shape_transition_remove_ivar(VALUE obj, ID id, VALUE *removed)
643637
{
644-
rb_shape_t *shape = RB_OBJ_SHAPE(obj);
638+
rb_shape_t *shape = rb_obj_shape(obj);
645639

646640
if (UNLIKELY(rb_shape_too_complex_p(shape))) {
647641
return false;
@@ -701,7 +695,7 @@ rb_shape_transition_frozen(VALUE obj)
701695
{
702696
RUBY_ASSERT(RB_OBJ_FROZEN(obj));
703697

704-
shape_id_t shape_id = RB_OBJ_SHAPE_ID(obj);
698+
shape_id_t shape_id = rb_obj_shape_id(obj);
705699
if (shape_id == ROOT_SHAPE_ID) {
706700
return SPECIAL_CONST_SHAPE_ID;
707701
}
@@ -741,7 +735,7 @@ shape_transition_too_complex(rb_shape_t *original_shape)
741735
shape_id_t
742736
rb_shape_transition_complex(VALUE obj)
743737
{
744-
rb_shape_t *original_shape = RB_OBJ_SHAPE(obj);
738+
rb_shape_t *original_shape = rb_obj_shape(obj);
745739
return rb_shape_id(shape_transition_too_complex(original_shape));
746740
}
747741

@@ -754,7 +748,7 @@ rb_shape_has_object_id(rb_shape_t *shape)
754748
rb_shape_t *
755749
rb_shape_object_id_shape(VALUE obj)
756750
{
757-
rb_shape_t* shape = RB_OBJ_SHAPE(obj);
751+
rb_shape_t* shape = rb_obj_shape(obj);
758752
RUBY_ASSERT(shape);
759753

760754
if (shape->flags & SHAPE_FL_HAS_OBJECT_ID) {
@@ -844,13 +838,13 @@ shape_get_next(rb_shape_t *shape, VALUE obj, ID id, bool emit_warnings)
844838
shape_id_t
845839
rb_shape_transition_add_ivar(VALUE obj, ID id)
846840
{
847-
return rb_shape_id(shape_get_next(RB_OBJ_SHAPE(obj), obj, id, true));
841+
return rb_shape_id(shape_get_next(rb_obj_shape(obj), obj, id, true));
848842
}
849843

850844
shape_id_t
851845
rb_shape_transition_add_ivar_no_warnings(VALUE obj, ID id)
852846
{
853-
return rb_shape_id(shape_get_next(RB_OBJ_SHAPE(obj), obj, id, false));
847+
return rb_shape_id(shape_get_next(rb_obj_shape(obj), obj, id, false));
854848
}
855849

856850
// Same as rb_shape_get_iv_index, but uses a provided valid shape id and index
@@ -1098,7 +1092,7 @@ rb_shape_rebuild_shape(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
10981092
RUBY_FUNC_EXPORTED bool
10991093
rb_shape_obj_too_complex_p(VALUE obj)
11001094
{
1101-
return rb_shape_too_complex_p(RB_OBJ_SHAPE(obj));
1095+
return rb_shape_too_complex_p(rb_obj_shape(obj));
11021096
}
11031097

11041098
bool
@@ -1261,7 +1255,7 @@ rb_shape_parent(VALUE self)
12611255
static VALUE
12621256
rb_shape_debug_shape(VALUE self, VALUE obj)
12631257
{
1264-
return rb_shape_t_to_rb_cShape(RB_OBJ_SHAPE(obj));
1258+
return rb_shape_t_to_rb_cShape(rb_obj_shape(obj));
12651259
}
12661260

12671261
static VALUE
@@ -1285,11 +1279,11 @@ rb_shape_exhaust(int argc, VALUE *argv, VALUE self)
12851279
return Qnil;
12861280
}
12871281

1288-
VALUE rb_obj_shape(rb_shape_t *shape);
1282+
static VALUE shape_to_h(rb_shape_t *shape);
12891283

12901284
static enum rb_id_table_iterator_result collect_keys_and_values(ID key, VALUE value, void *ref)
12911285
{
1292-
rb_hash_aset(*(VALUE *)ref, parse_key(key), rb_obj_shape((rb_shape_t *)value));
1286+
rb_hash_aset(*(VALUE *)ref, parse_key(key), shape_to_h((rb_shape_t *)value));
12931287
return ID_TABLE_CONTINUE;
12941288
}
12951289

@@ -1306,8 +1300,8 @@ static VALUE edges(struct rb_id_table* edges)
13061300
return hash;
13071301
}
13081302

1309-
VALUE
1310-
rb_obj_shape(rb_shape_t *shape)
1303+
static VALUE
1304+
shape_to_h(rb_shape_t *shape)
13111305
{
13121306
VALUE rb_shape = rb_hash_new();
13131307

@@ -1328,7 +1322,7 @@ rb_obj_shape(rb_shape_t *shape)
13281322
static VALUE
13291323
shape_transition_tree(VALUE self)
13301324
{
1331-
return rb_obj_shape(rb_shape_get_root_shape());
1325+
return shape_to_h(rb_shape_get_root_shape());
13321326
}
13331327

13341328
static VALUE

shape.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ RCLASS_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
149149
set_shape_id_in_flags(obj, shape_id);
150150
}
151151

152+
#define RSHAPE rb_shape_lookup
153+
152154
int32_t rb_shape_id_offset(void);
153155

154-
RUBY_FUNC_EXPORTED rb_shape_t *RSHAPE(shape_id_t shape_id);
155-
RUBY_FUNC_EXPORTED shape_id_t RB_OBJ_SHAPE_ID(VALUE obj);
156+
RUBY_FUNC_EXPORTED rb_shape_t *rb_shape_lookup(shape_id_t shape_id);
157+
RUBY_FUNC_EXPORTED shape_id_t rb_obj_shape_id(VALUE obj);
156158
shape_id_t rb_shape_get_next_iv_shape(shape_id_t shape_id, ID id);
157159
bool rb_shape_get_iv_index(rb_shape_t *shape, ID id, attr_index_t *value);
158160
bool rb_shape_get_iv_index_with_hint(shape_id_t shape_id, ID id, attr_index_t *value, shape_id_t *shape_id_hint);
@@ -161,7 +163,6 @@ bool rb_shape_too_complex_p(rb_shape_t *shape);
161163
bool rb_shape_id_too_complex_p(shape_id_t shape_id);
162164

163165
void rb_shape_set_shape(VALUE obj, rb_shape_t *shape);
164-
rb_shape_t *RB_OBJ_SHAPE(VALUE obj);
165166
shape_id_t rb_shape_transition_frozen(VALUE obj);
166167
shape_id_t rb_shape_transition_complex(VALUE obj);
167168
bool rb_shape_transition_remove_ivar(VALUE obj, ID id, VALUE *removed);
@@ -174,6 +175,12 @@ void rb_shape_free_all(void);
174175

175176
rb_shape_t *rb_shape_rebuild_shape(rb_shape_t *initial_shape, rb_shape_t *dest_shape);
176177

178+
static inline rb_shape_t *
179+
rb_obj_shape(VALUE obj)
180+
{
181+
return RSHAPE(rb_obj_shape_id(obj));
182+
}
183+
177184
static inline bool
178185
rb_shape_canonical_p(rb_shape_t *shape)
179186
{
@@ -224,7 +231,7 @@ ROBJECT_FIELDS_COUNT(VALUE obj)
224231
static inline uint32_t
225232
RBASIC_FIELDS_COUNT(VALUE obj)
226233
{
227-
return RSHAPE(RB_OBJ_SHAPE_ID(obj))->next_field_index;
234+
return RSHAPE(rb_obj_shape_id(obj))->next_field_index;
228235
}
229236

230237
shape_id_t rb_shape_traverse_from_new_root(shape_id_t initial_shape_id, shape_id_t orig_shape_id);
@@ -234,7 +241,7 @@ bool rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id);
234241
static inline bool
235242
rb_shape_obj_has_id(VALUE obj)
236243
{
237-
return rb_shape_has_object_id(RB_OBJ_SHAPE(obj));
244+
return rb_shape_has_object_id(rb_obj_shape(obj));
238245
}
239246

240247
// For ext/objspace

variable.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,8 @@ rb_obj_init_too_complex(VALUE obj, st_table *table)
15701570
{
15711571
// This method is meant to be called on newly allocated object.
15721572
RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj));
1573-
RUBY_ASSERT(rb_shape_canonical_p(RB_OBJ_SHAPE(obj)));
1574-
RUBY_ASSERT(RB_OBJ_SHAPE(obj)->next_field_index == 0);
1573+
RUBY_ASSERT(rb_shape_canonical_p(rb_obj_shape(obj)));
1574+
RUBY_ASSERT(rb_obj_shape(obj)->next_field_index == 0);
15751575

15761576
obj_transition_too_complex(obj, table);
15771577
}
@@ -1584,7 +1584,7 @@ rb_evict_fields_to_hash(VALUE obj)
15841584

15851585
RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj));
15861586

1587-
rb_shape_t *shape = RB_OBJ_SHAPE(obj);
1587+
rb_shape_t *shape = rb_obj_shape(obj);
15881588
st_table *table = st_init_numtable_with_size(shape->next_field_index);
15891589
rb_obj_copy_fields_to_hash_table(obj, table);
15901590
obj_transition_too_complex(obj, table);
@@ -1624,7 +1624,7 @@ general_ivar_set(VALUE obj, ID id, VALUE val, void *data,
16241624
.existing = true
16251625
};
16261626

1627-
rb_shape_t *current_shape = RB_OBJ_SHAPE(obj);
1627+
rb_shape_t *current_shape = rb_obj_shape(obj);
16281628

16291629
if (UNLIKELY(rb_shape_too_complex_p(current_shape))) {
16301630
goto too_complex;
@@ -1681,7 +1681,7 @@ general_field_set(VALUE obj, rb_shape_t *target_shape, VALUE val, void *data,
16811681
void (*transition_too_complex_func)(VALUE, void *),
16821682
st_table *(*too_complex_table_func)(VALUE, void *))
16831683
{
1684-
rb_shape_t *current_shape = RB_OBJ_SHAPE(obj);
1684+
rb_shape_t *current_shape = rb_obj_shape(obj);
16851685

16861686
if (UNLIKELY(rb_shape_too_complex_p(target_shape))) {
16871687
if (UNLIKELY(!rb_shape_too_complex_p(current_shape))) {
@@ -1964,7 +1964,7 @@ rb_vm_set_ivar_id(VALUE obj, ID id, VALUE val)
19641964
bool
19651965
rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id)
19661966
{
1967-
if (RB_OBJ_SHAPE_ID(obj) == shape_id) {
1967+
if (rb_obj_shape_id(obj) == shape_id) {
19681968
return false;
19691969
}
19701970

@@ -2119,7 +2119,7 @@ rb_ivar_defined(VALUE obj, ID id)
21192119
return Qtrue;
21202120
}
21212121
else {
2122-
return RBOOL(rb_shape_get_iv_index(RB_OBJ_SHAPE(obj), id, &index));
2122+
return RBOOL(rb_shape_get_iv_index(rb_obj_shape(obj), id, &index));
21232123
}
21242124
}
21252125

@@ -2206,7 +2206,7 @@ obj_fields_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg, b
22062206
.ivar_only = ivar_only,
22072207
};
22082208

2209-
rb_shape_t *shape = RB_OBJ_SHAPE(obj);
2209+
rb_shape_t *shape = rb_obj_shape(obj);
22102210
if (rb_shape_too_complex_p(shape)) {
22112211
rb_st_foreach(ROBJECT_FIELDS_HASH(obj), each_hash_iv, (st_data_t)&itr_data);
22122212
}
@@ -2218,7 +2218,7 @@ obj_fields_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg, b
22182218
static void
22192219
gen_fields_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg, bool ivar_only)
22202220
{
2221-
rb_shape_t *shape = RB_OBJ_SHAPE(obj);
2221+
rb_shape_t *shape = rb_obj_shape(obj);
22222222
struct gen_fields_tbl *fields_tbl;
22232223
if (!rb_gen_fields_tbl_get(obj, 0, &fields_tbl)) return;
22242224

@@ -2243,7 +2243,7 @@ class_fields_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
22432243
{
22442244
RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE));
22452245

2246-
rb_shape_t *shape = RB_OBJ_SHAPE(obj);
2246+
rb_shape_t *shape = rb_obj_shape(obj);
22472247
struct iv_itr_data itr_data = {
22482248
.obj = obj,
22492249
.arg = arg,
@@ -2276,7 +2276,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
22762276
goto clear;
22772277
}
22782278

2279-
rb_shape_t *src_shape = RB_OBJ_SHAPE(obj);
2279+
rb_shape_t *src_shape = rb_obj_shape(obj);
22802280

22812281
if (rb_gen_fields_tbl_get(obj, 0, &obj_fields_tbl)) {
22822282
if (gen_fields_tbl_count(obj, obj_fields_tbl) == 0)
@@ -2297,7 +2297,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
22972297
}
22982298

22992299
rb_shape_t *shape_to_set_on_dest = src_shape;
2300-
rb_shape_t *initial_shape = RB_OBJ_SHAPE(dest);
2300+
rb_shape_t *initial_shape = rb_obj_shape(dest);
23012301

23022302
if (!rb_shape_canonical_p(src_shape)) {
23032303
RUBY_ASSERT(initial_shape->type == SHAPE_ROOT);
@@ -4586,7 +4586,7 @@ rb_fields_tbl_copy(VALUE dst, VALUE src)
45864586
RUBY_ASSERT(rb_type(dst) == rb_type(src));
45874587
RUBY_ASSERT(RB_TYPE_P(dst, T_CLASS) || RB_TYPE_P(dst, T_MODULE));
45884588

4589-
RUBY_ASSERT(RB_OBJ_SHAPE(dst)->type == SHAPE_ROOT);
4589+
RUBY_ASSERT(rb_obj_shape(dst)->type == SHAPE_ROOT);
45904590
RUBY_ASSERT(!RCLASS_FIELDS(dst));
45914591

45924592
rb_ivar_foreach(src, tbl_copy_i, dst);

yjit/bindgen/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ fn main() {
9494
.allowlist_function("rb_bug")
9595

9696
// From shape.h
97-
.allowlist_function("RB_OBJ_SHAPE_ID")
98-
.allowlist_function("RSHAPE")
97+
.allowlist_function("rb_obj_shape_id")
98+
.allowlist_function("rb_shape_lookup")
9999
.allowlist_function("rb_shape_id_offset")
100100
.allowlist_function("rb_shape_get_iv_index")
101101
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")

0 commit comments

Comments
 (0)