mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Dynamically derive base_label in iseq
base_label isn't used very often in iseq and we can dynamically derive it from the label (of the current iseq or the local_iseq). We can remove this field to save 8 bytes.
This commit is contained in:
1 parent
e947cbd199
commit
fcbdc2072d
6 files changed
+14
-17
Notes:
git
2026-08-29 05:17:35 +00:00
No files matched your search
@@ -12680,7 +12680,7 @@ typedef uint32_t ibf_offset_t;
|
||||
|
||||
#define IBF_MAJOR_VERSION ISEQ_MAJOR_VERSION
|
||||
#ifdef RUBY_DEVEL
|
||||
#define IBF_DEVEL_VERSION 7
|
||||
#define IBF_DEVEL_VERSION 8
|
||||
#define IBF_MINOR_VERSION (ISEQ_MINOR_VERSION * 10000 + IBF_DEVEL_VERSION)
|
||||
#else
|
||||
#define IBF_MINOR_VERSION ISEQ_MINOR_VERSION
|
||||
@@ -13774,7 +13774,6 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
||||
const struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
|
||||
|
||||
const VALUE location_pathobj_index = ibf_dump_object(dump, body->location.pathobj); /* TODO: freeze */
|
||||
const VALUE location_base_label_index = ibf_dump_object(dump, body->location.base_label);
|
||||
const VALUE location_label_index = ibf_dump_object(dump, body->location.label);
|
||||
|
||||
#if IBF_ISEQ_ENABLE_LOCAL_BUFFER
|
||||
@@ -13856,7 +13855,6 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
||||
ibf_dump_write_small_value(dump, IBF_BODY_OFFSET(param_opt_table_offset));
|
||||
ibf_dump_write_small_value(dump, param_keyword_offset);
|
||||
ibf_dump_write_small_value(dump, location_pathobj_index);
|
||||
ibf_dump_write_small_value(dump, location_base_label_index);
|
||||
ibf_dump_write_small_value(dump, location_label_index);
|
||||
ibf_dump_write_small_value(dump, body->location.first_lineno);
|
||||
ibf_dump_write_small_value(dump, body->location.node_id);
|
||||
@@ -13972,7 +13970,6 @@ ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset)
|
||||
const ibf_offset_t param_opt_table_offset = (ibf_offset_t)IBF_BODY_OFFSET(ibf_load_small_value(load, &reading_pos));
|
||||
const ibf_offset_t param_keyword_offset = (ibf_offset_t)ibf_load_small_value(load, &reading_pos);
|
||||
const VALUE location_pathobj_index = ibf_load_small_value(load, &reading_pos);
|
||||
const VALUE location_base_label_index = ibf_load_small_value(load, &reading_pos);
|
||||
const VALUE location_label_index = ibf_load_small_value(load, &reading_pos);
|
||||
const int location_first_lineno = (int)ibf_load_small_value(load, &reading_pos);
|
||||
const int location_node_id = (int)ibf_load_small_value(load, &reading_pos);
|
||||
@@ -14137,7 +14134,6 @@ ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset)
|
||||
load->current_buffer = &load->global_buffer;
|
||||
#endif
|
||||
|
||||
RB_OBJ_WRITE(iseq, &load_body->location.base_label, ibf_load_location_str(load, location_base_label_index));
|
||||
RB_OBJ_WRITE(iseq, &load_body->location.label, ibf_load_location_str(load, location_label_index));
|
||||
|
||||
#if IBF_ISEQ_ENABLE_LOCAL_BUFFER
|
||||
|
||||
@@ -415,7 +415,6 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating)
|
||||
struct rb_iseq_variable *v = ISEQ_VARIABLE(iseq);
|
||||
if (v) rb_gc_mark_and_move(&v->script_lines);
|
||||
rb_gc_mark_and_move(&body->location.label);
|
||||
rb_gc_mark_and_move(&body->location.base_label);
|
||||
rb_gc_mark_and_move(&body->location.pathobj);
|
||||
if (body->local_iseq) rb_gc_mark_and_move_ptr(&body->local_iseq);
|
||||
if (body->parent_iseq) rb_gc_mark_and_move_ptr(&body->parent_iseq);
|
||||
@@ -711,7 +710,6 @@ iseq_location_setup(rb_iseq_t *iseq, VALUE name, VALUE path, VALUE realpath, int
|
||||
|
||||
rb_iseq_pathobj_set(iseq, path, realpath);
|
||||
RB_OBJ_WRITE(iseq, &loc->label, name);
|
||||
RB_OBJ_WRITE(iseq, &loc->base_label, name);
|
||||
loc->first_lineno = first_lineno;
|
||||
|
||||
if (ISEQ_BODY(iseq)->local_iseq == iseq && rb_streql_lit(name, "initialize")) {
|
||||
@@ -803,9 +801,6 @@ prepare_iseq_build(rb_iseq_t *iseq,
|
||||
|
||||
name = rb_fstring(name);
|
||||
iseq_location_setup(iseq, name, path, realpath, first_lineno, code_location, node_id);
|
||||
if (iseq != body->local_iseq) {
|
||||
RB_OBJ_WRITE(iseq, &body->location.base_label, ISEQ_BODY(body->local_iseq)->location.label);
|
||||
}
|
||||
ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
|
||||
if (body->variable) {
|
||||
body->variable->flip_count = 0;
|
||||
@@ -1619,7 +1614,15 @@ rb_iseq_label(const rb_iseq_t *iseq)
|
||||
VALUE
|
||||
rb_iseq_base_label(const rb_iseq_t *iseq)
|
||||
{
|
||||
return ISEQ_BODY(iseq)->location.base_label;
|
||||
const struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
|
||||
const rb_iseq_t *local_iseq = body->local_iseq;
|
||||
|
||||
if (local_iseq == NULL || local_iseq == iseq) {
|
||||
return body->location.label;
|
||||
}
|
||||
else {
|
||||
return ISEQ_BODY(rb_iseq_check(local_iseq))->location.label;
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
@@ -1634,7 +1637,7 @@ rb_iseq_method_name(const rb_iseq_t *iseq)
|
||||
struct rb_iseq_constant_body *const body = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq);
|
||||
|
||||
if (body->type == ISEQ_TYPE_METHOD) {
|
||||
return body->location.base_label;
|
||||
return body->location.label;
|
||||
}
|
||||
else {
|
||||
return Qnil;
|
||||
|
||||
+1
-1
@@ -374,7 +374,7 @@ location_base_label(rb_backtrace_location_t *loc)
|
||||
return rb_id2str(loc->cme->def->original_id);
|
||||
}
|
||||
|
||||
return ISEQ_BODY(loc->iseq)->location.base_label;
|
||||
return rb_iseq_base_label(loc->iseq);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -338,7 +338,6 @@ struct rb_execution_context_struct;
|
||||
|
||||
typedef struct rb_iseq_location_struct {
|
||||
VALUE pathobj; /* String (path) or Array [path, realpath]. Frozen. */
|
||||
VALUE base_label; /* String */
|
||||
VALUE label; /* String */
|
||||
int first_lineno;
|
||||
int node_id;
|
||||
|
||||
+1
-1
@@ -3160,7 +3160,7 @@ warn_unused_block(const rb_callable_method_entry_t *cme, const rb_iseq_t *iseq,
|
||||
}
|
||||
else if (RTEST(ruby_verbose) || strict_unused_block) {
|
||||
VALUE m_loc = rb_method_entry_location((const rb_method_entry_t *)cme);
|
||||
VALUE name = rb_gen_method_name(cme->defined_class, ISEQ_BODY(iseq)->location.base_label);
|
||||
VALUE name = rb_gen_method_name(cme->defined_class, rb_iseq_base_label(iseq));
|
||||
|
||||
if (!NIL_P(m_loc)) {
|
||||
rb_warn("the block passed to '%"PRIsVALUE"' defined at %"PRIsVALUE":%"PRIsVALUE" may be ignored",
|
||||
|
||||
Generated
+1
-2
@@ -619,7 +619,6 @@ pub struct iseq_inline_storage_entry {
|
||||
#[repr(C)]
|
||||
pub struct rb_iseq_location_struct {
|
||||
pub pathobj: VALUE,
|
||||
pub base_label: VALUE,
|
||||
pub label: VALUE,
|
||||
pub first_lineno: ::std::os::raw::c_int,
|
||||
pub node_id: ::std::os::raw::c_int,
|
||||
@@ -2099,7 +2098,7 @@ pub struct zjit_jit_frame {
|
||||
pub stack: __IncompleteArrayField<VALUE>,
|
||||
}
|
||||
pub const ISEQ_BODY_OFFSET_PARAM: zjit_struct_offsets = 16;
|
||||
pub const ISEQ_BODY_OFFSET_OUTER_VARIABLES: zjit_struct_offsets = 248;
|
||||
pub const ISEQ_BODY_OFFSET_OUTER_VARIABLES: zjit_struct_offsets = 240;
|
||||
pub const RUBY_OFFSET_THREAD_RACTOR: zjit_struct_offsets = 24;
|
||||
pub type zjit_struct_offsets = u32;
|
||||
#[repr(C)]
|
||||
|
||||
Reference in new issue
Block a user