ruby-changes:51197
From: nobu <ko1@a...>
Date: Sat, 12 May 2018 10:24:24 +0900 (JST)
Subject: [ruby-changes:51197] nobu:r63404 (trunk): iseq.c: iseq body local variables
nobu 2018-05-12 10:24:18 +0900 (Sat, 12 May 2018) New Revision: 63404 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63404 Log: iseq.c: iseq body local variables * iseq.c: extract body and param.keyword in iseq as local variables. Modified files: trunk/iseq.c Index: iseq.c =================================================================== --- iseq.c (revision 63403) +++ iseq.c (revision 63404) @@ -80,35 +80,36 @@ rb_iseq_free(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L80 RUBY_FREE_ENTER("iseq"); if (iseq && iseq->body) { + struct rb_iseq_constant_body *const body = iseq->body; mjit_free_iseq(iseq); /* Notify MJIT */ - ruby_xfree((void *)iseq->body->iseq_encoded); - ruby_xfree((void *)iseq->body->insns_info.body); - if (iseq->body->insns_info.positions) ruby_xfree((void *)iseq->body->insns_info.positions); + ruby_xfree((void *)body->iseq_encoded); + ruby_xfree((void *)body->insns_info.body); + if (body->insns_info.positions) ruby_xfree((void *)body->insns_info.positions); #if VM_INSN_INFO_TABLE_IMPL == 2 - if (iseq->body->insns_info.succ_index_table) ruby_xfree(iseq->body->insns_info.succ_index_table); + if (body->insns_info.succ_index_table) ruby_xfree(body->insns_info.succ_index_table); #endif - ruby_xfree((void *)iseq->body->local_table); - ruby_xfree((void *)iseq->body->is_entries); + ruby_xfree((void *)body->local_table); + ruby_xfree((void *)body->is_entries); - if (iseq->body->ci_entries) { + if (body->ci_entries) { unsigned int i; - struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&iseq->body->ci_entries[iseq->body->ci_size]; - for (i=0; i<iseq->body->ci_kw_size; i++) { + struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&body->ci_entries[body->ci_size]; + for (i=0; i<body->ci_kw_size; i++) { const struct rb_call_info_kw_arg *kw_arg = ci_kw_entries[i].kw_arg; ruby_xfree((void *)kw_arg); } - ruby_xfree(iseq->body->ci_entries); - ruby_xfree(iseq->body->cc_entries); + ruby_xfree(body->ci_entries); + ruby_xfree(body->cc_entries); } - ruby_xfree((void *)iseq->body->catch_table); - ruby_xfree((void *)iseq->body->param.opt_table); + ruby_xfree((void *)body->catch_table); + ruby_xfree((void *)body->param.opt_table); - if (iseq->body->param.keyword != NULL) { - ruby_xfree((void *)iseq->body->param.keyword->default_values); - ruby_xfree((void *)iseq->body->param.keyword); + if (body->param.keyword != NULL) { + ruby_xfree((void *)body->param.keyword->default_values); + ruby_xfree((void *)body->param.keyword); } compile_data_free(ISEQ_COMPILE_DATA(iseq)); - ruby_xfree(iseq->body); + ruby_xfree(body); } RUBY_FREE_LEAVE("iseq"); } @@ -182,9 +183,10 @@ rb_iseq_each_value(const rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/iseq.c#L183 const VALUE *code; size_t n; rb_vm_insns_translator_t * translator; + const struct rb_iseq_constant_body *const body = iseq->body; - size = iseq->body->iseq_size; - code = iseq->body->iseq_encoded; + size = body->iseq_size; + code = body->iseq_encoded; #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE if (FL_TEST(iseq, ISEQ_TRANSLATED)) { @@ -213,7 +215,7 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L215 RUBY_MARK_ENTER("iseq"); if (iseq->body) { - const struct rb_iseq_constant_body *body = iseq->body; + const struct rb_iseq_constant_body *const body = iseq->body; if (FL_TEST(iseq, ISEQ_MARKABLE_ISEQ)) { rb_iseq_each_value(iseq, each_insn_value, NULL); @@ -399,25 +401,26 @@ iseq_location_setup(rb_iseq_t *iseq, VAL https://github.com/ruby/ruby/blob/trunk/iseq.c#L401 static void set_relation(rb_iseq_t *iseq, const rb_iseq_t *piseq) { - const VALUE type = iseq->body->type; + struct rb_iseq_constant_body *const body = iseq->body; + const VALUE type = body->type; /* set class nest stack */ if (type == ISEQ_TYPE_TOP) { - iseq->body->local_iseq = iseq; + body->local_iseq = iseq; } else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) { - iseq->body->local_iseq = iseq; + body->local_iseq = iseq; } else if (piseq) { - iseq->body->local_iseq = piseq->body->local_iseq; + body->local_iseq = piseq->body->local_iseq; } if (piseq) { - iseq->body->parent_iseq = piseq; + body->parent_iseq = piseq; } if (type == ISEQ_TYPE_MAIN) { - iseq->body->local_iseq = iseq; + body->local_iseq = iseq; } } @@ -429,21 +432,22 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L432 { VALUE coverage = Qfalse; VALUE err_info = Qnil; + struct rb_iseq_constant_body *const body = iseq->body; if (parent && (type == ISEQ_TYPE_MAIN || type == ISEQ_TYPE_TOP)) err_info = Qfalse; - iseq->body->type = type; + body->type = type; set_relation(iseq, parent); name = rb_fstring(name); iseq_location_setup(iseq, name, path, realpath, first_lineno, code_location); - if (iseq != iseq->body->local_iseq) { - RB_OBJ_WRITE(iseq, &iseq->body->location.base_label, iseq->body->local_iseq->body->location.label); + if (iseq != body->local_iseq) { + RB_OBJ_WRITE(iseq, &body->location.base_label, body->local_iseq->body->location.label); } ISEQ_COVERAGE_SET(iseq, Qnil); ISEQ_ORIGINAL_ISEQ_CLEAR(iseq); - iseq->body->variable.flip_count = 0; + body->variable.flip_count = 0; ISEQ_COMPILE_DATA_ALLOC(iseq); RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info); @@ -483,14 +487,15 @@ void https://github.com/ruby/ruby/blob/trunk/iseq.c#L487 rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq) { #if VM_INSN_INFO_TABLE_IMPL == 2 - int size = iseq->body->insns_info.size; - int max_pos = iseq->body->iseq_size; - int *data = (int *)iseq->body->insns_info.positions; - if (iseq->body->insns_info.succ_index_table) ruby_xfree(iseq->body->insns_info.succ_index_table); - iseq->body->insns_info.succ_index_table = succ_index_table_create(max_pos, data, size); + struct rb_iseq_constant_body *const body = iseq->body; + int size = body->insns_info.size; + int max_pos = body->iseq_size; + int *data = (int *)body->insns_info.positions; + if (body->insns_info.succ_index_table) ruby_xfree(body->insns_info.succ_index_table); + body->insns_info.succ_index_table = succ_index_table_create(max_pos, data, size); #if VM_CHECK_MODE == 0 - ruby_xfree(iseq->body->insns_info.positions); - iseq->body->insns_info.positions = NULL; + ruby_xfree(body->insns_info.positions); + body->insns_info.positions = NULL; #endif #endif } @@ -510,13 +515,14 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L515 finish_iseq_build(rb_iseq_t *iseq) { struct iseq_compile_data *data = ISEQ_COMPILE_DATA(iseq); + const struct rb_iseq_constant_body *const body = iseq->body; VALUE err = data->err_info; ISEQ_COMPILE_DATA_CLEAR(iseq); compile_data_free(data); #if VM_INSN_INFO_TABLE_IMPL == 2 /* succinct bitvector */ /* create succ_index_table */ - if (iseq->body->insns_info.succ_index_table == NULL) { + if (body->insns_info.succ_index_table == NULL) { rb_iseq_insns_info_encode_positions(iseq); } #endif @@ -526,7 +532,7 @@ finish_iseq_build(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L532 #endif if (RTEST(err)) { - VALUE path = pathobj_path(iseq->body->location.pathobj); + VALUE path = pathobj_path(body->location.pathobj); if (err == Qtrue) err = rb_exc_new_cstr(rb_eSyntaxError, "compile error"); rb_funcallv(err, rb_intern("set_backtrace"), 1, &path); rb_exc_raise(err); @@ -941,12 +947,10 @@ rb_iseq_first_lineno(const rb_iseq_t *is https://github.com/ruby/ruby/blob/trunk/iseq.c#L947 VALUE rb_iseq_method_name(const rb_iseq_t *iseq) { - const rb_iseq_t *local_iseq; - - local_iseq = iseq->body->local_iseq; + struct rb_iseq_constant_body *const body = iseq->body->local_iseq->body; - if (local_iseq->body->type == ISEQ_TYPE_METHOD) { - return local_iseq->body->location.base_label; + if (body->type == ISEQ_TYPE_METHOD) { + return body->location.base_label; } else { return Qnil; @@ -956,10 +960,11 @@ rb_iseq_method_name(const rb_iseq_t *ise https://github.com/ruby/ruby/blob/trunk/iseq.c#L960 void rb_iseq_code_location(const rb_iseq_t *iseq, int *beg_pos_lineno, int *beg_pos_column, int *end_pos_lineno, int *end_pos_column) { - if (beg_pos_lineno) *beg_pos_lineno = iseq->body->location.code_location.beg_pos.lineno; - if (beg_pos_column) *beg_pos_column = iseq->body->location.code_location.beg_pos.column; - if (end_pos_lineno) *end_pos_lineno = iseq->body->location.code_location.end_pos.lineno; - if (end_pos_column) *end_pos_column = iseq->body->location.code_location.end_pos.column; + const rb_code_location_t *loc = &iseq->body->location.code_location; + if (beg_pos_lineno) *beg_pos_lineno = loc->beg_pos.lineno; + if (beg_pos_column) *beg_pos_column = loc->beg_pos.column; + if (end_pos_lineno) *end_pos_lineno = loc->end_pos.lineno; + if (end_pos_column) *end_pos_column = loc->end_pos.column; } VALUE @@ -1210,15 +1215,16 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L1215 iseqw_inspect(VALUE self) { const rb_iseq_t *iseq = iseqw_check(self); + const struct rb_iseq_constant_body *const body = iseq->body; VALUE klass = rb_class_name(rb_obj_class(self)); - if (!iseq->body->location.label) { + if (!body->location.label) { return rb_sprintf("#<%"PRIsVALUE": uninitialized>", klass); } else { return rb_sprintf("<%"PRIsVALUE":%"PRIsVALUE"@%"PRIsVALUE":%d>", klass, - iseq->body->location.label, rb_iseq_path(iseq), + body->location.label, rb_iseq_path(iseq), FIX2INT(rb_iseq_first_lineno(iseq))); } } @@ -1440,9 +1446,10 @@ iseqw_to_a(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1446 static const struct iseq_insn_info_entry * get_insn_info_binary_search(const rb_iseq_t *iseq, size_t pos) { - size_t size = iseq->body->insns_info.size; - const struct iseq_insn_info_entry *insns_info = iseq->body->insns_info.body; - const unsigned int *positions = iseq->body->insns_info.positions; + const struct rb_iseq_constant_body *const body = iseq->body; + size_t size = body->insns_info.size; + const struct iseq_insn_info_entry *insns_info = body->insns_info.body; + const unsigned int *positions = body->insns_info.positions; const int debug = 0; if (debug) { @@ -1492,9 +1499,10 @@ get_insn_info(const rb_iseq_t *iseq, siz https://github.com/ruby/ruby/blob/trunk/iseq.c#L1499 static const struct iseq_insn_info_entry * get_insn_info_succinct_bitvector(const rb_iseq_t *iseq, size_t pos) { - size_t size = iseq->body->insns_info.size; - const struct iseq_insn_info_entry *insns_info = iseq->body->insns_info.body; - const unsigned int *positions = iseq->body->insns_info.positions; + const struct rb_iseq_constant_body *const body = iseq->body; + size_t size = body->insns_info.size; + const struct iseq_insn_info_entry *insns_info = body->insns_info.body; + const unsigned int *positions = body->insns_info.positions; const int debug = 0; if (debug) { @@ -1511,8 +1519,8 @@ get_insn_info_succinct_bitvector(const r https://github.com/ruby/ruby/blob/trunk/iseq.c#L1519 } else { int index; - VM_ASSERT(iseq->body->insns_info.succ_index_table != NULL); - index = succ_index_lookup(iseq->body->insns_info.succ_index_table, (int)pos); + VM_ASSERT(body->insns_info.succ_index_table != NULL); + index = succ_index_lookup(body->insns_info.succ_index_table, (int)pos); return &insns_info[index-1]; } } @@ -1528,9 +1536,10 @@ get_insn_info(const rb_iseq_t *iseq, siz https://github.com/ruby/ruby/blob/trunk/iseq.c#L1536 static const struct iseq_insn_info_entry * get_insn_info_linear_search(const rb_iseq_t *iseq, size_t pos) { - size_t i = 0, size = iseq->body->insns_info.size; - const struct iseq_insn_info_entry *insns_info = iseq->body->insns_info.body; - const unsigned int *positions = iseq->body->insns_info.positions; + const struct rb_iseq_constant_body *const body = iseq->body; + size_t i = 0, size = body->insns_info.size; + const struct iseq_insn_info_entry *insns_info = body->insns_info.body; + const unsigned int *positions = body->insns_info.positions; const int debug = 0; if (debug) { @@ -1574,8 +1583,9 @@ get_insn_info(const rb_iseq_t *iseq, siz https://github.com/ruby/ruby/blob/trunk/iseq.c#L1583 static void validate_get_insn_info(const rb_iseq_t *iseq) { + const struct rb_iseq_constant_body *const body = iseq->body; size_t i; - for (i = 0; i < iseq->body->iseq_size; i++) { + for (i = 0; i < body->iseq_size; i++) { if (get_insn_info_linear_search(iseq, i) != get_insn_info(iseq, i)) { rb_bug("validate_get_insn_info: get_insn_info_linear_search(iseq, %"PRIuSIZE") != get_insn_info(iseq, %"PRIuSIZE")", i, i); } @@ -1909,23 +1919,26 @@ catch_type(int type) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1919 static VALUE iseq_inspect(const rb_iseq_t *iseq) { - if (!iseq->body->location.label) { + const struct rb_iseq_constant_body *const body = iseq->body; + if (!body->location.label) { return rb_sprintf("#<ISeq: uninitialized>"); } else { + const rb_code_location_t *loc = &body->location.code_location; return rb_sprintf("#<ISeq:%"PRIsVALUE"@%"PRIsVALUE":%d (%d,%d)-(%d,%d)>", - iseq->body->location.label, rb_iseq_path(iseq), - iseq->body->location.code_location.beg_pos.lineno, - iseq->body->location.code_location.beg_pos.lineno, - iseq->body->location.code_location.beg_pos.column, - iseq->body->location.code_location.end_pos.lineno, - iseq->body->location.code_location.end_pos.column); + body->location.label, rb_iseq_path(iseq), + loc->beg_pos.lineno, + loc->beg_pos.lineno, + loc->beg_pos.column, + loc->end_pos.lineno, + loc->end_pos.column); } } static VALUE rb_iseq_disasm_recursive(const rb_iseq_t *iseq, VALUE indent) { + const struct rb_iseq_constant_body *const body = iseq->body; VALUE *code; VALUE str = rb_str_new(0, 0); VALUE child = rb_ary_tmp_new(3); @@ -1940,7 +1953,7 @@ rb_iseq_disasm_recursive(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.c#L1953 rb_secure(1); - size = iseq->body->iseq_size; + size = body->iseq_size; indent_len = RSTRING_LEN(indent); indent_str = RSTRING_PTR(indent); @@ -1949,7 +1962,7 @@ rb_iseq_disasm_recursive(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.c#L1962 rb_str_cat2(str, "== disasm: "); rb_str_append(str, iseq_inspect(iseq)); - rb_str_catf(str, " (catch: %s)", iseq->body->catch_except_p ? "TRUE" : "FALSE"); + rb_str_catf(str, " (catch: %s)", body->catch_except_p ? "TRUE" : "FALSE"); if ((l = RSTRING_LEN(str) - indent_len) < header_minlen) { rb_str_modify_expand(str, header_minlen - l); memset(RSTRING_END(str), '=', header_minlen - l); @@ -1957,15 +1970,15 @@ rb_iseq_disasm_recursive(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.c#L1970 rb_str_cat2(str, "\n"); /* show catch table information */ - if (iseq->body->catch_table) { + if (body->catch_table) { rb_str_cat(str, indent_str, indent_len); rb_str_cat2(str, "== catch table\n"); } - if (iseq->body->catch_table) { + if (body->catch_table) { rb_str_cat_cstr(indent, "| "); indent_str = RSTRING_PTR(indent); - for (i = 0; i < iseq->body->catch_table->size; i++) { - const struct iseq_catch_table_entry *entry = &iseq->body->catch_table->entries[i]; + for (i = 0; i < body->catch_table->size; i++) { + const struct iseq_catch_table_entry *entry = &body->catch_table->entries[i]; rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n", @@ -1981,51 +1994,52 @@ rb_iseq_disasm_recursive(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.c#L1994 rb_str_resize(indent, indent_len); indent_str = RSTRING_PTR(indent); } - if (iseq->body->catch_table) { + if (body->catch_table) { rb_str_cat(str, indent_str, indent_len); rb_str_cat2(str, "|-------------------------------------" "-----------------------------------\n"); } /* show local table information */ - if (iseq->body->local_table) { + if (body->local_table) { + const struct rb_iseq_param_keyword *const keyword = body->param.keyword; rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "local table (size: %d, argc: %d " "[opts: %d, rest: %d, post: %d, block: %d, kw: %d@%d, kwrest: %d])\n", - iseq->body->local_table_size, - iseq->body->param.lead_num, - iseq->body->param.opt_num, - iseq->body->param.flags.has_rest ? iseq->body->param.rest_start : -1, - iseq->body->param.post_num, - iseq->body->param.flags.has_block ? iseq->body->param.block_start : -1, - iseq->body->param.flags.has_kw ? iseq->body->param.keyword->num : -1, - iseq->body->param.flags.has_kw ? iseq->body->param.keyword->required_num : -1, - iseq->body->param.flags.has_kwrest ? iseq->body->param.keyword->rest_start : -1); + body->local_table_size, + body->param.lead_num, + body->param.opt_num, + body->param.flags.has_rest ? body->param.rest_start : -1, + body->param.post_num, + body->param.flags.has_block ? body->param.block_start : -1, + body->param.flags.has_kw ? keyword->num : -1, + body->param.flags.has_kw ? keyword->required_num : -1, + body->param.flags.has_kwrest ? keyword->rest_start : -1); - for (i = iseq->body->local_table_size; i > 0;) { - int li = iseq->body->local_table_size - --i - 1; + for (i = body->local_table_size; i > 0;) { + int li = body->local_table_size - --i - 1; long width; VALUE name = local_var_name(iseq, 0, i); char argi[0x100] = ""; char opti[0x100] = ""; - if (iseq->body->param.flags.has_opt) { - int argc = iseq->body->param.lead_num; - int opts = iseq->body->param.opt_num; + if (body->param.flags.has_opt) { + int argc = body->param.lead_num; + int opts = body->param.opt_num; if (li >= argc && li < argc + opts) { snprintf(opti, sizeof(opti), "Opt=%"PRIdVALUE, - iseq->body->param.opt_table[li - argc]); + body->param.opt_table[li - argc]); } } snprintf(argi, sizeof(argi), "%s%s%s%s%s%s", /* arg, opts, rest, post, kwrest, block */ - iseq->body->param.lead_num > li ? "Arg" : "", + body->param.lead_num > li ? "Arg" : "", opti, - (iseq->body->param.flags.has_rest && iseq->body->param.rest_start == li) ? "Rest" : "", - (iseq->body->param.flags.has_post && iseq->body->param.post_start <= li && li < iseq->body->param.post_start + iseq->body->param.post_num) ? "Post" : "", - (iseq->body->param.flags.has_kwrest && iseq->body->param.keyword->rest_start == li) ? "Kwrest" : "", - (iseq->body->param.flags.has_block && iseq->body->param.block_start == li) ? "Block" : ""); + (body->param.flags.has_rest && body->param.rest_start == li) ? "Rest" : "", + (body->param.flags.has_post && body->param.post_start <= li && li < body->param.post_start + body->param.post_num) ? "Post" : "", + (body->param.flags.has_kwrest && keyword->rest_start == li) ? "Kwrest" : "", + (body->param.flags.has_block && body->param.block_start == li) ? "Block" : ""); rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "[%2d] ", i + 1); @@ -2069,17 +2083,18 @@ rb_iseq_all_children(const rb_iseq_t *is https://github.com/ruby/ruby/blob/trunk/iseq.c#L2083 VALUE *code = rb_iseq_original_iseq(iseq); VALUE all_children = rb_obj_hide(rb_ident_hash_new()); VALUE child; + const struct rb_iseq_constant_body *const body = iseq->body; - if (iseq->body->catch_table) { - for (i = 0; i < iseq->body->catch_table->size; i++) { - co (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/