| Ticket UUID: | 50f67a3acef090c734090bb894ca42445b2f3d0c | ||
| Title: | INST_START_CMD bug? | ||
| Type: | Bug | Created on: | 2014-11-27 20:02:24 |
| Submitter: | msofer | Assigned to: | dkf |
| Subsystem: | 47. Bytecode Compiler | Severity: | Minor |
| Priority: | 4 | Last modified: | 2014-12-11 13:17:47 |
| Status: | Open | Closed by: | nobody |
| Resolution: | None | Closed on: | |
| Version: | 8.6.3 | ||
| Description: | ||||
|
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. | ||||
| User Comments: | ||||
msofer added on 2014-11-27 20:03:24:
Assigning to dkf for comment - I believe he's the last one to have looked at INST_START_CMD. dkf added on 2014-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! msofer added on 2014-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? | ||||
