[ruby-core:78085] [Ruby trunk Bug#12905] tailcall_optimization not working as expected under certain condition order
From:
nagachika00@...
Date:
2016-11-11 15:35:36 UTC
List:
ruby-core #78085
Issue #12905 has been updated by Tomoyuki Chikanaga.
Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE
ruby_2_3 r56715 merged revision(s) 56208,56663.
----------------------------------------
Bug #12905: tailcall_optimization not working as expected under certain condition order
https://bugs.ruby-lang.org/issues/12905#change-61436
* Author: Kai Sun
* Status: Closed
* Priority: Normal
* Assignee:
* ruby -v: 2.3.1
* Backport: 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE
----------------------------------------
Below code gets stack too deep error:
~~~ ruby
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
def run_forever(current, final)
if current < final
run_forever(current+1, final)
else
nil
end
end
run_forever(1, Float::INFINITY)
~~~
However, below code works as expected:
~~~ ruby
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
def run_forever(current, final)
if current >= final
nil
else
run_forever(current+1, final)
end
end
run_forever(1, Float::INFINITY)
~~~
Thanks for looking at this :)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>