Overview
| Artifact ID: | e44267c64ac531cc0cc5b0a49f441dd086e8f62a |
|---|---|
| Ticket: | 3057639fffffffffffffffffffffffffffffffff
lappend inconsistency with respect to read traces |
| User & Date: | andreas_kupries on 2010-09-02 00:51:09 |
Changes
- icomment:
Continued notes ... =============== [HL] Note that YYYY is ZZZZ and we can probably fix/make changes to it to get it to work if necessary. But we are more concerned about user scripts compatibility and how will they be affected -- we have no way of modifying user scripts if they run into this situation. So we would like to get to the bottom of the issue -- primarily what is the intended behavior when read traces are set on non-existent variables and how lappend operates on it. =============== [JH] In the 2 switch cases below, you are seeing the subtle variation between a switch that can be bytecompiled (with --) and without (because $oper may be another option to switch, it checks at runtime instead of bytecompiling). As to other variables, this does have the same behavior, if you follow the same trace proc that ::env has set by default: proc test {oper var elem value} { upvar #0 $var lvar switch -- $oper { add { lappend lvar($elem) $value } } } proc nonull {var key val} { upvar 1 $var lvar if {![info exists lvar($key)]} { return -code error "no such variable" } } trace add variable myvar read nonull test add myvar key "new value" The 'nonull' style of trace is what ::env has had set for a long time. The difference is that byte-coded lappend changed to do read traces. This was done in 8.4, but done incompletely such that only _bytecompiled_ lappend was affected. Thus, you would have encountered this in 8.4 already had you written the autoeasy code slightly differently. The answer may be to remove these read traces on variables, but do we do that for 8.4 and 8.5, or just 8.5+? Or just for arrays, and leave for scalars? That would be very odd. I think that might be the best way to go, because otherwise lappend is simply a trap that cannot be used for currently empty ::env vars. The question that needs to be first answered is what other impact this might have for those that expected to have the read traces executed. What do you think of that? =============== [HL] Is nonull trace only set for env variable or for other variables too? If this behavior is changed, someone else out there might be relying on this feature -- will very difficult to find out. The other question is: should lappend be considered to have a read trace. How do append, lset or any other command which modifies existing variable behave. Do they invoke read traces whenever the variable value is updated or do they also depend on whether it is byte-compiled or not. I think that the read-traces should be consistent in whether they are invoked or not for all scenarios and not be dependent on byte-compiled or not. Otherwise we would be waiting for another bug/fix cycle needed in the future. Having said all this, [...], I would like it to not throw any errors on upgrade so that no modifications are required on our end to upgrade. =============== [JH] The nonull behavior is particular to the ::env array in Tcl in that it is the default behavior on that array defined by Tcl. No other arrays have traces on them by default, but users could set up such themselves. Only lappend has this read trace behavior turned on at the bytecode level, append does not. I'm beginning to think this is just not good that lappend does this read trace in this way. While technically correct, the other setter functions don't mirror this behavior, and lappend is only doing it when byte-compiled, not otherwise. I'll prepare a bug report for this, as it will be good to have it documented. I will probably have this behavior changed in both 8.4 and 8.5 branches as well as head, so it will again be consistent if you are using the latest. Again, be warned though that lappend can cause this error in the current 8.4 if you have a fully byte-compiled code segment. - login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"