From: duerst@... Date: 2019-09-02T08:37:33+00:00 Subject: [ruby-core:94739] [Ruby master Feature#12543] explicit tail call syntax: foo() then return Issue #12543 has been updated by duerst (Martin D�rst). mame (Yusuke Endoh) wrote: > I'm strongly against "ON by default". It makes the backtrace difficult to understand. Consider the following program: > If tail-call optimization is used by default, it will print: > > ``` > Traceback (most recent call last): > 1: from test.rb:9:in `
' > test.rb:2:in `foo': unhandled exception > ``` This should be changed to something like: ``` Traceback (most recent call last): 1: from test.rb:9:in `
' [some frames omitted due to tail call optimization, use --tail-call-optimization-off for more details] test.rb:2:in `foo': unhandled exception ``` Of course, the exact name of the exception and the wording of the message can still be improved. Implementation should be easy, just set a flag on the stack frame above the one that is eliminated by the tail call optimization. > The frame of `bar` is removed due to tail-call optimization, so the debugger must guess how it reached at Line 2 from Line 9. Guessing is of course not prohibited, but better use the option to get the full trace. > This issue would be incredibly difficult when multiple frames are omitted. It would be not so rare on practical programs. I believe that "easy to debug" is one of the most important properties in Ruby. I agree that "easy to debug" is important for Ruby. But I don't think my proposal makes debugging very difficult. ---------------------------------------- Feature #12543: explicit tail call syntax: foo() then return https://bugs.ruby-lang.org/issues/12543#change-81357 * Author: mame (Yusuke Endoh) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- How about introducing a new syntax for tail call? ``` def foo() foo() end foo() #=> stack level too deep ``` ``` def bar() bar() then return end bar() #=> infinite loop ``` * no new keyword (cf. `goto foo()`) * no conflict with any existing syntax * an experimental patch is available (attached) * no shift/reduce nor reduce/reduce conflict in parse.y -- Yusuke Endoh ---Files-------------------------------- then_return.patch (9.18 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: