diff options
author | Jean Boussier <[email protected]> | 2025-05-08 20:47:51 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-05-09 10:22:51 +0200 |
commit | c9b08882b796c9d3a5f92d57d0b4f866fb24f3ac (patch) | |
tree | 2012f42eea9fc420e656566be1716feec7fe85b1 | |
parent | e0200cfba03bf7d23b6e298c35ca2636cbbdbd91 (diff) |
Refactor `rb_shape_get_next` to return an ID
Also rename it, and change parameters to be consistent with
other transition functions.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13283
-rw-r--r-- | shape.c | 12 | ||||
-rw-r--r-- | shape.h | 5 | ||||
-rw-r--r-- | variable.c | 3 | ||||
-rw-r--r-- | yjit/bindgen/src/main.rs | 2 | ||||
-rw-r--r-- | yjit/src/codegen.rs | 4 | ||||
-rw-r--r-- | yjit/src/cruby_bindings.inc.rs | 6 | ||||
-rw-r--r-- | zjit/bindgen/src/main.rs | 2 | ||||
-rw-r--r-- | zjit/src/cruby_bindings.inc.rs | 6 |
8 files changed, 17 insertions, 23 deletions
@@ -857,16 +857,16 @@ shape_get_next(rb_shape_t *shape, VALUE obj, ID id, bool emit_warnings) return new_shape; } -rb_shape_t * -rb_shape_get_next(rb_shape_t *shape, VALUE obj, ID id) +shape_id_t +rb_shape_transition_add_ivar(VALUE obj, ID id) { - return shape_get_next(shape, obj, id, true); + return rb_shape_id(shape_get_next(rb_shape_get_shape(obj), obj, id, true)); } -rb_shape_t * -rb_shape_get_next_no_warnings(rb_shape_t *shape, VALUE obj, ID id) +shape_id_t +rb_shape_transition_add_ivar_no_warnings(VALUE obj, ID id) { - return shape_get_next(shape, obj, id, false); + return rb_shape_id(shape_get_next(rb_shape_get_shape(obj), obj, id, false)); } // Same as rb_shape_get_iv_index, but uses a provided valid shape id and index @@ -168,8 +168,9 @@ bool rb_shape_frozen_shape_p(rb_shape_t *shape); shape_id_t rb_shape_transition_frozen(VALUE obj); shape_id_t rb_shape_transition_complex(VALUE obj); bool rb_shape_transition_remove_ivar(VALUE obj, ID id, VALUE *removed); -rb_shape_t *rb_shape_get_next(rb_shape_t *shape, VALUE obj, ID id); -rb_shape_t *rb_shape_get_next_no_warnings(rb_shape_t *shape, VALUE obj, ID id); +shape_id_t rb_shape_transition_add_ivar(VALUE obj, ID id); +shape_id_t rb_shape_transition_add_ivar_no_warnings(VALUE obj, ID id); + rb_shape_t *rb_shape_object_id_shape(VALUE obj); bool rb_shape_has_object_id(rb_shape_t *shape); attr_index_t rb_shape_object_id_index(rb_shape_t *shape); diff --git a/variable.c b/variable.c index 92206e4b11..51fd9c48ba 100644 --- a/variable.c +++ b/variable.c @@ -1639,7 +1639,8 @@ general_ivar_set(VALUE obj, ID id, VALUE val, void *data, rb_raise(rb_eArgError, "too many instance variables"); } - rb_shape_t *next_shape = rb_shape_get_next(current_shape, obj, id); + shape_id_t next_shape_id = rb_shape_transition_add_ivar(obj, id); + rb_shape_t *next_shape = RSHAPE(next_shape_id); if (UNLIKELY(rb_shape_too_complex_p(next_shape))) { transition_too_complex_func(obj, data); goto too_complex; diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs index 73e876cfc9..cae721d06f 100644 --- a/yjit/bindgen/src/main.rs +++ b/yjit/bindgen/src/main.rs @@ -98,7 +98,7 @@ fn main() { .allowlist_function("RSHAPE") .allowlist_function("rb_shape_id_offset") .allowlist_function("rb_shape_get_iv_index") - .allowlist_function("rb_shape_get_next_no_warnings") + .allowlist_function("rb_shape_transition_add_ivar_no_warnings") .allowlist_function("rb_shape_id") .allowlist_function("rb_shape_obj_too_complex_p") .allowlist_function("rb_shape_too_complex_p") diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 08e8c68404..cfae1b6c1d 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -3112,8 +3112,8 @@ fn gen_set_ivar( let mut new_shape_too_complex = false; let new_shape = if !shape_too_complex && receiver_t_object && ivar_index.is_none() { let current_shape = comptime_receiver.shape_of(); - let next_shape = unsafe { rb_shape_get_next_no_warnings(current_shape, comptime_receiver, ivar_name) }; - let next_shape_id = unsafe { rb_shape_id(next_shape) }; + let next_shape_id = unsafe { rb_shape_transition_add_ivar_no_warnings(comptime_receiver, ivar_name) }; + let next_shape = unsafe { RSHAPE(next_shape_id) }; // If the VM ran out of shapes, or this class generated too many leaf, // it may be de-optimized into OBJ_TOO_COMPLEX_SHAPE (hash-table). diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs index d595b6bef7..f673be1739 100644 --- a/yjit/src/cruby_bindings.inc.rs +++ b/yjit/src/cruby_bindings.inc.rs @@ -1093,11 +1093,7 @@ extern "C" { pub fn rb_shape_get_iv_index(shape: *mut rb_shape_t, id: ID, value: *mut attr_index_t) -> bool; pub fn rb_shape_obj_too_complex_p(obj: VALUE) -> bool; pub fn rb_shape_too_complex_p(shape: *mut rb_shape_t) -> bool; - pub fn rb_shape_get_next_no_warnings( - shape: *mut rb_shape_t, - obj: VALUE, - id: ID, - ) -> *mut rb_shape_t; + pub fn rb_shape_transition_add_ivar_no_warnings(obj: VALUE, id: ID) -> shape_id_t; pub fn rb_shape_id(shape: *mut rb_shape_t) -> shape_id_t; pub fn rb_gvar_get(arg1: ID) -> VALUE; pub fn rb_gvar_set(arg1: ID, arg2: VALUE) -> VALUE; diff --git a/zjit/bindgen/src/main.rs b/zjit/bindgen/src/main.rs index e01acfe61f..e6930f5b9b 100644 --- a/zjit/bindgen/src/main.rs +++ b/zjit/bindgen/src/main.rs @@ -111,7 +111,7 @@ fn main() { .allowlist_function("RSHAPE") .allowlist_function("rb_shape_id_offset") .allowlist_function("rb_shape_get_iv_index") - .allowlist_function("rb_shape_get_next_no_warnings") + .allowlist_function("rb_shape_transition_add_ivar_no_warnings") .allowlist_function("rb_shape_id") .allowlist_function("rb_shape_obj_too_complex_p") .allowlist_var("SHAPE_ID_NUM_BITS") diff --git a/zjit/src/cruby_bindings.inc.rs b/zjit/src/cruby_bindings.inc.rs index 4d716ecadc..2bdb5553ef 100644 --- a/zjit/src/cruby_bindings.inc.rs +++ b/zjit/src/cruby_bindings.inc.rs @@ -872,11 +872,7 @@ unsafe extern "C" { pub fn rb_shape_get_shape_id(obj: VALUE) -> shape_id_t; pub fn rb_shape_get_iv_index(shape: *mut rb_shape_t, id: ID, value: *mut attr_index_t) -> bool; pub fn rb_shape_obj_too_complex_p(obj: VALUE) -> bool; - pub fn rb_shape_get_next_no_warnings( - shape: *mut rb_shape_t, - obj: VALUE, - id: ID, - ) -> *mut rb_shape_t; + pub fn rb_shape_transition_add_ivar_no_warnings(obj: VALUE, id: ID) -> shape_id_t; pub fn rb_shape_id(shape: *mut rb_shape_t) -> shape_id_t; pub fn rb_gvar_get(arg1: ID) -> VALUE; pub fn rb_gvar_set(arg1: ID, arg2: VALUE) -> VALUE; |