ruby-changes:44642
From: nagachika <ko1@a...>
Date: Sat, 12 Nov 2016 00:35:34 +0900 (JST)
Subject: [ruby-changes:44642] nagachika:r56715 (ruby_2_3): merge revision(s) 56208, 56663: [Backport #12905]
nagachika 2016-11-12 00:35:29 +0900 (Sat, 12 Nov 2016) New Revision: 56715 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56715 Log: merge revision(s) 56208,56663: [Backport #12905] * compile.c (iseq_peephole_optimize): enable tail call optimization inside a conditional block. Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ChangeLog branches/ruby_2_3/compile.c branches/ruby_2_3/test/ruby/test_optimization.rb branches/ruby_2_3/version.h Index: ruby_2_3/compile.c =================================================================== --- ruby_2_3/compile.c (revision 56714) +++ ruby_2_3/compile.c (revision 56715) @@ -2240,6 +2240,13 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/ruby_2_3/compile.c#L2240 /*case BIN(trace):*/ next = next->next; break; + case BIN(jump): + /* if cond + * return tailcall + * end + */ + next = get_destination_insn((INSN *)next); + break; case BIN(leave): piobj = iobj; default: Index: ruby_2_3/test/ruby/test_optimization.rb =================================================================== --- ruby_2_3/test/ruby/test_optimization.rb (revision 56714) +++ ruby_2_3/test/ruby/test_optimization.rb (revision 56715) @@ -230,7 +230,7 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_optimization.rb#L230 assert_equal true, MyObj.new == nil end - def self.tailcall(klass, src, file = nil, path = nil, line = nil) + def self.tailcall(klass, src, file = nil, path = nil, line = nil, tailcall: true) unless file loc, = caller_locations(1, 1) file = loc.path @@ -238,7 +238,7 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_optimization.rb#L238 end RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}", file, (path || file), line, - tailcall_optimization: true, + tailcall_optimization: tailcall, trace_instruction: false) .eval[klass] end @@ -334,6 +334,35 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_optimization.rb#L334 message(bug12565) {disasm(:add_one_and_two)}) end + def test_tailcall_condition_block + bug = '[ruby-core:78015] [Bug #12905]' + + src = "#{<<-"begin;"}\n#{<<-"end;"}" + begin; + def run(current, final) + if current < final + run(current+1, final) + else + nil + end + end + end; + + obj = Object.new + self.class.tailcall(obj.singleton_class, src, tailcall: false) + e = assert_raise(SystemStackError) { + obj.run(1, Float::INFINITY) + } + level = e.backtrace_locations.size + obj = Object.new + self.class.tailcall(obj.singleton_class, src, tailcall: true) + level *= 2 + mesg = message {"#{bug}: #{$!.backtrace_locations.size} / #{level} stack levels"} + assert_nothing_raised(SystemStackError, mesg) { + obj.run(1, level) + } + end + class Bug10557 def [](_) block_given? Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 56714) +++ ruby_2_3/version.h (revision 56715) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.2" #define RUBY_RELEASE_DATE "2016-11-12" -#define RUBY_PATCHLEVEL 206 +#define RUBY_PATCHLEVEL 207 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 11 Index: ruby_2_3/ChangeLog =================================================================== --- ruby_2_3/ChangeLog (revision 56714) +++ ruby_2_3/ChangeLog (revision 56715) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1 +Sat Nov 12 00:27:24 2016 Nobuyoshi Nakada <nobu@r...> + + * compile.c (iseq_peephole_optimize): enable tail call + optimization inside a conditional block. + Sat Nov 5 11:53:17 2016 Nobuyoshi Nakada <nobu@r...> * io.c (copy_stream_body): use IO to write to copy to duplex IO. Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r56208,56663 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/