Skip to content

Commit 625d6a9

Browse files
committed
Get rid of frozen shapes.
Instead `shape_id_t` higher bits contain flags, and the first one tells whether the shape is frozen. This has multiple benefits: - Can check if a shape is frozen with a single bit check instead of dereferencing a pointer. - Guarantees it is always possible to transition to frozen. - This allow reclaiming `FL_FREEZE` (not done yet). The downside is you have to be careful to preserve these flags when transitioning.
1 parent 6b7e339 commit 625d6a9

File tree

7 files changed

+95
-149
lines changed

7 files changed

+95
-149
lines changed

ext/objspace/objspace_dump.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,6 @@ shape_id_i(shape_id_t shape_id, void *data)
817817
dump_append(dc, ",\"edge_name\":");
818818
dump_append_id(dc, shape->edge_name);
819819

820-
break;
821-
case SHAPE_FROZEN:
822-
dump_append(dc, ", \"shape_type\":\"FROZEN\"");
823820
break;
824821
case SHAPE_T_OBJECT:
825822
dump_append(dc, ", \"shape_type\":\"T_OBJECT\"");

internal/class.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ static inline void RCLASS_WRITE_CLASSPATH(VALUE klass, VALUE classpath, bool per
297297
#define RCLASS_PRIME_CLASSEXT_WRITABLE FL_USER2
298298
#define RCLASS_IS_INITIALIZED FL_USER3
299299
// 3 is RMODULE_IS_REFINEMENT for RMODULE
300-
// 4-19: SHAPE_FLAG_MASK
301300

302301
/* class.c */
303302
rb_classext_t * rb_class_duplicate_classext(rb_classext_t *orig, VALUE obj, const rb_namespace_t *ns);

object.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,7 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
496496

497497
if (RB_OBJ_FROZEN(obj)) {
498498
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
499-
if (!rb_shape_obj_too_complex_p(clone) && rb_shape_too_complex_p(next_shape_id)) {
500-
rb_evict_ivars_to_hash(clone);
501-
}
502-
else {
503-
rb_obj_set_shape_id(clone, next_shape_id);
504-
}
499+
rb_obj_set_shape_id(clone, next_shape_id);
505500
}
506501
break;
507502
case Qtrue: {
@@ -518,14 +513,7 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
518513
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
519514
RBASIC(clone)->flags |= FL_FREEZE;
520515
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
521-
// If we're out of shapes, but we want to freeze, then we need to
522-
// evacuate this clone to a hash
523-
if (!rb_shape_obj_too_complex_p(clone) && rb_shape_too_complex_p(next_shape_id)) {
524-
rb_evict_ivars_to_hash(clone);
525-
}
526-
else {
527-
rb_obj_set_shape_id(clone, next_shape_id);
528-
}
516+
rb_obj_set_shape_id(clone, next_shape_id);
529517
break;
530518
}
531519
case Qfalse: {

0 commit comments

Comments
 (0)