From bf797ed9b094289d79b485fd3794cb40acb368b0 Mon Sep 17 00:00:00 2001 From: shugo Date: Wed, 22 Aug 2012 02:25:16 +0000 Subject: [PATCH] * vm_insnhelper.c (vm_setup_method): should not enable tail call optimization for frames with VM_FRAME_FLAG_FINISH. [ruby-dev:46065] [Bug #6901] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ test/ruby/test_optimization.rb | 21 +++++++++++++++++++++ vm_insnhelper.c | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 667445c6ce..094e38d314 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Aug 22 11:23:35 2012 Shugo Maeda + + * vm_insnhelper.c (vm_setup_method): should not enable tail call + optimization for frames with VM_FRAME_FLAG_FINISH. + [ruby-dev:46065] [Bug #6901] + Wed Aug 22 11:20:47 2012 NARUSE, Yui * lib/rubygems/test_case.rb: run test with psych if exist. diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index ed604e7bc3..1b0c730996 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -160,4 +160,25 @@ class TestRubyOptimization < Test::Unit::TestCase EOF assert_equal(9131, Tailcall.new.fact(3000).to_s.size, bug4082) end + + def test_tailcall_with_block + bug6901 = '[ruby-dev:46065]' + + option = { + tailcall_optimization: true, + trace_instruction: false, + } + iseq = RubyVM::InstructionSequence.new(<<-EOF, "Bug#6901", bug6901, nil, option).eval + def identity(val) + val + end + + def delay + -> { + identity(yield) + } + end + EOF + assert_equal(123, delay { 123 }.call, bug6901) + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index b774f1206f..c9c1b222a3 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -510,7 +510,8 @@ vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, sp = rsp + iseq->arg_size; - if (LIKELY(!(flag & VM_CALL_TAILCALL_BIT))) { + if (LIKELY(!(flag & VM_CALL_TAILCALL_BIT) || + VM_FRAME_TYPE_FINISH_P(th->cfp))) { if (0) printf("local_size: %d, arg_size: %d\n", iseq->local_size, iseq->arg_size);