tailcall/try inconsistency compiled/direct
Closed / Fixed3046594fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-08-16 20:16:06
% proc foo {} {try {tailcall concat} finally {}}
% foo
tailcall called from within a catch environment
% proc bar {} {set try try; $try {tailcall concat} finally {}}
% bar
dgpplain2010-08-17 23:58:11
Worse related example:
% proc foo {} {set catch catch; $catch {tailcall concat}}
% foo
Program received signal SIGSEGV, Segmentation fault.
0x00000001 in ?? ()
(gdb) bt
#0 0x00000001 in ?? ()
#1 0x080e2414 in TclNRRunCallbacks (interp=0x81c2eb0, result=0,
rootPtr=0x821cfb0, tebcCall=1)
at /home/dgp/cvs/tcl-only/generic/tclBasic.c:4324
#2 0x0816ee9b in TclExecuteByteCode (interp=0x81c2eb0, codePtr=0x824c220)
at /home/dgp/cvs/tcl-only/generic/tclExecute.c:6596
#3 0x080e26f9 in NRCallTEBC (data=0x823dd8c, interp=0x81c2eb0, result=0)
at /home/dgp/cvs/tcl-only/generic/tclBasic.c:4400
#4 0x080e2414 in TclNRRunCallbacks (interp=0x81c2eb0, result=0, rootPtr=0x0,
tebcCall=0) at /home/dgp/cvs/tcl-only/generic/tclBasic.c:4324
#5 0x080e4b64 in TclEvalObjEx (interp=0x81c2eb0, objPtr=0x8246844,
flags=131072, invoker=0x0, word=0)
at /home/dgp/cvs/tcl-only/generic/tclBasic.c:5941
#6 0x080e4aeb in Tcl_EvalObjEx (interp=0x81c2eb0, objPtr=0x8246844,
flags=131072) at /home/dgp/cvs/tcl-only/generic/tclBasic.c:5922
#7 0x0817cfc3 in Tcl_RecordAndEvalObj (interp=0x81c2eb0, cmdPtr=0x820ef80,
flags=131072) at /home/dgp/cvs/tcl-only/generic/tclHistory.c:192
#8 0x080730e1 in Tcl_Main (argc=-1, argv=0xbfffe0f8,
appInitProc=0x80545bb <Tcl_AppInit>)
at /home/dgp/cvs/tcl-only/generic/tclMain.c:471
#9 0x080545ac in main (argc=Cannot access memory at address 0x1a
) at /home/dgp/cvs/tcl-only/unix/tclAppInit.c:85
msoferplain2010-08-18 02:35:16
These two are related but not identical. 1. non-bc'ed catching of tailcalls is there, but it is broken (hence the segfault) 2. bc'ed try uses the catch mechanism, hence does not permit tailcalling out of the try body 3. non-bc'ed try is not aware of tailcalls
msoferplain2010-08-18 03:14:09
Discussion of the second example moved over to #3047235
msoferplain2010-08-18 22:55:42
Inconsistency fixed in HEAD. Leaving open with a question: should the error message change to "tailcall called from within a catch or try environment"?
msofer Ticket [3046594fff]: 1 change
[History diff]2010-08-18 22:56:11
ferrieuxplain2010-08-18 23:33:48
I think so :)
dgpplain2010-08-19 00:04:58
I'm not fully convinced that a refusal error is the right design. With that reservation stated, if you do convince me, I would hope we could come up with an error message that would not need maintenance every time a new command with [catch]-like function was addded.
dgpplain2010-08-19 00:08:48
Keep in mind this quirk as well:
% proc foo {} {try {tailcall concat}}
% foo
%
With no 'finally' and no handlers, the
[try] command doesn't actually create
a "catch environment" to disallow [tailcall].
dgpplain2010-08-19 00:10:16
Conversely, "catch environment" does show
up places you might not expect it:
% proc bar {} {subst {[tailcall concat]}}
% bar
tailcall called from within a catch environment
msoferplain2010-08-19 00:31:41
how we got here is ... (a) can't tailcall out of a catch range, in order to avoid sidestepping hand-made try-finally constructs (b) as try (and subst) use the CATCH instruction, and TEBC has no way to know which command it is running, they block tailcalls (when bc'ed) as a side-effect of that decision
msoferplain2010-08-30 21:09:28
allow_comments - 1 New implementation from #3048771 fixes this issue
Log in (anonymous is fine) to add a comment.