Issue #12543 has been updated by shyouhei (Shyouhei Urabe).


Dan0042 (Daniel DeLorme) wrote:
> Questions:
> 1. Is it possible to use "partial" tail-call optimization, where the backtrace is kept but all other frame state is discarded?

That's heavier than a normal method call; we don't "keep" a Thread::Backtrace::Location now.  Instances of that class are constructed on-the-fly when necessary.  However if we do a "partial" optimization like you say we have to explicitly keep them, which adds extra overhead every time when you call something -- not only when backtraces are needed.

> 2. Is it possible to detect tail-recursion and turn on optimization just for that?

That's what's requested in this request.  "Turn optimization just for this `return`" is what's called `then return` here.

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

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