Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-12-11
13:17 • Ticket [50f67a3ace] INST_START_CMD bug? status still Open with 3 other chang... artifact: c0eea2ab10 user: dkf
2014-12-04
00:37 • Ticket [50f67a3ace]: 3 changes artifact: 62bb9bb583 user: msofer
2014-12-03
23:24 • Ticket [50f67a3ace]: 4 changes artifact: af364c3058 user: dkf
2014-11-27
20:03 • Ticket [50f67a3ace]: 4 changes artifact: 5a65c9729e user: msofer
20:02 • New ticket [50f67a3ace]. artifact: 8ae37f9f6e user: msofer

INST_START_CMD bug?

Open50f67a3acef090c734090bb894ca42445b2f3d0cCreated 12 years agoUpdated 12 years ago
Descriptionwiki2014-11-27 20:02:24
There seems to be a problem with commands redefining themselves in their own arguments. Consider the script
  mig@MTP:~/DEVEL/tcl-core/trunk/unix$ cat TT 
  proc history args {}
  set x [proc set args {puts FOO}]42
  puts $x

There are 3 ways in which we can run this: './tclsh TT', 'source TT', or typing it directly at the command line. The first works properly: the command [set] is replaced *before* it is used, the variable x is never set.

The third variant, typing it at the command line, misbehaves since ... forever? Doing this sets the variable x to 42, the command [set] is redefined *after* it is used.

The second variant used to work properly until [42090a4d6], where it started replacing after use.

msoferplain2014-11-27 20:03:24
Assigning to dkf for comment - I believe he's the last one to have looked at INST_START_CMD.
dkfhtml2014-12-03 23:24:45

The compiled version has been this way since 8.0, and the difference you observe is that we now compile source (as part of NRE-enabling it, which is useful for things like templating engines in coroutine-based web servers). It's very hard to avoid this sort of thing when compiling; you've got to have the ability to do things in a bit different order (especially to handle arguments like that) or you end up going crazy trying to generate code.

I continue to suggest that people relying on redefining commands that are being executed are in for a world of pain, and that this will get worse in 9.0. Indeed, I ought to propose changing the point where Tcl looks up the command implementation to immediately after the first word is read, even though dispatch to it won't happen until after all arguments are examined, since that would enormously simplify many things (while causing much hurt for people who do the most awful things). That's the sort of subtle change that would help compilation a lot by letting us ignore the worst cases entirely.

Except that it causes problems with autoloading. My brain hurts!

msoferplain2014-12-04 00:37:55
I agree 110% with your proposal to change Tcl.n to resolve earlier.

In the meantime, handling this is part of the job of INST_START_CMD. I think the problem could well be that we are not issuing enough of that instruction?
dkf Ticket [50f67a3ace]: 3 changes [History diff]2014-12-11 13:17:47
Log in (anonymous is fine) to add a comment.