ruby-changes:62111
From: Koichi <ko1@a...>
Date: Fri, 3 Jul 2020 16:56:57 +0900 (JST)
Subject: [ruby-changes:62111] a0f12a0258 (master): Use ID instead of GENTRY for gvars. (#3278)
https://git.ruby-lang.org/ruby.git/commit/?id=a0f12a0258 From a0f12a0258e4020bd657ee80b7d8f22bd33ea223 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Fri, 3 Jul 2020 16:56:44 +0900 Subject: Use ID instead of GENTRY for gvars. (#3278) Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development. diff --git a/compile.c b/compile.c index ccb079c..dfa3802 100644 --- a/compile.c +++ b/compile.c @@ -2318,13 +2318,6 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) https://github.com/ruby/ruby/blob/trunk/compile.c#L2318 case TS_ID: /* ID */ generated_iseq[code_index + 1 + j] = SYM2ID(operands[j]); break; - case TS_GENTRY: - { - struct rb_global_entry *entry = - (struct rb_global_entry *)(operands[j] & (~1)); - generated_iseq[code_index + 1 + j] = (VALUE)entry; - } - break; case TS_FUNCPTR: generated_iseq[code_index + 1 + j] = operands[j]; break; @@ -4875,7 +4868,7 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4868 case NODE_GVAR: ADD_INSN(ret, line, putnil); ADD_INSN3(ret, line, defined, INT2FIX(DEFINED_GVAR), - ID2SYM(node->nd_entry->id), needstr); + ID2SYM(node->nd_entry), needstr); return; case NODE_CVAR: @@ -5262,7 +5255,7 @@ compile_named_capture_assign(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE https://github.com/ruby/ruby/blob/trunk/compile.c#L5255 LABEL *fail_label = NEW_LABEL(line), *end_label = NEW_LABEL(line); #if !(defined(NAMED_CAPTURE_BY_SVAR) && NAMED_CAPTURE_BY_SVAR-0) - ADD_INSN1(ret, line, getglobal, ((VALUE)rb_global_entry(idBACKREF) | 1)); + ADD_INSN1(ret, line, getglobal, ID2SYM(idBACKREF)); #else ADD_INSN2(ret, line, getspecial, INT2FIX(1) /* '~' */, INT2FIX(0)); #endif @@ -7599,8 +7592,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in https://github.com/ruby/ruby/blob/trunk/compile.c#L7592 if (!popped) { ADD_INSN(ret, line, dup); } - ADD_INSN1(ret, line, setglobal, - ((VALUE)node->nd_entry | 1)); + ADD_INSN1(ret, line, setglobal, ID2SYM(node->nd_entry)); break; } case NODE_IASGN:{ @@ -8212,8 +8204,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in https://github.com/ruby/ruby/blob/trunk/compile.c#L8204 break; } case NODE_GVAR:{ - ADD_INSN1(ret, line, getglobal, - ((VALUE)node->nd_entry | 1)); + ADD_INSN1(ret, line, getglobal, ID2SYM(node->nd_entry)); if (popped) { ADD_INSN(ret, line, pop); } @@ -8980,13 +8971,6 @@ insn_data_to_s_detail(INSN *iobj) https://github.com/ruby/ruby/blob/trunk/compile.c#L8971 case TS_ID: /* ID */ rb_str_concat(str, opobj_inspect(OPERAND_AT(iobj, j))); break; - case TS_GENTRY: - { - struct rb_global_entry *entry = (struct rb_global_entry *) - (OPERAND_AT(iobj, j) & (~1)); - rb_str_append(str, rb_id2str(entry->id)); - break; - } case TS_IC: /* inline cache */ case TS_IVC: /* inline ivar cache */ case TS_ISE: /* inline storage entry */ @@ -9376,10 +9360,6 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *const anchor, https://github.com/ruby/ruby/blob/trunk/compile.c#L9360 } } break; - case TS_GENTRY: - op = rb_to_symbol_type(op); - argv[j] = (VALUE)rb_global_entry(SYM2ID(op)); - break; case TS_ISE: FL_SET((VALUE)iseq, ISEQ_MARKABLE_ISEQ); /* fall through */ @@ -10136,19 +10116,6 @@ ibf_dump_iseq(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L10116 } } -static VALUE -ibf_dump_gentry(struct ibf_dump *dump, const struct rb_global_entry *entry) -{ - return (VALUE)ibf_dump_id(dump, entry->id); -} - -static VALUE -ibf_load_gentry(const struct ibf_load *load, const struct rb_global_entry *entry) -{ - ID gid = ibf_load_id(load, (ID)(VALUE)entry); - return (VALUE)rb_global_entry(gid); -} - static unsigned char ibf_load_byte(const struct ibf_load *load, ibf_offset_t *offset) { @@ -10316,9 +10283,6 @@ ibf_dump_code(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L10283 case TS_ID: wv = ibf_dump_id(dump, (ID)op); break; - case TS_GENTRY: - wv = ibf_dump_gentry(dump, (const struct rb_global_entry *)op); - break; case TS_FUNCPTR: rb_raise(rb_eRuntimeError, "TS_FUNCPTR is not supported"); goto skip_wv; @@ -10403,12 +10367,6 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod https://github.com/ruby/ruby/blob/trunk/compile.c#L10367 code[code_index] = ibf_load_id(load, (ID)(VALUE)op); } break; - case TS_GENTRY: - { - VALUE op = ibf_load_small_value(load, &reading_pos); - code[code_index] = ibf_load_gentry(load, (const struct rb_global_entry *)(VALUE)op); - } - break; case TS_FUNCPTR: rb_raise(rb_eRuntimeError, "TS_FUNCPTR is not supported"); break; diff --git a/insns.def b/insns.def index 95f1391..c4e8004 100644 --- a/insns.def +++ b/insns.def @@ -288,25 +288,23 @@ setconstant https://github.com/ruby/ruby/blob/trunk/insns.def#L288 /* get global variable id. */ DEFINE_INSN getglobal -(GENTRY entry) +(ID gid) () (VALUE val) -// attr bool leaf = leafness_of_getglobal(entry); +// attr bool leaf = false; { - struct rb_global_entry *gentry = (void *)entry; - val = rb_gvar_get(gentry); + val = rb_gvar_get(gid); } /* set global variable id as val. */ DEFINE_INSN setglobal -(GENTRY entry) +(ID gid) (VALUE val) () -// attr bool leaf = leafness_of_setglobal(entry); +// attr bool leaf = false; { - struct rb_global_entry *gentry = (void *)entry; - rb_gvar_set(gentry, val); + rb_gvar_set(gid, val); } /**********************************************************/ diff --git a/internal/variable.h b/internal/variable.h index f0b7b21..6ed7280 100644 --- a/internal/variable.h +++ b/internal/variable.h @@ -19,13 +19,6 @@ https://github.com/ruby/ruby/blob/trunk/internal/variable.h#L19 #define ROBJECT_TRANSIENT_FLAG FL_USER13 -struct rb_global_variable; /* defined in variable.c */ - -struct rb_global_entry { - struct rb_global_variable *var; - ID id; -}; - /* variable.c */ void rb_gc_mark_global_tbl(void); void rb_gc_update_global_tbl(void); @@ -36,9 +29,8 @@ VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef); https://github.com/ruby/ruby/blob/trunk/internal/variable.h#L29 void rb_autoload_str(VALUE mod, ID id, VALUE file); VALUE rb_autoload_at_p(VALUE, ID, int); NORETURN(VALUE rb_mod_const_missing(VALUE,VALUE)); -rb_gvar_getter_t *rb_gvar_getter_function_of(const struct rb_global_entry *); -rb_gvar_setter_t *rb_gvar_setter_function_of(const struct rb_global_entry *); -bool rb_gvar_is_traced(const struct rb_global_entry *); +rb_gvar_getter_t *rb_gvar_getter_function_of(ID); +rb_gvar_setter_t *rb_gvar_setter_function_of(ID); void rb_gvar_readonly_setter(VALUE v, ID id, VALUE *_); static inline bool ROBJ_TRANSIENT_P(VALUE obj); static inline void ROBJ_TRANSIENT_SET(VALUE obj); @@ -55,11 +47,9 @@ void rb_deprecate_constant(VALUE mod, const char *name); https://github.com/ruby/ruby/blob/trunk/internal/variable.h#L47 RUBY_SYMBOL_EXPORT_END MJIT_SYMBOL_EXPORT_BEGIN -struct rb_global_entry *rb_global_entry(ID); -VALUE rb_gvar_get(struct rb_global_entry *); -VALUE rb_gvar_set(struct rb_global_entry *, VALUE); -VALUE rb_gvar_defined(struct rb_global_entry *); -struct st_table *rb_ivar_generic_ivtbl(void); +VALUE rb_gvar_get(ID); +VALUE rb_gvar_set(ID, VALUE); +VALUE rb_gvar_defined(ID); void rb_const_warn_if_deprecated(const rb_const_entry_t *, VALUE, ID); MJIT_SYMBOL_EXPORT_END diff --git a/iseq.c b/iseq.c index 956bd2a..e6568a6 100644 --- a/iseq.c +++ b/iseq.c @@ -1946,12 +1946,6 @@ rb_insn_operand_intern(const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L1946 } break; } - case TS_GENTRY: - { - struct rb_global_entry *entry = (struct rb_global_entry *)op; - ret = rb_str_dup(rb_id2str(entry->id)); - } - break; case TS_IC: case TS_IVC: @@ -2776,12 +2770,6 @@ iseq_data_to_ary(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2770 } } break; - case TS_GENTRY: - { - struct rb_global_entry *entry = (struct rb_global_entry *)*seq; - rb_ary_push(ary, ID2SYM(entry->id)); - } - break; case TS_IC: case TS_IVC: case TS_ISE: diff --git a/node.c b/node.c index 4ef18db..7a2fce1 100644 --- a/node.c +++ b/node.c @@ -63,7 +63,7 @@ https://github.com/ruby/ruby/blob/trunk/node.c#L63 #define SIMPLE_FIELD1(name, ann) SIMPLE_FIELD(FIELD_NAME_LEN(name, ann), FIELD_NAME_DESC(name, ann)) #define F_CUSTOM1(name, ann) SIMPLE_FIELD1(#name, ann) #define F_ID(name, ann) SIMPLE_FIELD1(#name, ann) A_ID(node->name) -#define F_GENTRY(name, ann) SIMPLE_FIELD1(#name, ann) A_ID((node->name)->id) +#define F_GENTRY(name, ann) SIMPLE_FIELD1(#name, ann) A_ID(node->name) #define F_INT(name, ann) SIMPLE_FIELD1(#name, ann) A_INT(node->name) #define F_LONG(name, ann) SIMPLE_FIELD1(#name, ann) A_LONG(node->name) #define F_LIT(name, ann) SIMPLE_FIELD1(#name, ann) A_LIT(node->name) diff --git a/node.h b/node.h index 60e (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/