Issue #12543 has been updated by duerst (Martin D=FCrst).


mame (Yusuke Endoh) wrote:
> I'm strongly against "ON by default".  It makes the backtrace difficult t=
o 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 `<main>'
> 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 `<main>'
      [some frames omitted due to tail call optimization, use --tail-call-o=
ptimization-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 c=
an 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 debug=
ger 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 pr=
oposal 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() #=3D> stack level too deep
```

```
def bar()
  bar() then return
end
bar() #=3D> 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 <mame / ruby-lang.org>

---Files--------------------------------
then_return.patch (9.18 KB)


-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>