ruby-changes:51235
From: nobu <ko1@a...>
Date: Wed, 16 May 2018 10:40:49 +0900 (JST)
Subject: [ruby-changes:51235] nobu:r63441 (trunk): iseq body local variables
nobu 2018-05-16 10:40:44 +0900 (Wed, 16 May 2018) New Revision: 63441 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63441 Log: iseq body local variables * compile.c, iseq.c: extract body and param.keyword in iseq as local variables. Modified files: trunk/compile.c trunk/iseq.c Index: iseq.c =================================================================== --- iseq.c (revision 63440) +++ iseq.c (revision 63441) @@ -228,12 +228,13 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L228 RUBY_MARK_UNLESS_NULL((VALUE)body->parent_iseq); if (body->param.flags.has_kw && ISEQ_COMPILE_DATA(iseq) == NULL) { + const struct rb_iseq_param_keyword *const keyword = body->param.keyword; int i, j; - i = body->param.keyword->required_num; + i = keyword->required_num; - for (j = 0; i < body->param.keyword->num; i++, j++) { - VALUE obj = body->param.keyword->default_values[j]; + for (j = 0; i < keyword->num; i++, j++) { + VALUE obj = keyword->default_values[j]; if (!SPECIAL_CONST_P(obj)) { rb_gc_mark(obj); } @@ -2706,6 +2707,7 @@ rb_iseq_parameters(const rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/iseq.c#L2707 { int i, r; const struct rb_iseq_constant_body *const body = iseq->body; + const struct rb_iseq_param_keyword *const keyword = body->param.keyword; VALUE a, args = rb_ary_new2(body->param.size); ID req, opt, rest, block, key, keyrest; #define PARAM_TYPE(type) rb_ary_push(a = rb_ary_new2(2), ID2SYM(type)) @@ -2757,29 +2759,29 @@ rb_iseq_parameters(const rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/iseq.c#L2759 } if (body->param.flags.has_kw) { i = 0; - if (body->param.keyword->required_num > 0) { + if (keyword->required_num > 0) { ID keyreq; CONST_ID(keyreq, "keyreq"); - for (; i < body->param.keyword->required_num; i++) { + for (; i < keyword->required_num; i++) { PARAM_TYPE(keyreq); - if (rb_id2str(body->param.keyword->table[i])) { - rb_ary_push(a, ID2SYM(body->param.keyword->table[i])); + if (rb_id2str(keyword->table[i])) { + rb_ary_push(a, ID2SYM(keyword->table[i])); } rb_ary_push(args, a); } } CONST_ID(key, "key"); - for (; i < body->param.keyword->num; i++) { + for (; i < keyword->num; i++) { PARAM_TYPE(key); - if (rb_id2str(body->param.keyword->table[i])) { - rb_ary_push(a, ID2SYM(body->param.keyword->table[i])); + if (rb_id2str(keyword->table[i])) { + rb_ary_push(a, ID2SYM(keyword->table[i])); } rb_ary_push(args, a); } } if (body->param.flags.has_kwrest) { CONST_ID(keyrest, "keyrest"); - rb_ary_push(args, PARAM(body->param.keyword->rest_start, keyrest)); + rb_ary_push(args, PARAM(keyword->rest_start, keyrest)); } if (body->param.flags.has_block) { CONST_ID(block, "block"); Index: compile.c =================================================================== --- compile.c (revision 63440) +++ compile.c (revision 63441) @@ -1443,13 +1443,15 @@ get_dyna_var_idx(const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L1443 static int iseq_local_block_param_p(const rb_iseq_t *iseq, unsigned int idx, unsigned int level) { + const struct rb_iseq_constant_body *body; while (level > 0) { iseq = iseq->body->parent_iseq; level--; } - if (iseq->body->local_iseq == iseq && /* local variables */ - iseq->body->param.flags.has_block && - iseq->body->local_table_size - iseq->body->param.block_start == idx) { + body = iseq->body; + if (body->local_iseq == iseq && /* local variables */ + body->param.flags.has_block && + body->local_table_size - body->param.block_start == idx) { return TRUE; } else { @@ -1499,37 +1501,38 @@ iseq_add_setlocal(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L1501 static void iseq_calc_param_size(rb_iseq_t *iseq) { - if (iseq->body->param.flags.has_opt || - iseq->body->param.flags.has_post || - iseq->body->param.flags.has_rest || - iseq->body->param.flags.has_block || - iseq->body->param.flags.has_kw || - iseq->body->param.flags.has_kwrest) { - - if (iseq->body->param.flags.has_block) { - iseq->body->param.size = iseq->body->param.block_start + 1; - } - else if (iseq->body->param.flags.has_kwrest) { - iseq->body->param.size = iseq->body->param.keyword->rest_start + 1; - } - else if (iseq->body->param.flags.has_kw) { - iseq->body->param.size = iseq->body->param.keyword->bits_start + 1; + struct rb_iseq_constant_body *const body = iseq->body; + if (body->param.flags.has_opt || + body->param.flags.has_post || + body->param.flags.has_rest || + body->param.flags.has_block || + body->param.flags.has_kw || + body->param.flags.has_kwrest) { + + if (body->param.flags.has_block) { + body->param.size = body->param.block_start + 1; + } + else if (body->param.flags.has_kwrest) { + body->param.size = body->param.keyword->rest_start + 1; + } + else if (body->param.flags.has_kw) { + body->param.size = body->param.keyword->bits_start + 1; } - else if (iseq->body->param.flags.has_post) { - iseq->body->param.size = iseq->body->param.post_start + iseq->body->param.post_num; + else if (body->param.flags.has_post) { + body->param.size = body->param.post_start + body->param.post_num; } - else if (iseq->body->param.flags.has_rest) { - iseq->body->param.size = iseq->body->param.rest_start + 1; + else if (body->param.flags.has_rest) { + body->param.size = body->param.rest_start + 1; } - else if (iseq->body->param.flags.has_opt) { - iseq->body->param.size = iseq->body->param.lead_num + iseq->body->param.opt_num; + else if (body->param.flags.has_opt) { + body->param.size = body->param.lead_num + body->param.opt_num; } else { rb_bug("unreachable"); } } else { - iseq->body->param.size = iseq->body->param.lead_num; + body->param.size = body->param.lead_num; } } @@ -1538,13 +1541,14 @@ iseq_set_arguments_keywords(rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/compile.c#L1541 const struct rb_args_info *args, int arg_size) { const NODE *node = args->kw_args; + struct rb_iseq_constant_body *const body = iseq->body; struct rb_iseq_param_keyword *keyword; const VALUE default_values = rb_ary_tmp_new(1); const VALUE complex_mark = rb_str_tmp_new(0); int kw = 0, rkw = 0, di = 0, i; - iseq->body->param.flags.has_kw = TRUE; - iseq->body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1); + body->param.flags.has_kw = TRUE; + body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1); while (node) { kw++; @@ -1592,10 +1596,10 @@ iseq_set_arguments_keywords(rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/compile.c#L1596 if (args->kw_rest_arg->nd_vid != 0) { keyword->rest_start = arg_size++; - iseq->body->param.flags.has_kwrest = TRUE; + body->param.flags.has_kwrest = TRUE; } keyword->required_num = rkw; - keyword->table = &iseq->body->local_table[keyword->bits_start - keyword->num]; + keyword->table = &body->local_table[keyword->bits_start - keyword->num]; { VALUE *dvs = ALLOC_N(VALUE, RARRAY_LEN(default_values)); @@ -1620,6 +1624,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1624 debugs("iseq_set_arguments: %s\n", node_args ? "" : "0"); if (node_args) { + struct rb_iseq_constant_body *const body = iseq->body; struct rb_args_info *args = node_args->nd_ainfo; ID rest_id = 0; int last_comma = 0; @@ -1628,9 +1633,9 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1633 EXPECT_NODE("iseq_set_arguments", node_args, NODE_ARGS, COMPILE_NG); - iseq->body->param.lead_num = arg_size = (int)args->pre_args_num; - if (iseq->body->param.lead_num > 0) iseq->body->param.flags.has_lead = TRUE; - debugs(" - argc: %d\n", iseq->body->param.lead_num); + body->param.lead_num = arg_size = (int)args->pre_args_num; + if (body->param.lead_num > 0) body->param.flags.has_lead = TRUE; + debugs(" - argc: %d\n", body->param.lead_num); rest_id = args->rest_arg; if (rest_id == 1) { @@ -1668,26 +1673,26 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1673 } rb_ary_clear(labels); - iseq->body->param.flags.has_opt = TRUE; - iseq->body->param.opt_num = i; - iseq->body->param.opt_table = opt_table; + body->param.flags.has_opt = TRUE; + body->param.opt_num = i; + body->param.opt_table = opt_table; arg_size += i; } if (rest_id) { - iseq->body->param.rest_start = arg_size++; - iseq->body->param.flags.has_rest = TRUE; - assert(iseq->body->param.rest_start != -1); + body->param.rest_start = arg_size++; + body->param.flags.has_rest = TRUE; + assert(body->param.rest_start != -1); } if (args->first_post_arg) { - iseq->body->param.post_start = arg_size; - iseq->body->param.post_num = args->post_args_num; - iseq->body->param.flags.has_post = TRUE; + body->param.post_start = arg_size; + body->param.post_num = args->post_args_num; + body->param.flags.has_post = TRUE; arg_size += args->post_args_num; - if (iseq->body->param.flags.has_rest) { /* TODO: why that? */ - iseq->body->param.post_start = iseq->body->param.rest_start + 1; + if (body->param.flags.has_rest) { /* TODO: why that? */ + body->param.post_start = body->param.rest_start + 1; } } @@ -1697,17 +1702,17 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1702 else if (args->kw_rest_arg) { struct rb_iseq_param_keyword *keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1); keyword->rest_start = arg_size++; - iseq->body->param.keyword = keyword; - iseq->body->param.flags.has_kwrest = TRUE; + body->param.keyword = keyword; + body->param.flags.has_kwrest = TRUE; } if (block_id) { - iseq->body->param.block_start = arg_size++; - iseq->body->param.flags.has_block = TRUE; + body->param.block_start = arg_size++; + body->param.flags.has_block = TRUE; } iseq_calc_param_size(iseq); - iseq->body->param.size = arg_size; + body->param.size = arg_size; if (args->pre_init) { /* m_init */ COMPILE_POPPED(optargs, "init arguments (m)", args->pre_init); @@ -1716,16 +1721,16 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1721 COMPILE_POPPED(optargs, "init arguments (p)", args->post_init); } - if (iseq->body->type == ISEQ_TYPE_BLOCK) { - if (iseq->body->param.flags.has_opt == FALSE && - iseq->body->param.flags.has_post == FALSE && - iseq->body->param.flags.has_rest == FALSE && - iseq->body->param.flags.has_kw == FALSE && - iseq->body->param.flags.has_kwrest == FALSE) { + if (body->type == ISEQ_TYPE_BLOCK) { + if (body->param.flags.has_opt == FALSE && + body->param.flags.has_post == FALSE && + body->param.flags.has_rest == FALSE && + body->param.flags.has_kw == FALSE && + body->param.flags.has_kwrest == FALSE) { - if (iseq->body->param.lead_num == 1 && last_comma == 0) { + if (body->param.lead_num == 1 && last_comma == 0) { /* {|a|} */ - iseq->body->param.flags.ambiguous_param0 = TRUE; + body->param.flags.ambiguous_param0 = TRUE; } } } @@ -1978,6 +1983,7 @@ static int https://github.com/ruby/ruby/blob/trunk/compile.c#L1983 iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) { struct iseq_insn_info_entry *insns_info; + struct rb_iseq_constant_body *const body = iseq->body; unsigned int *positions; LINK_ELEMENT *list; VALUE *generated_iseq; @@ -2040,11 +2046,11 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2046 generated_iseq = ALLOC_N(VALUE, code_index); insns_info = ALLOC_N(struct iseq_insn_info_entry, insn_num); positions = ALLOC_N(unsigned int, insn_num); - iseq->body->is_entries = ZALLOC_N(union iseq_inline_storage_entry, iseq->body->is_size); - iseq->body->ci_entries = (struct rb_call_info *)ruby_xmalloc(sizeof(struct rb_call_info) * iseq->body->ci_size + - sizeof(struct rb_call_info_with_kwarg) * iseq->body->ci_kw_size); - MEMZERO(iseq->body->ci_entries + iseq->body->ci_size, struct rb_call_info_with_kwarg, iseq->body->ci_kw_size); /* need to clear ci_kw entries */ - iseq->body->cc_entries = ZALLOC_N(struct rb_call_cache, iseq->body->ci_size + iseq->body->ci_kw_size); + body->is_entries = ZALLOC_N(union iseq_inline_storage_entry, body->is_size); + body->ci_entries = (struct rb_call_info *)ruby_xmalloc(sizeof(struct rb_call_info) * body->ci_size + + sizeof(struct rb_call_info_with_kwarg) * body->ci_kw_size); + MEMZERO(body->ci_entries + body->ci_size, struct rb_call_info_with_kwarg, body->ci_kw_size); /* need to clear ci_kw entries */ + body->cc_entries = ZALLOC_N(struct rb_call_cache, body->ci_size + body->ci_kw_size); ISEQ_COMPILE_DATA(iseq)->ci_index = ISEQ_COMPILE_DATA(iseq)->ci_kw_index = 0; @@ -2124,9 +2130,9 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2130 case TS_IC: /* inline cache */ { unsigned int ic_index = FIX2UINT(operands[j]); - IC ic = (IC)&iseq->body->is_entries[ic_index]; - if (UNLIKELY(ic_index >= iseq->body->is_size)) { - rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, iseq->body->is_size); + IC ic = (IC)&body->is_entries[ic_index]; + if (UNLIKELY(ic_index >= body->is_size)) { + rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, body->is_size); } generated_iseq[code_index + 1 + j] = (VALUE)ic; break; @@ -2134,9 +2140,9 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2140 case TS_ISE: /* inline storage entry */ { unsigned int ic_index = FIX2UINT(operands[j]); - IC ic = (IC)&iseq->body->is_entries[ic_index]; - if (UNLIKELY(ic_index >= iseq->body->is_size)) { - rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, iseq->body->is_size); + IC ic = (IC)&body->is_entries[ic_index]; + if (UNLIKELY(ic_index >= body->is_size)) { + rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, body->is_size); } generated_iseq[code_index + 1 + j] = (VALUE)ic; FL_SET(iseq, ISEQ_MARKABLE_ISEQ); @@ -2148,16 +2154,16 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2154 struct rb_call_info *ci; if (base_ci->flag & VM_CALL_KWARG) { - struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&iseq->body->ci_entries[iseq->body->ci_size]; + struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&body->ci_entries[body->ci_size]; struct rb_call_info_with_kwarg *ci_kw = &ci_kw_entries[ISEQ_COMPILE_DATA(iseq)->ci_kw_index++]; *ci_kw = *((struct rb_call_info_with_kwarg *)base_ci); ci = (struct rb_call_info *)ci_kw; - assert(ISEQ_COMPILE_DATA(iseq)->ci_kw_index <= iseq->body->ci_kw_size); + assert(ISEQ_COMPILE_DATA(iseq)->ci_kw_index <= body->ci_kw_size); } else { - ci = &iseq->body->ci_entries[ISEQ_COMPILE_DATA(iseq)->ci_index++]; + ci = &body->ci_entries[ISEQ_COMPILE_DATA(iseq)->ci_index++]; *ci = *base_ci; - assert(ISEQ_COMPILE_DATA(iseq)->ci_index <= iseq->body->ci_size); + assert(ISEQ_COMPILE_DATA(iseq)->ci_index <= body->ci_size); } generated_iseq[code_index + 1 + j] = (VALUE)ci; @@ -2165,7 +2171,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2171 } case TS_CALLCACHE: { - struct rb_call_cache *cc = &iseq->body->cc_entries[ISEQ_COMPILE_DATA(iseq)->ci_index + ISEQ_COMPILE_DATA(iseq)->ci_kw_index - 1]; + struct rb_call_cache *cc = &body->cc_entries[ISEQ_COMPILE_DATA(iseq)->ci_index + ISEQ_COMPILE_DATA(iseq)->ci_kw_index - 1]; generated_iseq[code_index + 1 + j] = (VALUE)cc; break; } @@ -2243,19 +2249,19 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2249 list = list->next; } - iseq->body->iseq_encoded = (void *)generated_iseq; - iseq->body->iseq_size = code_index; - iseq->body->stack_max = stack_max; + body->iseq_encoded = (void *)generated_iseq; + body->iseq_size = code_index; + body->stack_max = stack_max; /* get rid of memory leak when REALLOC failed */ - iseq->body->insns_info.body = insns_info; - iseq->body->insns_info.positions = positions; + body->insns_info.body = insns_info; + body->insns_info.positions = positions; REALLOC_N(insns_info, struct iseq_insn_info_entry, insns_info_index); - iseq->body->insns_info.body = insns_info; + body->insns_info.body = insns_info; REALLOC_N(positions, unsigned int, insns_info_index); - iseq->body->insns_info.positions = positions; - iseq->body->insns_info.size = insns_info_index; + body->insns_info.positions = positions; + body->insns_info.size = insns_info_index; return COMPILE_OK; } @@ -4833,6 +4839,7 @@ number_literal_p(const NODE *n) https://github.com/ruby/ruby/blob/trunk/compile.c#L4839 static int compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped, const enum node_type type) { + struct rb_iseq_constant_body *const body = iseq->body; const NODE *const node_body = type == NODE_IF ? node->nd_body : node->nd_else; const NODE *const node_else = type == NODE_IF ? node->nd_else : node->nd_body; @@ -4858,20 +4865,20 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L4865 compile_branch_condition(iseq, cond_seq, node->nd_cond, then_label, else_label); - ci_size = iseq->body->ci_size; - ci_kw_size = iseq->body->ci_kw_size; + ci_size = body->ci_size; + ci_kw_size = body->ci_kw_size; CHECK(COMPILE_(then_seq, "then", node_body, popped)); if (!then_label->refcnt) { - iseq->body->ci_size = ci_size; - iseq->body->ci_kw_size = ci_kw_size; + body->ci_size = ci_size; + body->ci_kw_size = ci_kw_size; } - ci_size = iseq->body->ci_size; - ci_kw_size = iseq->body->ci_kw_size; + ci_size = body->ci_size; + ci_kw_size = body->ci_kw_size; CHECK(COMPILE_(else_seq, "else", node_else, popped)); if (!else_label->refcnt) { - iseq->body->ci_size = ci_size; - iseq->body->ci_kw_size = ci_kw_size; + body->ci_size = ci_size; + body->ci_kw_size = ci_kw_size; } ADD_SEQ(ret, cond_seq); @@ -5776,6 +5783,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5783 { const int line = (int)nd_line(node); const enum node_type type = nd_type(node); + struct rb_iseq_constant_body *const body = iseq->body; if (ISEQ_COMPILE_DATA(iseq)->last_line == line) { /* ignore */ @@ -5879,7 +5887,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5887 case NODE_LASGN:{ ID id = node->nd_vid; - int idx = iseq->body->local_iseq->body->local_table_size - get_local_var_idx(iseq, id); + int idx = body->local_iseq->body->local_table_size - get_local_var_idx(iseq, id); debugs("lvar: %s idx: %d\n", rb_id2name(id), idx); CHECK(COMPILE(ret, "rvalue", node->nd_value)); @@ -6513,46 +6521,48 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L6521 else { /* NODE_ZSUPER */ int i; - const rb_iseq_t *liseq = iseq->body->local_iseq; + const rb_iseq_t *liseq = body->local_iseq; + const struct rb_iseq_constant_body *const local_body = liseq->body; + const struct rb_iseq_param_keyword *const local_kwd = local_body->param.keyword; int lvar_level = g (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/