summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-02 07:13:22 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-02 07:13:22 +0000
commit0812ab5fecb72f4a83e09fe0c313aca2c7f4a8e5 (patch)
tree125d7d50b56f448124494179e3353dc6a20d9c94
parent0fa65358e0b54a1039b9baf82ad6b4f11a571383 (diff)
merge revision(s) 63040: [Backport #14553]
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/branches/ruby_2_5@66130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--compile.c15
-rw-r--r--test/ruby/test_optimization.rb11
-rw-r--r--version.h6
3 files changed, 29 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index ee3b477e20..c00323707f 100644
--- a/compile.c
+++ b/compile.c
@@ -4580,6 +4580,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);
@@ -4590,8 +4591,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 a59115443c..6b08d07fe2 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -703,6 +703,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")
diff --git a/version.h b/version.h
index 1575f990ca..a98b3b1e9d 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.5.4"
-#define RUBY_RELEASE_DATE "2018-12-01"
-#define RUBY_PATCHLEVEL 116
+#define RUBY_RELEASE_DATE "2018-12-02"
+#define RUBY_PATCHLEVEL 117
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 12
-#define RUBY_RELEASE_DAY 1
+#define RUBY_RELEASE_DAY 2
#include "ruby/version.h"