mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Refactor raw accesses to rb_shape_t.capacity
This commit is contained in:
parent
0b07d2a1e3
commit
4e39580992
Notes:
git
2025-06-05 20:06:29 +00:00
12 changed files with 51 additions and 32 deletions
|
@ -101,6 +101,7 @@ fn main() {
|
|||
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")
|
||||
.allowlist_function("rb_yjit_shape_obj_too_complex_p")
|
||||
.allowlist_function("rb_yjit_shape_too_complex_p")
|
||||
.allowlist_function("rb_yjit_shape_capacity")
|
||||
.allowlist_var("SHAPE_ID_NUM_BITS")
|
||||
|
||||
// From ruby/internal/intern/object.h
|
||||
|
|
|
@ -3119,7 +3119,7 @@ fn gen_set_ivar(
|
|||
// The current shape doesn't contain this iv, we need to transition to another shape.
|
||||
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 current_shape_id = comptime_receiver.shape_id_of();
|
||||
let next_shape_id = unsafe { rb_shape_transition_add_ivar_no_warnings(comptime_receiver, ivar_name) };
|
||||
|
||||
// If the VM ran out of shapes, or this class generated too many leaf,
|
||||
|
@ -3128,18 +3128,20 @@ fn gen_set_ivar(
|
|||
if new_shape_too_complex {
|
||||
Some((next_shape_id, None, 0_usize))
|
||||
} else {
|
||||
let next_shape = unsafe { rb_shape_lookup(next_shape_id) };
|
||||
let current_capacity = unsafe { (*current_shape).capacity };
|
||||
let current_shape = unsafe { rb_shape_lookup(current_shape_id) };
|
||||
|
||||
let current_capacity = unsafe { rb_yjit_shape_capacity(current_shape_id) };
|
||||
let next_capacity = unsafe { rb_yjit_shape_capacity(next_shape_id) };
|
||||
|
||||
// If the new shape has a different capacity, or is TOO_COMPLEX, we'll have to
|
||||
// reallocate it.
|
||||
let needs_extension = unsafe { (*current_shape).capacity != (*next_shape).capacity };
|
||||
let needs_extension = next_capacity != current_capacity;
|
||||
|
||||
// We can write to the object, but we need to transition the shape
|
||||
let ivar_index = unsafe { (*current_shape).next_field_index } as usize;
|
||||
|
||||
let needs_extension = if needs_extension {
|
||||
Some((current_capacity, unsafe { (*next_shape).capacity }))
|
||||
Some((current_capacity, next_capacity))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
3
yjit/src/cruby_bindings.inc.rs
generated
3
yjit/src/cruby_bindings.inc.rs
generated
|
@ -1139,7 +1139,7 @@ extern "C" {
|
|||
pub fn rb_shape_transition_add_ivar_no_warnings(obj: VALUE, id: ID) -> shape_id_t;
|
||||
pub fn rb_gvar_get(arg1: ID) -> VALUE;
|
||||
pub fn rb_gvar_set(arg1: ID, arg2: VALUE) -> VALUE;
|
||||
pub fn rb_ensure_iv_list_size(obj: VALUE, len: u32, newsize: u32);
|
||||
pub fn rb_ensure_iv_list_size(obj: VALUE, current_len: u32, newsize: u32);
|
||||
pub fn rb_vm_barrier();
|
||||
pub fn rb_str_byte_substr(str_: VALUE, beg: VALUE, len: VALUE) -> VALUE;
|
||||
pub fn rb_str_substr_two_fixnums(
|
||||
|
@ -1264,6 +1264,7 @@ extern "C" {
|
|||
pub fn rb_object_shape_count() -> VALUE;
|
||||
pub fn rb_yjit_shape_too_complex_p(shape_id: shape_id_t) -> bool;
|
||||
pub fn rb_yjit_shape_obj_too_complex_p(obj: VALUE) -> bool;
|
||||
pub fn rb_yjit_shape_capacity(shape_id: shape_id_t) -> attr_index_t;
|
||||
pub fn rb_yjit_assert_holding_vm_lock();
|
||||
pub fn rb_yjit_sendish_sp_pops(ci: *const rb_callinfo) -> usize;
|
||||
pub fn rb_yjit_invokeblock_sp_pops(ci: *const rb_callinfo) -> usize;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue