ruby-changes:54760
From: nobu <ko1@a...>
Date: Fri, 1 Feb 2019 14:11:13 +0900 (JST)
Subject: [ruby-changes:54760] nobu:r66977 (trunk): Revert r63383, r63248 "compile.c: copy a short insn with leave"
nobu 2019-02-01 14:11:08 +0900 (Fri, 01 Feb 2019) New Revision: 66977 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66977 Log: Revert r63383, r63248 "compile.c: copy a short insn with leave" When copying `leave` insn, TRACE also should be copied if it is present, but this optimization is trivial and not worth the complexity. [ruby-core:91366] [Bug #15578] 4cae5353c03009beb1e0a1619422072773580609 5afd479de63b6609ddcd1510da94d2c1ac384f7f Modified files: trunk/compile.c trunk/test/coverage/test_coverage.rb trunk/test/ruby/test_settracefunc.rb Index: test/ruby/test_settracefunc.rb =================================================================== --- test/ruby/test_settracefunc.rb (revision 66976) +++ test/ruby/test_settracefunc.rb (revision 66977) @@ -2153,4 +2153,16 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L2153 assert_equal Array.new(2){th}, events end + + def test_return_event_with_rescue + obj = Object.new + def obj.example + 1 if 1 == 1 + rescue + end + ok = false + tp = TracePoint.new(:return) {ok = true} + tp.enable {obj.example} + assert ok, "return event should be emitted" + end end Index: test/coverage/test_coverage.rb =================================================================== --- test/coverage/test_coverage.rb (revision 66976) +++ test/coverage/test_coverage.rb (revision 66977) @@ -171,8 +171,8 @@ class TestCoverage < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/coverage/test_coverage.rb#L171 result = { :branches => { [:"&.", 0, 1, 0, 1, 8] => { - [:then, 1, 1, 0, 1, 8] => 1, - [:else, 2, 1, 0, 1, 8] => 0, + [:then, 1, 1, 0, 1, 8] => 0, + [:else, 2, 1, 0, 1, 8] => 1, }, }, } Index: compile.c =================================================================== --- compile.c (revision 66976) +++ compile.c (revision 66977) @@ -2709,7 +2709,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2709 optimize_checktype(iseq, iobj); if (IS_INSN_ID(iobj, jump)) { - INSN *niobj, *diobj, *piobj, *dniobj; + INSN *niobj, *diobj, *piobj; diobj = (INSN *)get_destination_insn(iobj); niobj = (INSN *)get_next_insn(iobj); @@ -2740,11 +2740,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2740 remove_unreachable_chunk(iseq, iobj->link.next); goto again; } - else if (dniobj = 0, - IS_INSN_ID(diobj, leave) || - (diobj->operand_size == 0 && - (dniobj = (INSN *)get_next_insn(diobj)) != 0 && - (IS_INSN_ID(dniobj, leave) || (dniobj = 0)))) { + else if (IS_INSN_ID(diobj, leave)) { INSN *pop; /* * jump LABEL @@ -2760,19 +2756,12 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2756 */ /* replace */ unref_destination(iobj, 0); - iobj->insn_id = diobj->insn_id; + iobj->insn_id = BIN(leave); iobj->operand_size = 0; iobj->insn_info = diobj->insn_info; - if (dniobj) { - dniobj = new_insn_body(iseq, dniobj->insn_info.line_no, BIN(leave), 0); - ELEM_INSERT_NEXT(&iobj->link, &dniobj->link); - } - else { - dniobj = iobj; - } /* adjust stack depth */ pop = new_insn_body(iseq, diobj->insn_info.line_no, BIN(pop), 0); - ELEM_INSERT_NEXT(&dniobj->link, &pop->link); + ELEM_INSERT_NEXT(&iobj->link, &pop->link); goto again; } else if ((piobj = (INSN *)get_prev_insn(iobj)) != 0 && -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/