ruby-changes:71500
From: Peter <ko1@a...>
Date: Thu, 24 Mar 2022 23:04:13 +0900 (JST)
Subject: [ruby-changes:71500] 5f10bd634f (master): Add ISEQ_BODY macro
https://git.ruby-lang.org/ruby.git/commit/?id=5f10bd634f From 5f10bd634fb6ae8f74a4ea730176233b0ca96954 Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Wed, 23 Mar 2022 15:19:48 -0400 Subject: Add ISEQ_BODY macro Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using this macro will make it easier for us to change the allocation strategy of rb_iseq_constant_body when using Variable Width Allocation. --- ast.c | 4 +- compile.c | 334 +++++++++++++++--------------- cont.c | 2 +- eval.c | 4 +- gc.c | 6 +- insns.def | 6 +- iseq.c | 104 +++++----- iseq.h | 22 +- mjit.c | 62 +++--- mjit.h | 2 +- mjit_compile.c | 38 ++-- mjit_worker.c | 52 ++--- proc.c | 32 +-- thread.c | 8 +- tool/mk_builtin_loader.rb | 2 +- tool/ruby_vm/views/_mjit_compile_send.erb | 6 +- vm.c | 80 +++---- vm_args.c | 86 ++++---- vm_backtrace.c | 26 +-- vm_core.h | 4 +- vm_dump.c | 24 +-- vm_eval.c | 8 +- vm_exec.h | 6 +- vm_insnhelper.c | 172 +++++++-------- vm_method.c | 26 +-- yjit_codegen.c | 62 +++--- yjit_core.c | 10 +- yjit_iface.c | 14 +- 28 files changed, 601 insertions(+), 601 deletions(-) diff --git a/ast.c b/ast.c index 0515689a29..42d4126a5b 100644 --- a/ast.c +++ b/ast.c @@ -215,14 +215,14 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script https://github.com/ruby/ruby/blob/trunk/ast.c#L215 iseq = rb_method_iseq(body); } if (iseq) { - node_id = iseq->body->location.node_id; + node_id = ISEQ_BODY(iseq)->location.node_id; } } if (!iseq) { return Qnil; } - lines = iseq->body->variable.script_lines; + lines = ISEQ_BODY(iseq)->variable.script_lines; VALUE path = rb_iseq_path(iseq); int e_option = RSTRING_LEN(path) == 2 && memcmp(RSTRING_PTR(path), "-e", 2) == 0; diff --git a/compile.c b/compile.c index cd3f0e2a9d..67641fcfb6 100644 --- a/compile.c +++ b/compile.c @@ -534,11 +534,9 @@ static void https://github.com/ruby/ruby/blob/trunk/compile.c#L534 verify_call_cache(rb_iseq_t *iseq) { #if CPDEBUG - // fprintf(stderr, "ci_size:%d\t", iseq->body->ci_size); rp(iseq); - VALUE *original = rb_iseq_original_iseq(iseq); size_t i = 0; - while (i < iseq->body->iseq_size) { + while (i < ISEQ_BODY(iseq)->iseq_size) { VALUE insn = original[i]; const char *types = insn_op_types(insn); @@ -556,8 +554,8 @@ verify_call_cache(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L554 i += insn_len(insn); } - for (unsigned int i=0; i<iseq->body->ci_size; i++) { - struct rb_call_data *cd = &iseq->body->call_data[i]; + for (unsigned int i=0; i<ISEQ_BODY(iseq)->ci_size; i++) { + struct rb_call_data *cd = &ISEQ_BODY(iseq)->call_data[i]; const struct rb_callinfo *ci = cd->ci; const struct rb_callcache *cc = cd->cc; if (cc != NULL && cc != vm_cc_empty()) { @@ -758,7 +756,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L756 iseq_set_local_table(iseq, node->nd_tbl); iseq_set_arguments(iseq, ret, node->nd_args); - switch (iseq->body->type) { + switch (ISEQ_BODY(iseq)->type) { case ISEQ_TYPE_BLOCK: { LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0); @@ -768,13 +766,13 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L766 end->rescued = LABEL_RESCUE_END; ADD_TRACE(ret, RUBY_EVENT_B_CALL); - NODE dummy_line_node = generate_dummy_line_node(FIX2INT(iseq->body->location.first_lineno), -1); + NODE dummy_line_node = generate_dummy_line_node(FIX2INT(ISEQ_BODY(iseq)->location.first_lineno), -1); ADD_INSN (ret, &dummy_line_node, nop); ADD_LABEL(ret, start); CHECK(COMPILE(ret, "block body", node->nd_body)); ADD_LABEL(ret, end); ADD_TRACE(ret, RUBY_EVENT_B_RETURN); - ISEQ_COMPILE_DATA(iseq)->last_line = iseq->body->location.code_location.end_pos.lineno; + ISEQ_COMPILE_DATA(iseq)->last_line = ISEQ_BODY(iseq)->location.code_location.end_pos.lineno; /* wide range catch handler must put at last */ ADD_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start); @@ -809,7 +807,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L807 const char *m; #define INVALID_ISEQ_TYPE(type) \ ISEQ_TYPE_##type: m = #type; goto invalid_iseq_type - switch (iseq->body->type) { + switch (ISEQ_BODY(iseq)->type) { case INVALID_ISEQ_TYPE(METHOD); case INVALID_ISEQ_TYPE(CLASS); case INVALID_ISEQ_TYPE(BLOCK); @@ -829,7 +827,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L827 CHECK(COMPILE(ret, "ensure", node)); break; default: - COMPILE_ERROR(ERROR_ARGS "unknown scope: %d", iseq->body->type); + COMPILE_ERROR(ERROR_ARGS "unknown scope: %d", ISEQ_BODY(iseq)->type); return COMPILE_NG; invalid_iseq_type: COMPILE_ERROR(ERROR_ARGS "compile/ISEQ_TYPE_%s should not be reached", m); @@ -837,7 +835,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L835 } } - if (iseq->body->type == ISEQ_TYPE_RESCUE || iseq->body->type == ISEQ_TYPE_ENSURE) { + if (ISEQ_BODY(iseq)->type == ISEQ_TYPE_RESCUE || ISEQ_BODY(iseq)->type == ISEQ_TYPE_ENSURE) { NODE dummy_line_node = generate_dummy_line_node(0, -1); ADD_GETLOCAL(ret, &dummy_line_node, LVAR_ERRINFO, 0); ADD_INSN1(ret, &dummy_line_node, throw, INT2FIX(0) /* continue throw */ ); @@ -864,10 +862,10 @@ rb_iseq_translate_threaded_code(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L862 #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE const void * const *table = rb_vm_get_insns_address_table(); unsigned int i; - VALUE *encoded = (VALUE *)iseq->body->iseq_encoded; + VALUE *encoded = (VALUE *)ISEQ_BODY(iseq)->iseq_encoded; - for (i = 0; i < iseq->body->iseq_size; /* */ ) { - int insn = (int)iseq->body->iseq_encoded[i]; + for (i = 0; i < ISEQ_BODY(iseq)->iseq_size; /* */ ) { + int insn = (int)ISEQ_BODY(iseq)->iseq_encoded[i]; int len = insn_len(insn); encoded[i] = (VALUE)table[insn]; i += len; @@ -883,14 +881,14 @@ rb_iseq_original_iseq(const rb_iseq_t *iseq) /* cold path */ https://github.com/ruby/ruby/blob/trunk/compile.c#L881 VALUE *original_code; if (ISEQ_ORIGINAL_ISEQ(iseq)) return ISEQ_ORIGINAL_ISEQ(iseq); - original_code = ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, iseq->body->iseq_size); - MEMCPY(original_code, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size); + original_code = ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, ISEQ_BODY(iseq)->iseq_size); + MEMCPY(original_code, ISEQ_BODY(iseq)->iseq_encoded, VALUE, ISEQ_BODY(iseq)->iseq_size); #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE { unsigned int i; - for (i = 0; i < iseq->body->iseq_size; /* */ ) { + for (i = 0; i < ISEQ_BODY(iseq)->iseq_size; /* */ ) { const void *addr = (const void *)original_code[i]; const int insn = rb_vm_insn_addr2insn(addr); @@ -1298,8 +1296,7 @@ new_callinfo(rb_iseq_t *iseq, ID mid, int argc, unsigned int flag, struct rb_cal https://github.com/ruby/ruby/blob/trunk/compile.c#L1296 argc += kw_arg->keyword_len; } - // fprintf(stderr, "[%d] id:%s\t", (int)iseq->body->ci_size, rb_id2name(mid)); rp(iseq); - iseq->body->ci_size++; + ISEQ_BODY(iseq)->ci_size++; const struct rb_callinfo *ci = vm_ci_new(mid, flag, argc, kw_arg); RB_OBJ_WRITTEN(iseq, Qundef, ci); return ci; @@ -1330,7 +1327,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node, https://github.com/ruby/ruby/blob/trunk/compile.c#L1327 ast.root = node; ast.compile_option = 0; - ast.script_lines = iseq->body->variable.script_lines; + ast.script_lines = ISEQ_BODY(iseq)->variable.script_lines; debugs("[new_child_iseq]> ---------------------------------------\n"); int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth; @@ -1362,7 +1359,7 @@ set_catch_except_p(struct rb_iseq_constant_body *body) https://github.com/ruby/ruby/blob/trunk/compile.c#L1359 { body->catch_except_p = TRUE; if (body->parent_iseq != NULL) { - set_catch_except_p(body->parent_iseq->body); + set_catch_except_p(ISEQ_BODY(body->parent_iseq)); } } @@ -1499,16 +1496,16 @@ iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) https://github.com/ruby/ruby/blob/trunk/compile.c#L1496 if (!rb_iseq_translate_threaded_code(iseq)) return COMPILE_NG; debugs("[compile step 6 (update_catch_except_flags)] \n"); - update_catch_except_flags(iseq->body); + update_catch_except_flags(ISEQ_BODY(iseq)); debugs("[compile step 6.1 (remove unused catch tables)] \n"); - if (!iseq->body->catch_except_p && iseq->body->catch_table) { - xfree(iseq->body->catch_table); - iseq->body->catch_table = NULL; + (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/