ruby-changes:50833
From: nobu <ko1@a...>
Date: Fri, 30 Mar 2018 14:15:12 +0900 (JST)
Subject: [ruby-changes:50833] nobu:r63040 (trunk): compile.c: do not dump unused callinfos
nobu 2018-03-30 14:15:07 +0900 (Fri, 30 Mar 2018) New Revision: 63040 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63040 Log: compile.c: do not dump unused callinfos * compile.c (compile_if): rewind callinfo indexes used in unreachable paths, to get rid of dumping unused callinfos. [ruby-core:86399] [Bug #14553] Modified files: trunk/compile.c trunk/test/ruby/test_optimization.rb Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 63039) +++ test/ruby/test_optimization.rb (revision 63040) @@ -721,6 +721,17 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L721 END end + def test_callinfo_unreachable_path + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + iseq = RubyVM::InstructionSequence.compile("if false; foo(bar: :baz); else :ok end") + bin = iseq.to_binary + iseq = RubyVM::InstructionSequence.load_from_binary(bin) + assert_instance_of(RubyVM::InstructionSequence, iseq) + assert_equal(:ok, iseq.eval) + end; + end + def test_side_effect_in_popped_splat bug = '[ruby-core:84340] [Bug #14201]' eval("{**(bug = nil; {})};42") Index: compile.c =================================================================== --- compile.c (revision 63039) +++ compile.c (revision 63040) @@ -4723,6 +4723,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L4723 DECL_ANCHOR(else_seq); LABEL *then_label, *else_label, *end_label; VALUE branches = 0; + int ci_size, ci_kw_size; INIT_ANCHOR(cond_seq); INIT_ANCHOR(then_seq); @@ -4733,8 +4734,22 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L4734 compile_branch_condition(iseq, cond_seq, node->nd_cond, then_label, else_label); + + ci_size = iseq->body->ci_size; + ci_kw_size = iseq->body->ci_kw_size; CHECK(COMPILE_(then_seq, "then", node_body, popped)); + if (!then_label->refcnt) { + iseq->body->ci_size = ci_size; + iseq->body->ci_kw_size = ci_kw_size; + } + + ci_size = iseq->body->ci_size; + ci_kw_size = iseq->body->ci_kw_size; CHECK(COMPILE_(else_seq, "else", node_else, popped)); + if (!else_label->refcnt) { + iseq->body->ci_size = ci_size; + iseq->body->ci_kw_size = ci_kw_size; + } ADD_SEQ(ret, cond_seq); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/