Skip to content
Tcl Source Code History Of Ticket af0e43c96ee61ede
Login

History Of Ticket af0e43c96ee61ede

Artifacts Associated With Ticket af0e43c96ee61ede

  1. Ticket change [71b6bfd95b] (rid 222147) by dgp on 2024-02-07 16:32:24:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. 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.
      
    5. foundin initialized to: "8.6+"
    6. is_private initialized to: "0"
    7. login: "dgp"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "8e2300e85be5dd1445b9666eb9429055951e33be"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "dgp"
    14. subsystem initialized to: "45. Parsing and Eval"
    15. title initialized to:
      some tailcall operations evade recursion limit checks
      
    16. type initialized to: "Bug"
  2. Ticket change [5c772f2441] (rid 222154) by sebres on 2024-02-07 17:23:18:

    1. 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>?
      
    2. login: "sebres"
    3. mimetype: "text/x-markdown"
  3. Ticket change [1ad422f4ab] (rid 238591) by sebres on 2025-03-20 13:47:48:

    1. closedate changed to: "2460755.07486266"
    2. closer changed to: "sebres"
    3. 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).
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Postponed"
    7. status changed to: "Closed"