From 6af6154b418ba392feb6afbc14ef318de4c0e9ef Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 29 Mar 2016 13:25:02 +0000 Subject: merge revision(s) 53658: [Backport #12018] * compile.c (iseq_peephole_optimize): don't apply tailcall optimization to send/invokesuper instructions with blockiseq. This is a follow-up to the changes in r51903; blockiseq is now the third operand of send/invokesuper instructions. [ruby-core:73413] [Bug #12018] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@54401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ compile.c | 8 ++++++-- test/ruby/test_optimization.rb | 16 ++++++++++++++++ version.h | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index fbde95df19..418dff755c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Mar 29 22:08:36 2016 Kazuki Yamaguchi + + * compile.c (iseq_peephole_optimize): don't apply tailcall + optimization to send/invokesuper instructions with blockiseq. + This is a follow-up to the changes in r51903; blockiseq is now + the third operand of send/invokesuper instructions. + [ruby-core:73413] [Bug #12018] + Tue Mar 29 21:22:22 2016 Nobuyoshi Nakada * parse.y (xstring): reset heredoc indent after dedenting, diff --git a/compile.c b/compile.c index b70a069916..e385c83f39 100644 --- a/compile.c +++ b/compile.c @@ -2228,8 +2228,12 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal if (piobj) { struct rb_call_info *ci = (struct rb_call_info *)piobj->operands[0]; - rb_iseq_t *blockiseq = (rb_iseq_t *)piobj->operands[1]; - if (blockiseq == 0) { + if (piobj->insn_id == BIN(send) || piobj->insn_id == BIN(invokesuper)) { + if (piobj->operands[2] == 0) { /* no blockiseq */ + ci->flag |= VM_CALL_TAILCALL; + } + } + else { ci->flag |= VM_CALL_TAILCALL; } } diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 2115fc849d..8804931bca 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -275,6 +275,22 @@ class TestRubyOptimization < Test::Unit::TestCase assert_equal(123, delay { 123 }.call, bug6901) end + def just_yield + yield + end + + def test_tailcall_inhibited_by_block + assert_separately([], <<~'end;') + def just_yield + yield + end + iseq = RubyVM::InstructionSequence + result = iseq.compile("just_yield {:ok}", __FILE__, __FILE__, __LINE__, + tailcall_optimization: true).eval + assert_equal(:ok, result) + end; + end + class Bug10557 def [](_) block_given? diff --git a/version.h b/version.h index a9ed58dd17..3127df53ea 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.3.0" #define RUBY_RELEASE_DATE "2016-03-29" -#define RUBY_PATCHLEVEL 49 +#define RUBY_PATCHLEVEL 50 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 3 -- cgit v1.2.3