@@ -461,7 +461,6 @@ rb_shape_alloc(ID edge_name, rb_shape_t *parent, enum shape_type type)
461461{
462462 rb_shape_t * shape = rb_shape_alloc_with_parent_id (edge_name , raw_shape_id (parent ));
463463 shape -> type = (uint8_t )type ;
464- shape -> flags = parent -> flags ;
465464 shape -> heap_index = parent -> heap_index ;
466465 shape -> capacity = parent -> capacity ;
467466 shape -> edges = 0 ;
@@ -510,8 +509,6 @@ rb_shape_alloc_new_child(ID id, rb_shape_t *shape, enum shape_type shape_type)
510509
511510 switch (shape_type ) {
512511 case SHAPE_OBJ_ID :
513- new_shape -> flags |= SHAPE_FL_HAS_OBJECT_ID ;
514- // fallthrough
515512 case SHAPE_IVAR :
516513 if (UNLIKELY (shape -> next_field_index >= shape -> capacity )) {
517514 RUBY_ASSERT (shape -> next_field_index == shape -> capacity );
@@ -753,18 +750,6 @@ rb_shape_transition_complex(VALUE obj)
753750 return ROOT_TOO_COMPLEX_SHAPE_ID | (original_shape_id & SHAPE_ID_FLAGS_MASK );
754751}
755752
756- static inline bool
757- shape_has_object_id (rb_shape_t * shape )
758- {
759- return shape -> flags & SHAPE_FL_HAS_OBJECT_ID ;
760- }
761-
762- bool
763- rb_shape_has_object_id (shape_id_t shape_id )
764- {
765- return shape_has_object_id (RSHAPE (shape_id ));
766- }
767-
768753shape_id_t
769754rb_shape_transition_object_id (VALUE obj )
770755{
@@ -773,7 +758,11 @@ rb_shape_transition_object_id(VALUE obj)
773758 rb_shape_t * shape = RSHAPE (original_shape_id );
774759 RUBY_ASSERT (shape );
775760
776- if (shape -> flags & SHAPE_FL_HAS_OBJECT_ID ) {
761+ if (rb_shape_has_object_id (original_shape_id )) {
762+ if (rb_shape_too_complex_p (original_shape_id )) {
763+ return ROOT_SHAPE_WITH_OBJ_ID | SHAPE_ID_FL_HAS_OBJECT_ID | SHAPE_ID_FL_TOO_COMPLEX ;
764+ }
765+
777766 while (shape -> type != SHAPE_OBJ_ID ) {
778767 shape = RSHAPE (shape -> parent_id );
779768 }
@@ -783,7 +772,7 @@ rb_shape_transition_object_id(VALUE obj)
783772 shape = get_next_shape_internal (shape , ruby_internal_object_id , SHAPE_OBJ_ID , & dont_care , true);
784773 }
785774 RUBY_ASSERT (shape );
786- return shape_id (shape , original_shape_id );
775+ return shape_id (shape , original_shape_id ) | SHAPE_ID_FL_HAS_OBJECT_ID ;
787776}
788777
789778/*
@@ -1203,8 +1192,7 @@ static VALUE
12031192shape_has_object_id_p (VALUE self )
12041193{
12051194 shape_id_t shape_id = NUM2INT (rb_struct_getmember (self , rb_intern ("id" )));
1206- rb_shape_t * shape = RSHAPE (shape_id );
1207- return RBOOL (shape_has_object_id (shape ));
1195+ return RBOOL (rb_shape_has_object_id (shape_id ));
12081196}
12091197
12101198static VALUE
@@ -1441,6 +1429,11 @@ Init_default_shapes(void)
14411429 GET_SHAPE_TREE ()-> root_shape = root ;
14421430 RUBY_ASSERT (raw_shape_id (GET_SHAPE_TREE ()-> root_shape ) == ROOT_SHAPE_ID );
14431431
1432+ rb_shape_t * root_with_obj_id = rb_shape_alloc_with_parent_id (0 , ROOT_SHAPE_ID );
1433+ root_with_obj_id -> type = SHAPE_OBJ_ID ;
1434+ root_with_obj_id -> heap_index = 0 ;
1435+ RUBY_ASSERT (raw_shape_id (root_with_obj_id ) == ROOT_SHAPE_WITH_OBJ_ID );
1436+
14441437 // Make shapes for T_OBJECT
14451438 size_t * sizes = rb_gc_heap_sizes ();
14461439 for (int i = 0 ; sizes [i ] > 0 ; i ++ ) {
0 commit comments