Artifacts Associated With Ticket af0e43c96e
Ticket change [71b6bfd95b] (rid 222147) by dgp on 2024-02-07 16:32:24:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- comment initialized to:
Declared a "separate issue" in [8e666d7c95], there seem to be some circumstances where [tailcall] operations never encounter testing of the interp recursionlimit and lock up Tcl in an infinite recursion. Should not lose sight of this.
- foundin initialized to: "8.6+"
- is_private initialized to: "0"
- login: "dgp"
- priority initialized to: "5 Medium"
- private_contact initialized to: "8e2300e85be5dd1445b9666eb9429055951e33be"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "dgp"
- subsystem initialized to: "45. Parsing and Eval"
- title initialized to:
some tailcall operations evade recursion limit checks
- type initialized to: "Bug"
Ticket change [5c772f2441] (rid 222154) by sebres on 2024-02-07 17:23:18:
- icomment:
Not "some circumstances" - basically it never tests <code>interp recursionlimit</code>: % interp recursionlimit {} 1000 % proc test {{cnt 0}} { if {$cnt >= 1e5} {return STOPPED}; tailcall test [incr cnt] }; test STOPPED ... and it is good so in my opinion: - <code>tailcall</code> is not a recursion directly, because it builds a function invocation stacklessly (replaces the current frame with invoked frame) - moreover it is rather a replacement for (cyclic) uplevel call, and as [its docu](https://www.tcl-lang.org/man/tcl/TclCmd/tailcall.html) says:<br/> *The tailcall command **replaces** the currently executing procedure, lambda application, or method with another command*<br/> but also as [its TIP](/../tips/doc/trunk/tip/327.md) says:<br/> *The effect of this command is very similar to:<br/> <code>return [uplevel 1 [list [namespace which cmd ] ?arg ...?]]</code><br/> with the sole exception that the invocation of cmd happens **after the currently executing body returns** and is not visible in Tcl's call stack.* - it's one of the advantages of <code>tailcall</code>; - the important reason for <code>interp recursionlimit</code> is not a prevention against infinite execution (for which one'd rather use <code>interp limit</code>), but avoidance of stack overflow or OOM situation (mostly before NRE got introduced); - many cyclic flows inclusive recursion unfolded to cycle with self-made stack for args as list (no matter NRE or not) would also not implicitly check <code>interp recursionlimit</code>; With other words, if it is not a recursion, why shall it check the <code>interp recursionlimit</code>? - login: "sebres"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [1ad422f4ab] (rid 238591) by sebres on 2025-03-20 13:47:48:
- closedate changed to: "2460755.07486266"
- closer changed to: "sebres"
- icomment:
Closed for no activity...<br/> Please reopen, Don, if you have some objections.<br/> However one could consider this rather as an RFE, and implement it either as: <code>interp tailcalllimit</code> or <code>interp limit {} tailcall ?value?</code> Just it will be hardly possible, IMHO, because in opposition to recursion, it doesn't necessarily have a nesting and/or start and end, or rather it is almost impossible to detect such.<br/> Furthermore how one shall consider single tailcall used instead of return to uplevel-ed command, quasi to yield it to upper frame? Shall that be counted also (together with other tailcalls)?<br>And if we'd have some cyclic proceedings above? Note that it is not always possible to detect recursion and a simple rule "tailcall to itself" doesn't always working, because it needs to consider nesting "loops" (e. g. cross tailcall to some parent proc). - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Postponed"
- status changed to: "Closed"