#4312 bizarre interaction of uplevel and tailcall

obsolete: 8.6b1.1
closed-fixed
8
2009-03-19
2009-02-28
No

I'm struggling to come up with a smaller example of this
problem; it's quite nasty.

When the attached 'bugg.tcl' script is run, it
produces the output,

v should have been found at global level but was found in bar's method bravo

Removing the line:

proc dump args {}

from the script makes it print a play-by-play analysis of what happened.

It appears that everything is working fine right up to the very end, when the last [tailcall] invokes

::grill create betty

That constructor runs at level 2, despite having been tailcalled from level 1, and causing [upvar 1 v w] to resolve in the wrong callframe.

Discussion

  • Kevin B KENNY

    Kevin B KENNY - 2009-02-28

    Script that tickles the bug

     
    Attachments
  • Donal K. Fellows

    Confirmed with HEAD. At the offending point (just before doing 'set resolution $w' in grill's constructor) doing an 'uplevel 1 dump' produces this output:
    1: ::barney bravo
    That would seem to indicate that we're somehow managing to not stick within the constraints of the [uplevel]ed stack! I have no idea at all how that could possibly happen! Help!

     
  • Donal K. Fellows

    • priority: 7 --> 8
    • assigned_to: dkf --> msofer
     
  • Donal K. Fellows

    Here's a simplified version that exhibits the same problem, but with less gunk in the way.

    Note that it does not include the puzzling code from the original that wasn't hitting the problem...
    File Added: bug2.tcl

     
  • Donal K. Fellows

    Evidence! In my script, in procedure 'bravo', changing
    uplevel 1 [list delta ::betty]
    to
    uplevel 1 delta ::betty
    makes the problem go away.

     
  • Donal K. Fellows

    Much simplified script

     
    Attachments
  • Donal K. Fellows

    This version also exhibits the bug and doesn't use TclOO...
    File Added: bug2.tcl

     
  • Donal K. Fellows

    problem seems to be that tailcall doesn't work right from within a procedure called by a pure-list uplevel body

     
  • Donal K. Fellows

    • summary: bizarre interaction of uplevel, tailcall, method invocation --> bizarre interaction of uplevel and tailcall
     
  • Donal K. Fellows

    Having slept on it, I think the issue is related to the fact that TclNREvalObjEx-list doesn't push the same callbacks as TclNREvalObjEx-string. Respectively:

    TclNREvalObjEx-list:
    TEOEx_ListCallback
    NRCommand
    NRRunObjProc

    TclNREvalObjEx-string:
    TEOEx_ByteCodeCallback
    NRCallTEBC

    According to what I can (and can't) see in the code, the issue might be that NRCommand doesn't do tailcall processing; that's only done in TEBC (which doesn't get called at this level on the canonical-list route).

     
  • miguel sofer

    miguel sofer - 2009-03-19

    These two examples were added to tests/tailcall.test

     
  • miguel sofer

    miguel sofer - 2009-03-19
    • status: open --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks