8000 Get rid of frozen shapes by casperisfine · Pull Request #13289 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Get rid of frozen shapes #13289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
byroot committed Jun 3, 2025
commit a483cdd1ac83f90e37aaeee7cc18917c6dce35c0
3 changes: 0 additions & 3 deletions ext/objspace/objspace_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,6 @@ shape_id_i(shape_id_t shape_id, void *data)
dump_append(dc, ",\"edge_name\":");
dump_append_id(dc, shape->edge_name);

break;
case SHAPE_FROZEN:
dump_append(dc, ", \"shape_type\":\"FROZEN\"");
break;
case SHAPE_T_OBJECT:
dump_append(dc, ", \"shape_type\":\"T_OBJECT\"");
Expand Down
1 change: 0 additions & 1 deletion internal/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ static inline void RCLASS_WRITE_CLASSPATH(VALUE klass, VALUE classpath, bool per
#define RCLASS_PRIME_CLASSEXT_WRITABLE FL_USER2
#define RCLASS_IS_INITIALIZED FL_USER3
// 3 is RMODULE_IS_REFINEMENT for RMODULE
// 4-19: SHAPE_FLAG_MASK

/* class.c */
rb_classext_t * rb_class_duplicate_classext(rb_classext_t *orig, VALUE obj, const rb_namespace_t *ns);
Expand Down
16 changes: 2 additions & 14 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,7 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)

if (RB_OBJ_FROZEN(obj)) {
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
if (!rb_shape_obj_too_complex_p(clone) && rb_shape_too_complex_p(next_shape_id)) {
rb_evict_ivars_to_hash(clone);
}
else {
rb_obj_set_shape_id(clone, next_shape_id);
}
rb_obj_set_shape_id(clone, next_shape_id);
}
break;
case Qtrue: {
Expand All @@ -518,14 +513,7 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
RBASIC(clone)->flags |= FL_FREEZE;
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
// If we're out of shapes, but we want to freeze, then we need to
// evacuate this clone to a hash
if (!rb_shape_obj_too_complex_p(clone) && rb_shape_too_complex_p(next_shape_id)) {
rb_evict_ivars_to_hash(clone);
}
else {
rb_obj_set_shape_id(clone, next_shape_id);
}
rb_obj_set_shape_id(clone, next_shape_id);
break;
}
case Qfalse: {
Expand Down
Loading
0