Rename RB_OBJ_SHAPE -> rb_obj_shape

As well as `RB_OBJ_SHAPE_ID` -> `rb_obj_shape_id`
and `RSHAPE` is now a simple alias for `rb_shape_lookup`.

I tried to turn all these into `static inline` but I'm having
trouble with `RUBY_EXTERN rb_shape_tree_t *rb_shape_tree_ptr;`
not being exposed as I'd expect.
This commit is contained in:
Jean Boussier 2025-05-09 08:58:07 +02:00
parent 0b81359b3f
commit ea77250847
Notes: git 2025-05-09 08:23:05 +00:00
14 changed files with 68 additions and 67 deletions

View file

@ -94,8 +94,8 @@ fn main() {
.allowlist_function("rb_bug")
// From shape.h
.allowlist_function("RB_OBJ_SHAPE_ID")
.allowlist_function("RSHAPE")
.allowlist_function("rb_obj_shape_id")
.allowlist_function("rb_shape_lookup")
.allowlist_function("rb_shape_id_offset")
.allowlist_function("rb_shape_get_iv_index")
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")

View file

@ -2894,7 +2894,7 @@ fn gen_get_ivar(
let ivar_index = unsafe {
let shape_id = comptime_receiver.shape_id_of();
let shape = RSHAPE(shape_id);
let shape = rb_shape_lookup(shape_id);
let mut ivar_index: u32 = 0;
if rb_shape_get_iv_index(shape, ivar_name, &mut ivar_index) {
Some(ivar_index as usize)
@ -2909,7 +2909,7 @@ fn gen_get_ivar(
// Compile time self is embedded and the ivar index lands within the object
let embed_test_result = unsafe { FL_TEST_RAW(comptime_receiver, VALUE(ROBJECT_EMBED.as_usize())) != VALUE(0) };
let expected_shape = unsafe { RB_OBJ_SHAPE_ID(comptime_receiver) };
let expected_shape = unsafe { rb_obj_shape_id(comptime_receiver) };
let shape_id_offset = unsafe { rb_shape_id_offset() };
let shape_opnd = Opnd::mem(SHAPE_ID_NUM_BITS as u8, recv, shape_id_offset);
@ -3097,7 +3097,7 @@ fn gen_set_ivar(
let shape_too_complex = comptime_receiver.shape_too_complex();
let ivar_index = if !shape_too_complex {
let shape_id = comptime_receiver.shape_id_of();
let shape = unsafe { RSHAPE(shape_id) };
let shape = unsafe { rb_shape_lookup(shape_id) };
let mut ivar_index: u32 = 0;
if unsafe { rb_shape_get_iv_index(shape, ivar_name, &mut ivar_index) } {
Some(ivar_index as usize)
@ -3113,7 +3113,7 @@ fn gen_set_ivar(
let new_shape = if !shape_too_complex && receiver_t_object && ivar_index.is_none() {
let current_shape = comptime_receiver.shape_of();
let next_shape_id = unsafe { rb_shape_transition_add_ivar_no_warnings(comptime_receiver, ivar_name) };
let next_shape = unsafe { RSHAPE(next_shape_id) };
let next_shape = unsafe { rb_shape_lookup(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).
@ -3187,7 +3187,7 @@ fn gen_set_ivar(
// Upgrade type
guard_object_is_heap(asm, recv, recv_opnd, Counter::setivar_not_heap);
let expected_shape = unsafe { RB_OBJ_SHAPE_ID(comptime_receiver) };
let expected_shape = unsafe { rb_obj_shape_id(comptime_receiver) };
let shape_id_offset = unsafe { rb_shape_id_offset() };
let shape_opnd = Opnd::mem(SHAPE_ID_NUM_BITS as u8, recv, shape_id_offset);
@ -3387,7 +3387,7 @@ fn gen_definedivar(
let shape_id = comptime_receiver.shape_id_of();
let ivar_exists = unsafe {
let shape = RSHAPE(shape_id);
let shape = rb_shape_lookup(shape_id);
let mut ivar_index: u32 = 0;
rb_shape_get_iv_index(shape, ivar_name, &mut ivar_index)
};

View file

@ -445,12 +445,12 @@ impl VALUE {
}
pub fn shape_id_of(self) -> u32 {
unsafe { RB_OBJ_SHAPE_ID(self) }
unsafe { rb_obj_shape_id(self) }
}
pub fn shape_of(self) -> *mut rb_shape {
unsafe {
let shape = RSHAPE(self.shape_id_of());
let shape = rb_shape_lookup(self.shape_id_of());
if shape.is_null() {
panic!("Shape should not be null");

View file

@ -1088,8 +1088,8 @@ extern "C" {
pub fn rb_obj_info(obj: VALUE) -> *const ::std::os::raw::c_char;
pub fn rb_ec_stack_check(ec: *mut rb_execution_context_struct) -> ::std::os::raw::c_int;
pub fn rb_shape_id_offset() -> i32;
pub fn RSHAPE(shape_id: shape_id_t) -> *mut rb_shape_t;
pub fn RB_OBJ_SHAPE_ID(obj: VALUE) -> shape_id_t;
pub fn rb_shape_lookup(shape_id: shape_id_t) -> *mut rb_shape_t;
pub fn rb_obj_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_too_complex_p(shape: *mut rb_shape_t) -> bool;