Issue #12543 has been updated by mame (Yusuke Endoh).


I'm strongly against "ON by default".  It makes the backtrace difficult to understand.  Consider the following program:

```
1: def foo
2:   raise
3: end
4:
5: def bar
6:   foo
7: end
8:
9: bar
```

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
```

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.

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. 

----------------------------------------
Feature #12543: explicit tail call syntax: foo() then return
https://bugs.ruby-lang.org/issues/12543#change-81356

* 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 <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=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>