mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 56208,56663: [Backport #12905]
* compile.c (iseq_peephole_optimize): enable tail call optimization inside a conditional block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@56715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a6f510959e
commit
c5ee9b3868
4 changed files with 44 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Nov 12 00:27:24 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* compile.c (iseq_peephole_optimize): enable tail call
|
||||||
|
optimization inside a conditional block.
|
||||||
|
|
||||||
Sat Nov 5 11:53:17 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Nov 5 11:53:17 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (copy_stream_body): use IO to write to copy to duplex IO.
|
* io.c (copy_stream_body): use IO to write to copy to duplex IO.
|
||||||
|
|
|
@ -2240,6 +2240,13 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
|
||||||
/*case BIN(trace):*/
|
/*case BIN(trace):*/
|
||||||
next = next->next;
|
next = next->next;
|
||||||
break;
|
break;
|
||||||
|
case BIN(jump):
|
||||||
|
/* if cond
|
||||||
|
* return tailcall
|
||||||
|
* end
|
||||||
|
*/
|
||||||
|
next = get_destination_insn((INSN *)next);
|
||||||
|
break;
|
||||||
case BIN(leave):
|
case BIN(leave):
|
||||||
piobj = iobj;
|
piobj = iobj;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -230,7 +230,7 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
assert_equal true, MyObj.new == nil
|
assert_equal true, MyObj.new == nil
|
||||||
end
|
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
|
unless file
|
||||||
loc, = caller_locations(1, 1)
|
loc, = caller_locations(1, 1)
|
||||||
file = loc.path
|
file = loc.path
|
||||||
|
@ -238,7 +238,7 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}",
|
RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}",
|
||||||
file, (path || file), line,
|
file, (path || file), line,
|
||||||
tailcall_optimization: true,
|
tailcall_optimization: tailcall,
|
||||||
trace_instruction: false)
|
trace_instruction: false)
|
||||||
.eval[klass]
|
.eval[klass]
|
||||||
end
|
end
|
||||||
|
@ -334,6 +334,35 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
message(bug12565) {disasm(:add_one_and_two)})
|
message(bug12565) {disasm(:add_one_and_two)})
|
||||||
end
|
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
|
class Bug10557
|
||||||
def [](_)
|
def [](_)
|
||||||
block_given?
|
block_given?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.3.2"
|
#define RUBY_VERSION "2.3.2"
|
||||||
#define RUBY_RELEASE_DATE "2016-11-12"
|
#define RUBY_RELEASE_DATE "2016-11-12"
|
||||||
#define RUBY_PATCHLEVEL 206
|
#define RUBY_PATCHLEVEL 207
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2016
|
#define RUBY_RELEASE_YEAR 2016
|
||||||
#define RUBY_RELEASE_MONTH 11
|
#define RUBY_RELEASE_MONTH 11
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue