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

ruby-changes:52301

From: mame <ko1@a...>
Date: Wed, 22 Aug 2018 20:09:53 +0900 (JST)
Subject: [ruby-changes:52301] mame:r64509 (trunk): compile.c: remove tracecoverage instruction for line coverage

mame	2018-08-22 20:09:47 +0900 (Wed, 22 Aug 2018)

  New Revision: 64509

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64509

  Log:
    compile.c: remove tracecoverage instruction for line coverage
    
    Line coverage was based on special instruction "tracecoverage".
    Now, instead, it uses the mechanism of trace hook [Feature #14104].

  Modified files:
    trunk/compile.c
    trunk/iseq.h
    trunk/test/coverage/test_coverage.rb
    trunk/thread.c
    trunk/vm_insnhelper.c
Index: iseq.h
===================================================================
--- iseq.h	(revision 64508)
+++ iseq.h	(revision 64509)
@@ -72,7 +72,8 @@ ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.h#L72
 			   RUBY_EVENT_CALL  | \
 			   RUBY_EVENT_RETURN| \
 			   RUBY_EVENT_B_CALL| \
-			   RUBY_EVENT_B_RETURN)
+			   RUBY_EVENT_B_RETURN| \
+			   RUBY_EVENT_COVERAGE_LINE)
 
 #define ISEQ_NOT_LOADED_YET   IMEMO_FL_USER1
 #define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2
Index: compile.c
===================================================================
--- compile.c	(revision 64508)
+++ compile.c	(revision 64509)
@@ -260,15 +260,6 @@ struct iseq_compile_data_ensure_node_sta https://github.com/ruby/ruby/blob/trunk/compile.c#L260
 
 #define ADD_TRACE(seq, event) \
   ADD_ELEM((seq), (LINK_ELEMENT *)new_trace_body(iseq, (event)))
-#define ADD_TRACE_LINE_COVERAGE(seq, line) \
-  do { \
-      if (ISEQ_COVERAGE(iseq) && \
-	  ISEQ_LINE_COVERAGE(iseq) && \
-	  (line) > 0) { \
-	  RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \
-	  ADD_INSN2((seq), (line), tracecoverage, INT2FIX(RUBY_EVENT_COVERAGE_LINE), INT2FIX(line)); \
-      } \
-  } while (0)
 
 
 #define DECL_BRANCH_BASE(branches, first_line, first_column, last_line, last_column, type) \
@@ -2021,6 +2012,10 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2012
 		sp = calc_sp_depth(sp, iobj);
 		code_index += insn_data_length(iobj);
 		insn_num++;
+		if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq) && (events & RUBY_EVENT_COVERAGE_LINE)) {
+		    int line = iobj->insn_info.line_no;
+		    RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line - 1, INT2FIX(0));
+		}
 		iobj->insn_info.events |= events;
 		events = 0;
 		break;
@@ -5829,9 +5824,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5824
     }
     else {
 	if (node->flags & NODE_FL_NEWLINE) {
+	    int event = RUBY_EVENT_LINE;
 	    ISEQ_COMPILE_DATA(iseq)->last_line = line;
-	    ADD_TRACE_LINE_COVERAGE(ret, line);
-	    ADD_TRACE(ret, RUBY_EVENT_LINE);
+	    if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
+		event |= RUBY_EVENT_COVERAGE_LINE;
+	    }
+	    ADD_TRACE(ret, event);
 	}
     }
 
@@ -7462,18 +7460,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L7460
 	return COMPILE_NG;
     }
 
-    /* remove tracecoverage instruction if there is no relevant instruction */
-    if (IS_TRACE(ret->last) && ((TRACE*) ret->last)->event == RUBY_EVENT_LINE) {
-	LINK_ELEMENT *insn = ret->last->prev;
-	if (IS_INSN(insn) &&
-	    IS_INSN_ID(insn, tracecoverage) &&
-	    FIX2LONG(OPERAND_AT(insn, 0)) == RUBY_EVENT_COVERAGE_LINE
-	) {
-	    ELEM_REMOVE(insn); /* remove tracecovearge */
-	    RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line - 1, Qnil);
-	}
-    }
-
     debug_node_end();
     return COMPILE_OK;
 }
Index: thread.c
===================================================================
--- thread.c	(revision 64508)
+++ thread.c	(revision 64509)
@@ -5256,7 +5256,7 @@ update_line_coverage(VALUE data, const r https://github.com/ruby/ruby/blob/trunk/thread.c#L5256
     if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
 	VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
 	if (lines) {
-	    long line = FIX2INT(trace_arg->data) - 1;
+	    long line = rb_sourceline() - 1;
 	    long count;
 	    VALUE num;
 	    if (line >= RARRAY_LEN(lines)) { /* no longer tracked */
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 64508)
+++ vm_insnhelper.c	(revision 64509)
@@ -3883,6 +3883,12 @@ vm_trace(rb_execution_context_t *ec, rb_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3883
 	    EXEC_EVENT_HOOK(ec, RUBY_EVENT_LINE, GET_SELF(), 0, 0, 0, Qundef);
 	    reg_cfp->pc--;
 	}
+	if (events & RUBY_EVENT_COVERAGE_LINE) {
+	    reg_cfp->pc++;
+	    vm_dtrace(RUBY_EVENT_COVERAGE_LINE, ec);
+	    EXEC_EVENT_HOOK(ec, RUBY_EVENT_COVERAGE_LINE, GET_SELF(), 0, 0, 0, Qundef);
+	    reg_cfp->pc--;
+	}
 	if (event = (events & (RUBY_EVENT_END | RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN))) {
 	    VM_ASSERT(event == RUBY_EVENT_END ||
 		      event == RUBY_EVENT_RETURN  ||
Index: test/coverage/test_coverage.rb
===================================================================
--- test/coverage/test_coverage.rb	(revision 64508)
+++ test/coverage/test_coverage.rb	(revision 64509)
@@ -194,7 +194,7 @@ class TestCoverage < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/coverage/test_coverage.rb#L194
 
   def test_line_coverage_for_multiple_lines
     result = {
-      :lines => [1, nil, nil, nil, nil, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1, nil, 1, 1, 1, nil, nil, nil, nil, nil, 1]
+      :lines => [nil, 1, nil, nil, nil, 1, nil, nil, nil, 1, nil, 1, nil, nil, nil, nil, 1, 1, nil, 1, nil, nil, nil, nil, 1]
     }
     assert_coverage(<<~"end;", { lines: true }, result) # Bug #14191
       FOO = [

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

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