Overview
| Artifact ID: | 5c772f24414af00ca60dc02d4591ffe1420782e2cef4651c0e742eb353fcec9d |
|---|---|
| Ticket: | af0e43c96ee61edeea3ec666533316fb05ec9b2f
some tailcall operations evade recursion limit checks |
| User & Date: | sebres on 2024-02-07 17:23:18 |
Changes
- 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"