From: "drbrain (Eric Hodel)" Date: 2013-11-16T09:47:11+09:00 Subject: [ruby-core:58372] [ruby-trunk - Bug #9114] InstructionSequence.compile w/tailcall_optimization: true, trace_instruction: false not working as expected Issue #9114 has been updated by drbrain (Eric Hodel). =begin Here's an update where a call is in tail position, but from the output you'll see only the initial call uses the tail call optimization. source = <<-SOURCE def fact n, acc = 1 if n.zero? acc else fact n - 1, acc * n end end fact 10000 SOURCE i_seq = RubyVM::InstructionSequence.new source, nil, nil, nil, tailcall_optimization: false puts i_seq.disasm begin value = i_seq.eval p value rescue SystemStackError => e puts e end i_seq = RubyVM::InstructionSequence.new source, nil, nil, nil, tailcall_optimization: true puts i_seq.disasm begin value = i_seq.eval p value rescue SystemStackError => e puts e end =end ---------------------------------------- Bug #9114: InstructionSequence.compile w/tailcall_optimization: true, trace_instruction: false not working as expected https://bugs.ruby-lang.org/issues/9114#change-42971 Author: garysweaver (Gary Weaver) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN Code to reproduce is a recursive sort I wrote; I was trying to compile RubyVM::InstructionSequence with tailcall_optimization: true, trace_instruction: false, which has worked before, but not for this case. method_string = < recursively_sort a SystemStackError: stack level too deep from /Users/gary/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/irb/workspace.rb:80 Maybe IRB bug! 2.0.0p247 :014 > recursively_sort a SystemStackError: stack level too deep from /Users/gary/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/workspace.rb:86 Maybe IRB bug! I had assumed that since the blocks were defined within the tail call optimized method that referenced the method compiled with TCO, it would still be tail call optimized. Did I do something wrong/is there a suggested workaround? Thanks for looking at this! -- http://bugs.ruby-lang.org/