[前][次][番号順一覧][スレッド一覧]

ruby-changes:73727

From: Samuel <ko1@a...>
Date: Sun, 25 Sep 2022 20:41:43 +0900 (JST)
Subject: [ruby-changes:73727] 22af2e9084 (master): Rework vm_core to use `int first_lineno` struct member.

https://git.ruby-lang.org/ruby.git/commit/?id=22af2e9084

From 22af2e9084d869b0d1eb24e4c11bc1fd62b7c50d Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Sun, 25 Sep 2022 21:07:18 +1300
Subject: Rework vm_core to use `int first_lineno` struct member.

---
 compile.c            |  6 +++---
 gc.c                 |  5 ++---
 iseq.c               |  6 +++---
 lib/mjit/compiler.rb |  4 ++--
 mjit.c               | 26 ++++++++++----------------
 mjit_c.rb            |  7 ++++++-
 proc.c               |  6 +++---
 vm_backtrace.c       |  4 ++--
 vm_core.h            |  4 ++--
 vm_method.c          |  2 +-
 10 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/compile.c b/compile.c
index 26b10ff43c..d9a17560be 100644
--- a/compile.c
+++ b/compile.c
@@ -766,7 +766,7 @@ 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(iseq)->location.first_lineno), -1);
+                NODE dummy_line_node = generate_dummy_line_node(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));
@@ -12024,7 +12024,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L12024
     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, RB_INT2NUM(body->location.first_lineno));
     ibf_dump_write_small_value(dump, body->location.node_id);
     ibf_dump_write_small_value(dump, body->location.code_location.beg_pos.lineno);
     ibf_dump_write_small_value(dump, body->location.code_location.beg_pos.column);
@@ -12195,7 +12195,7 @@ ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset) https://github.com/ruby/ruby/blob/trunk/compile.c#L12195
     load_body->variable.flip_count = variable_flip_count;
     load_body->variable.script_lines = Qnil;
 
-    load_body->location.first_lineno = location_first_lineno;
+    load_body->location.first_lineno = RB_NUM2INT(location_first_lineno);
     load_body->location.node_id = location_node_id;
     load_body->location.code_location.beg_pos.lineno = location_code_location_beg_pos_lineno;
     load_body->location.code_location.beg_pos.column = location_code_location_beg_pos_column;
diff --git a/gc.c b/gc.c
index ecb4aa7e20..d026139d7b 100644
--- a/gc.c
+++ b/gc.c
@@ -13804,11 +13804,10 @@ rb_raw_iseq_info(char *const buff, const size_t buff_size, const rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/gc.c#L13804
 {
     if (buff_size > 0 && ISEQ_BODY(iseq) && ISEQ_BODY(iseq)->location.label && !RB_TYPE_P(ISEQ_BODY(iseq)->location.pathobj, T_MOVED)) {
         VALUE path = rb_iseq_path(iseq);
-        VALUE n = ISEQ_BODY(iseq)->location.first_lineno;
+        int n = ISEQ_BODY(iseq)->location.first_lineno;
         snprintf(buff, buff_size, " %s@%s:%d",
                  RSTRING_PTR(ISEQ_BODY(iseq)->location.label),
-                 RSTRING_PTR(path),
-                 n ? FIX2INT(n) : 0 );
+                 RSTRING_PTR(path), n);
     }
 }
 
diff --git a/iseq.c b/iseq.c
index 5f2143baa9..a4792d81fd 100644
--- a/iseq.c
+++ b/iseq.c
@@ -598,7 +598,7 @@ iseq_location_setup(rb_iseq_t *iseq, VALUE name, VALUE path, VALUE realpath, int https://github.com/ruby/ruby/blob/trunk/iseq.c#L598
     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 = RB_INT2NUM(first_lineno);
+    loc->first_lineno = first_lineno;
     if (code_location) {
         loc->node_id = node_id;
         loc->code_location = *code_location;
@@ -1235,7 +1235,7 @@ rb_iseq_base_label(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1235
 VALUE
 rb_iseq_first_lineno(const rb_iseq_t *iseq)
 {
-    return ISEQ_BODY(iseq)->location.first_lineno;
+    return RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);
 }
 
 VALUE
@@ -3164,7 +3164,7 @@ iseq_data_to_ary(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3164
     rb_ary_push(val, iseq_body->location.label);
     rb_ary_push(val, rb_iseq_path(iseq));
     rb_ary_push(val, rb_iseq_realpath(iseq));
-    rb_ary_push(val, iseq_body->location.first_lineno);
+    rb_ary_push(val, RB_INT2NUM(iseq_body->location.first_lineno));
     rb_ary_push(val, ID2SYM(type));
     rb_ary_push(val, locals);
     rb_ary_push(val, params);
diff --git a/lib/mjit/compiler.rb b/lib/mjit/compiler.rb
index 254ecc885f..49f28ab690 100644
--- a/lib/mjit/compiler.rb
+++ b/lib/mjit/compiler.rb
@@ -785,8 +785,8 @@ module RubyVM::MJIT https://github.com/ruby/ruby/blob/trunk/lib/mjit/compiler.rb#L785
 
             if C.mjit_opts.verbose >= 1 # print beforehand because ISeq may be GCed during copy job.
               child_location = child_iseq.body.location
-              $stderr.puts "JIT inline: #{child_location.label}@#{C.rb_iseq_path(child_iseq)}:#{child_location.first_lineno} " \
-                "=> #{iseq.body.location.label}@#{C.rb_iseq_path(iseq)}:#{iseq.body.location.first_lineno}"
+              $stderr.puts "JIT inline: #{child_location.label}@#{C.rb_iseq_path(child_iseq)}:#{C.rb_iseq_first_lineno(child_iseq)} " \
+                "=> #{iseq.body.location.label}@#{C.rb_iseq_path(iseq)}:#{C.rb_iseq_first_lineno(iseq)}"
             end
             if !precompile_inlinable_child_iseq(f, child_iseq, status, ci, cc, pos)
               return false
diff --git a/mjit.c b/mjit.c
index 1997eaa939..80743a150b 100644
--- a/mjit.c
+++ b/mjit.c
@@ -707,15 +707,12 @@ mjit_compact(char* c_file) https://github.com/ruby/ruby/blob/trunk/mjit.c#L707
         char funcname[MAXPATHLEN];
         sprint_funcname(funcname, child_unit);
 
-        long iseq_lineno = 0;
-        if (FIXNUM_P(ISEQ_BODY(child_unit->iseq)->location.first_lineno))
-            // FIX2INT may fallback to rb_num2long(), which is a method call and dangerous in MJIT worker. So using only FIX2LONG.
-            iseq_lineno = FIX2LONG(ISEQ_BODY(child_unit->iseq)->location.first_lineno);
+        int iseq_lineno = ISEQ_BODY(child_unit->iseq)->location.first_lineno;
         const char *sep = "@";
         const char *iseq_label = RSTRING_PTR(ISEQ_BODY(child_unit->iseq)->location.label);
         const char *iseq_path = RSTRING_PTR(rb_iseq_path(child_unit->iseq));
         if (!iseq_label) iseq_label = sep = "";
-        fprintf(f, "\n/* %s%s%s:%ld */\n", iseq_label, sep, iseq_path, iseq_lineno);
+        fprintf(f, "\n/* %s%s%s:%d */\n", iseq_label, sep, iseq_path, iseq_lineno);
         success &= mjit_compile(f, child_unit->iseq, funcname, child_unit->id);
     }
 
@@ -875,24 +872,21 @@ mjit_compile_unit(struct rb_mjit_unit *unit) https://github.com/ruby/ruby/blob/trunk/mjit.c#L872
     compile_prelude(f);
 
     // To make MJIT worker thread-safe against GC.compact, copy ISeq values while `in_jit` is true.
-    long iseq_lineno = 0;
-    if (FIXNUM_P(ISEQ_BODY(unit->iseq)->location.first_lineno))
-        // FIX2INT may fallback to rb_num2long(), which is a method call and dangerous in MJIT worker. So using only FIX2LONG.
-        iseq_lineno = FIX2LONG(ISEQ_BODY(unit->iseq)->location.first_lineno);
+    int iseq_lineno = ISEQ_BODY(unit->iseq)->location.first_lineno;
     char *iseq_label = alloca(RSTRING_LEN(ISEQ_BODY(unit->iseq)->location.label) + 1);
     char *iseq_path  = alloca(RSTRING_LEN(rb_iseq_path(unit->iseq)) + 1);
     strcpy(iseq_label, RSTRING_PTR(ISEQ_BODY(unit->iseq)->location.label));
     strcpy(iseq_path,  RSTRING_PTR(rb_iseq_path(unit->iseq)));
 
-    verbose(2, "start compilation: %s@%s:%ld -> %s", iseq_label, iseq_path, iseq_lineno, c_file);
-    fprintf(f, "/* %s@%s:%ld */\n\n", iseq_label, iseq_path, iseq_lineno);
+    verbose(2, "start compilation: %s@%s:%d -> %s", iseq_label, iseq_path, iseq_lineno, c_file);
+    fprintf(f, "/* %s@%s:%d */\n\n", iseq_label, iseq_path, iseq_lineno);
     bool success = mjit_compile(f, unit->iseq, funcname, unit->id);
 
     fclose(f);
     if (!success) {
         if (!mjit_opts.save_temps)
             remove_file(c_file);
-        verbose(1, "JIT failure: %s@%s:%ld -> %s", iseq_label, iseq_path, iseq_lineno, c_file);
+        verbose(1, "JIT failure: %s@%s:%d -> %s", iseq_label, iseq_path, iseq_lineno, c_file);
         return 1;
     }
 
@@ -1372,9 +1366,9 @@ mjit_notify_waitpid(int exit_code) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1366
             rb_iseq_t *iseq = current_cc_unit->iseq;
             if ((uintptr_t)func > (uintptr_t)LAST_JIT_ISEQ_FUNC) {
                 double end_time = real_ms_time();
-                verbose(1, "JIT success (%.1fms): %s@%s:%ld -> %s",
+                verbose(1, "JIT success (%.1fms): %s@%s:%d -> %s",
                         end_time - current_cc_ms, RSTRING_PTR(ISEQ_BODY(iseq)->location.label),
-                        RSTRING_PTR(rb_iseq_path(iseq)), FIX2LONG(ISEQ_BODY(iseq)->location.first_lineno), c_file);
+                        RSTRING_PTR(rb_iseq_path(iseq)), ISEQ_BODY(iseq)->location.first_lineno, c_file);
 
                 add_to_list(current_cc_unit, &active_units);
             }
@@ -1531,7 +1525,7 @@ mjit_recompile(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1525
         return;
 
     verbose(1, "JIT recompile: %s@%s:%d", RSTRING_PTR(ISEQ_BODY(iseq)->location.label),
-            RSTRING_PTR(rb_iseq_path(iseq)), FIX2INT(ISEQ_BODY(iseq)->location.first_lineno));
+            RSTRING_PTR(rb_iseq_path(iseq)), ISEQ_BODY(iseq)->location.first_lineno);
     V (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]