Tcl Source Code

View Ticket
Login
2016-06-16
17:16 • Closed ticket [4b61afd660]: info frame lost with indirect command call plu... artifact: 9c068f8ab8 user: dgp
17:15
[4b61afd660] Allow [info frame] to record line info for substituted command names. check-in: 15dd07c23c user: dgp tags: trunk
17:15
[4b61afd660] Allow [info frame] to record line info for substituted command names. check-in: c94c7c4f4c user: dgp tags: core-8-6-branch
17:12
[4b61afd660] Allow [info frame] to record line info for substituted command names. check-in: 49f56e9254 user: dgp tags: core-8-5-branch
2016-06-15
06:58 • Ticket [4b61afd660] info frame lost with indirect command call status stil... artifact: 3b57be0ead user: beric
2016-06-11
18:19 • Ticket [4b61afd660]: 4 changes artifact: 93c496f32c user: aku
2016-06-10
14:47 • Ticket [4b61afd660]: 3 changes artifact: e6a4760063 user: beric
13:44 • Ticket [4b61afd660]: 4 changes artifact: 915de8fa73 user: dgp
07:42 • New ticket [4b61afd660]. artifact: 9a58e1554e user: beric

Ticket UUID: 4b61afd660d7a1d29ecf794426f46a7384b4a41
Title: [info frame] lost with indirect command call
Type: Bug Created on: 2016-06-10 07:42:10
Submitter: beric Assigned to: dgp
Subsystem: 47. Bytecode Compiler Severity: Critical
Priority: 5 Medium Last modified: 2016-06-16 17:16:23
Status: Closed Closed by: dgp
Resolution: Fixed Closed on: 2016-06-16 17:16:23
Version: 8.6.5
Description:
# The following command prints stack with [info frame]
proc stack {} {
    set level [info frame]
    set result {}
    for {set i 1} {$i < $level} {incr i} {
        lappend result [info frame $i]
    }
    return "[join $result "\n"]"
}


# Test command
proc info_frame_test {} {
    puts "*** call stack ***"
    puts [stack]
    puts "*** call stack from variable ***"
    set cmd stack
    puts [$cmd]
}

Now run info_frame_test, the result is:

*** call stack ***
type eval line 1 cmd info_frame_test level 2
type proc line 3 cmd stack proc ::info_frame_test level 1
*** call stack from variable ***
type eval line 1 cmd info_frame_test level 2
type proc line -1 cmd {$cmd} proc ::info_frame_test level 1

The line is -1 when stack is called through a variable.
User Comments:
dgp added on 2016-06-10 13:44:57:
See change on branch bug-4b61afd660 to see
where in the code this choice is made.  That
branch causes arguably a more sensible value
to be reported in the demo script submitted,
but it also causes several tests in the test
suite to fail, so there are likely tradeoffs
here I do not appreciate.

Passing on to the TIP 280 man...

beric added on 2016-06-10 14:47:49:
Thanks for pointing out where is the problem.
I tried to mitigate your patch (in 8.6.5) with the following:

	wwlines[wordIdx] =
		(wordIdx == 0 || TclWordKnownAtCompileTime(tokenPtr, NULL) ? wordLine : -1);

In fact, my case only involves the first word.

Guess what, no more info test failure, and the reported line is ok :-)

Now, if someone can explain...

aku added on 2016-06-11 18:19:21:
Ok. Let me see if I can shed some light on things.
The function in question is *EnterCmdWordData*
It is used during the byte compilation of code to record the lines each word of a single command starts at.
This is part of the code propagating line information around for others to use.

For example, when a command like

    while <expression> <script>

is compiled we have to know the line <script> starts on so that when we compile that part as well we know from there to start counting for the commands inside of <script>.

However when the command is

    while <expression> $script

then counting from the beginning of where '$script' was found does not make sense and would provide the user with completely bogus line information somewhere into the script the 'while' is a part of. So the "-1" is stuck into that slot to signal to the using place that there is no valid line to start from. And I now wish that I had used a named constant for that marker so that I could quickly find and point you to these using places in the core.

Regardless, that is why the unconditional use of the line information makes tests fail. These should be the tests that check that the type of propagation I mentioned is properly broken. ... Yes, the first fail is info-23.5, a direct example of this.

That is also why beric's alternate fix (adding the 'wordIdx == 0' clause) does work.

The word[0] of a command is always the command's _name_. It cannot be a script. (*1*)

So for this one word of the whole command we can get away with not setting the marker value even if that word is not known at compile time, i.e. $cmd, [cmd], etc.

I will not object to accepting that change, although I would recommend to record the reason for why it works outside of the code, with reference to the relevant section of Tcl.n underlying the reasoning, i.e. (*1*). So that if this thing evre changes we know what places to be wary of and in need of an update.

beric added on 2016-06-15 06:58:14:
Thanks for the explanation aku.