ruby-changes:24720
From: shugo <ko1@a...>
Date: Wed, 22 Aug 2012 11:25:26 +0900 (JST)
Subject: [ruby-changes:24720] shugo:r36771 (trunk): * vm_insnhelper.c (vm_setup_method): should not enable tail call
shugo 2012-08-22 11:25:16 +0900 (Wed, 22 Aug 2012) New Revision: 36771 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36771 Log: * vm_insnhelper.c (vm_setup_method): should not enable tail call optimization for frames with VM_FRAME_FLAG_FINISH. [ruby-dev:46065] [Bug #6901] Modified files: trunk/ChangeLog trunk/test/ruby/test_optimization.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 36770) +++ ChangeLog (revision 36771) @@ -1,3 +1,9 @@ +Wed Aug 22 11:23:35 2012 Shugo Maeda <shugo@r...> + + * 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 <naruse@r...> * lib/rubygems/test_case.rb: run test with psych if exist. Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 36770) +++ vm_insnhelper.c (revision 36771) @@ -510,7 +510,8 @@ 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); Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 36770) +++ test/ruby/test_optimization.rb (revision 36771) @@ -160,4 +160,25 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/