diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-30 05:15:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-30 05:15:07 +0000 |
commit | 484cc6b3bc828a0bb62aebefd7fdc2c86cab4f57 (patch) | |
tree | db3f166fa30b980aa4946268c1fd56ae2aae84f9 | |
parent | c49350362569899d694fdda4d0a35a54b5b20ac7 (diff) | |
download | ruby-484cc6b3bc828a0bb62aebefd7fdc2c86cab4f57.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | compile.c | 15 | ||||
-rw-r--r-- | test/ruby/test_optimization.rb | 11 |
2 files changed, 26 insertions, 0 deletions
@@ -4723,6 +4723,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int 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 *const ret, const NODE *const node, int 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); diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 38da8b6c45..d77651f2eb 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -721,6 +721,17 @@ class TestRubyOptimization < Test::Unit::TestCase 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") |