|
2024-08-20
| ||
| 14:48 | • Ticket [a34733451b] Regression with TIP #636 in foreach status still Closed ... artifact: ec0a07cca3 user: pooryorick | |
|
2024-08-15
| ||
| 17:05 | Merge [5bc8af69e37a1a99], fix foreach bug [a34733451b]. Other code cleanup discovered by code review... check-in: 4ef5c51312 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE | |
|
2023-07-13
| ||
| 07:48 | • Ticket [a34733451b] Regression with TIP #636 in foreach status still Closed ... artifact: a2adb801ba user: fvogel | |
| 06:52 | • Ticket [a34733451b]: 5 changes artifact: 051cd53330 user: jan.nijtmans | |
| 06:18 | • Ticket [a34733451b]: 5 changes artifact: a8c0b2f193 user: fvogel | |
|
2023-07-12
| ||
| 20:40 | • Closed ticket [a34733451b]. artifact: 6637783ec9 user: griffin | |
| 14:51 | • Ticket [a34733451b]: 4 changes artifact: 3c8216c928 user: jan.nijtmans | |
| 14:07 | • Ticket [6022b9f946] Tk when built against Tcl 9.0 broken status still Closed... artifact: d9431d13c2 user: pooryorick | |
| 14:06 | • Ticket [a34733451b] Regression with TIP #636 in foreach status still Open wi... artifact: 305896c27d user: pooryorick | |
| 14:04 | • Ticket [a34733451b]: 3 changes artifact: b8f5dcadc8 user: pooryorick | |
| 13:57 | • Ticket [a34733451b]: 3 changes artifact: a58fbbcc64 user: jan.nijtmans | |
| 13:54 | • Ticket [a34733451b]: 3 changes artifact: 42b569e576 user: jan.nijtmans | |
| 13:53 | • Ticket [a34733451b]: 3 changes artifact: 0d2cbac76b user: griffin | |
| 13:49 | • Ticket [a34733451b]: 3 changes artifact: 1b51017c06 user: jan.nijtmans | |
| 13:37 | • Ticket [a34733451b]: 3 changes artifact: 03bfea39d6 user: pooryorick | |
| 13:02 | • Ticket [a34733451b]: 3 changes artifact: 9df653f6cb user: apnadkarni | |
| 07:55 | • Ticket [a34733451b]: 3 changes artifact: f5d3a842e6 user: jan.nijtmans | |
| 07:35 | • Ticket [a34733451b]: 3 changes artifact: e1663c922f user: apnadkarni | |
| 06:06 | • Ticket [a34733451b]: 3 changes artifact: 3324e48dbe user: apnadkarni | |
| 05:46 | • Ticket [a34733451b]: 3 changes artifact: 9fcc1f8173 user: apnadkarni | |
| 03:34 | • Ticket [a34733451b]: 3 changes artifact: a6e80750d8 user: griffin | |
| 03:06 | Fix foreach bug [a34733451b]. Other code cleanup discovered by code review. check-in: 5bc8af69e3 user: griffin tags: trunk, main | |
|
2023-07-11
| ||
| 15:44 | • Ticket [a34733451b] Regression with TIP #636 in foreach status still Open wi... artifact: a5b2b8bd0f user: griffin | |
| 15:23 | • Ticket [a34733451b]: 3 changes artifact: fb5ebc96f3 user: apnadkarni | |
| 13:47 | • Ticket [a34733451b]: 3 changes artifact: 451d7d2ffe user: griffin | |
| 13:05 | • Ticket [a34733451b]: 3 changes artifact: 2f605e9c76 user: jan.nijtmans | |
| 12:26 | • Ticket [a34733451b]: 3 changes artifact: 06430f9a0c user: chrstphrchvz | |
|
2023-07-09
| ||
| 19:37 | • Ticket [a34733451b]: 3 changes artifact: 3cf406d58c user: griffin | |
| 16:25 | • Ticket [a34733451b]: 3 changes artifact: b02bcab768 user: fvogel | |
| 15:40 | • Ticket [a34733451b]: 3 changes artifact: 7a0db14b46 user: fvogel | |
| 15:39 | • New ticket [a34733451b]. artifact: 23a7c0edf5 user: fvogel | |
Regression with TIP #636 in foreach
==== imgPhoto-4.79 ImgPhotoCmd, transparency get: no option FAILED
==== Contents of test case:
set pixelCoords {{156 239} {76 207} {153 213} {139 43} {75 112}}
foreach coord $pixelCoords {
lappend result [photo1 transparency get {*}$coord]
}
set result
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: can't read "coord": no such variable
while executing
"photo1 transparency get {*}$coord"
("foreach" body line 2)
invoked from within
"foreach coord $pixelCoords {
lappend result [photo1 transparency get {*}$coord]
}"
("uplevel" body line 3)
invoked from within
"uplevel 1 $script"
---- errorCode: TCL LOOKUP VARNAME coord
==== imgPhoto-4.79 FAILED
==== imgPhoto-4.81 ImgPhotoCmd, transparency get: -alpha FAILED
==== Contents of test case:
set pixelCoords {{156 239} {76 207} {153 213} {139 43} {75 112}}
foreach coord $pixelCoords {
lappend result [photo1 transparency get {*}$coord -alpha]
}
set result
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: can't read "coord": no such variable
while executing
"photo1 transparency get {*}$coord -alpha"
("foreach" body line 2)
invoked from within
"foreach coord $pixelCoords {
lappend result [photo1 transparency get {*}$coord -alpha]
}"
("uplevel" body line 3)
invoked from within
"uplevel 1 $script"
---- errorCode: TCL LOOKUP VARNAME coord
==== imgPhoto-4.81 FAILED
==== panedwindow-17.1 MoveSash, move right FAILED
==== Contents of test case:
panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
foreach w {.f1 .f2} c {red blue} {
.p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
}
# Get the requested width of the paned window
lappend result [winfo reqwidth .p]
.p sash place 0 30 0
# Get the reqwidth again, to make sure it hasn't changed
lappend result [winfo reqwidth .p]
# Check that the sash moved
lappend result [.p sash coord 0]
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: unknown color name "3"
(processing "-bg" option)
invoked from within
"frame $w -height 20 -width 20 -bg $c"
("foreach" body line 2)
invoked from within
"foreach w {.f1 .f2} c {red blue} {
.p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
}"
("uplevel" body line 3)
invoked from within
"uplevel 1 $script"
---- errorCode: TK LOOKUP COLOR 3
==== panedwindow-17.1 FAILED
plus an additional error message:
[...] unixWm.test Test file error: can't read "geom": no such variable util.test [...]
Bisection shows that the first commit triggering this regression is [91c2f411e7], that is the merge of TIP #636 implementation into trunk.
In all the four cases, the problem is in a foreach loop apparently not assigning a value to the loop variable.
Warning: the problem cannot be reproduced when running only the imgPhoto.test or panedwindow.test file from Tk. Running the entire test suite of Tk allows however to reproduce (on all three platforms).
4ef5c51312Merge [5bc8af69e37a1a99], fix foreach bug [a34733451b]. Other code cleanup discovered by code review. check-in2024-08-15 17:05:055bc8af69e3Fix foreach bug [a34733451b]. Other code cleanup discovered by code review. check-in2023-07-12 03:06:54
Hard to debug. Requires some prior test(s) to effect state. imgPhoto test seems to run in a subprocess, direct gdb doesn't work. It also seems that child interps are involved.
One area of change that is a concern is in the bytecode engine. There are spots where care must be taken when making calls out of the bce when the call has the potential of then calling eval. This creates a recursive call to the bce. The caution is to make sure stack ptr save/restore calls are made, otherwise the stack can be corrupted. Abstract Lists increased the chances of this in places that were not protecting the stack pointer.
My suspicion currently is that the Tk tests are somehow uncovering these holes.
The debugging continues...
This is a duplicate of [6022b9f946]. The bug got merged from main into tip-636-tcl9-644 by [3e44e4bdd3]. The bug was then fixed on main, but the fix somehow did not get merged into tip-636-tcl9-644 during [2f493bd21cb9]. The bug presumably then remained on tip-636-tcl9-644 and was merged back into main by [91c2f411e7].
@nathan, can you help here? Since you introduced the bug, you should be able to fix it (again).
I am aware that the fix is [this commit], but this commit has so many changes that I cannot extract the relevant change from it. It's pure magic to me (which is not meant as a compliment).
The problem is with TclDuplicatePureObj(). This function forces a type upon a value which sometimes causes a shimmer. This is bad for abstract lists when called prematurely, i.e. before the value is actually consumed. I had modified the function to prefer src Obj type over the requested type, except when the src was just a string. Any shimmer would already occur later at the point of consumption.
The point of failure in this ticket is specifically relying on Dup for type conversion. (A hidden aspect of Dup) The specific value in this case is a variable name previously used, and still exits, as an "index" type. This interfered with the variable lookup because the string was stripped from the obj. It also explains why the test passes when run alone, the variable was not used prior to the test, so did not exist.
I don't think preference to the src Obj type over requested type would work in all cases as my reading of some of the calls indicates caller assumes the internal rep is the requested type and directly accesses it accordingly (in particular does not check for errors when further calls fail).
Converting the type doesn't work in all cases either. That's why it is a bad idea to have 1 function do 2 orthogonal things, make a pure copy, convert the type.
What happened?
- Canvas widget defines an option table the includes the string "coords"
- Testcase has: "foreach coord $pixelCoords {..."
- Internal to the foreach command, a copy of the variable argument is made using TclDuplicatePureObj().
- The "coord" argument ends up as a shared Obj with a type of "index" ObjType.
- (this is due to use of an abbreviated "coord" keyword to a canvas command somewhere in an earlier test. Probably hundreds of them.)
- The internal rep matches the "coords" value in the canvas option table.
- The Dup-Pure removes the string rep, leaving the "index" ObjType internal rep.
- The var lookup code requests the string, which is generated from the option table, and returns "coords"
- The lookup fails because the variable name is "coord".
Take away:
- I think TclDuplicatePureObj() is dangerous. Uses should be inspected carefully.
- I think the option table implementation is violating consistency promise between internal rep and string rep.
This issue has been fixed by replacing TclDuplicatePureObj with Tcl_DuplicateObj(). In this case, the values are var names. It's all about the string here.
Adding my two cents, more to clarify my own thinking:
Tcl values are defined by their string representation as stored in the
Tcl_Obj.bytesfieldTcl_DuplicateObjpreserves the value sematics by preserving thebytes, whileTclDuplicatePureObjdoes not. Consider two objects, both of typeintType(or whatever theintinternal rep is) with value 16 butobj1.bytesbeing "16" andobj2.bytesbeing "0x10". These are not equal values butobj1andTclDuplicatePureObj(obj2)will be equal.Tcl_DuplicateObjwas used in at least two ways. One was to make an unshared copy for further modification. The other was to ensure the internal rep remained valid (e.g. iterating a list) even though no modification was planned.TclDuplicatePureObjcan replaceTcl_DuplicateObjin the first instance since anyways thebyteswill be invalidated. I don't think it can replace in the second instance. All uses need to be examined for which of the two cases applies.I am a bit uncomfortable with the implementation which copies the
bytespointer from the source to the dup object and callsTcl_ConvertToType. I don't know if there are any guarantees thatTcl_ConvertToTypewill not somehow manipulate the allocation if the Tcl_Obj is unshared. May not be a problem now but in the future for all possible types?Although I initially thought the option table code might also violate consistency, I am not so sure any more based on my
intexample above. It is legitimate to have two string values map to the same internal rep. However, when generated from a string, the string representation must be preserved. This does not happen due toTclDuplicatePureObj, not because of the option table code.
On further thought, I'll modify my third point as * `Tcl_DuplicateObj` was used in at least two ways. One was to make an unshared copy for further modification. The other was to ensure the internal rep remained valid (e.g. iterating a list) even though no modification was planned. `TclDuplicatePureObj` can replace `Tcl_DuplicateObj` in the first instance since anyways the `bytes` will be invalidated. On the other hand, it can only be applied in the second case in limited cases where the dup'ed object is not preserved. For example, immediately discarded after iteration on a list. In any case, all uses need to be examined for which of the two cases applies.
One more note - the semantics of TclDuplicatePureObj differ between 8.7 and 9.0. Not sure if this is intentional but it adds to the confusion about usage. 8.7 coerces to the passed in typePtr but 9.0 prefers the typePtr of the source Tcl_Obj.
Whatever recent changes were done to TclDuplicatePureObj() should be backported to 8.7 as well (we don't want the recently discovered bugs discovered in 9.0 to re-appear in 8.7). I never liked the introduction of TclDuplicatePureObj(), but I didn't have much arguments to complain.
My analysis might be misplaced so would be useful to have @pooryorick comment but ...
Jan, I noticed you added int, double, index as additional "protected" types to TclDuplicatePureObj. Since lists (abstract and traditional) can also have the same issue - multiple string representations for the same internal rep - should those also be protected. In which case one wonders what's left and whether the whole exercise is worthwhile.
Originally, the list code used TclListObjCopy as a specialized internal function. It was important from a performance perspective within its limited context. TclDuplicatePureObj generalizes it to do more but given it does not preserve value semantics its applicability is limited to those same use cases. That hints to me that the protections be removed, and the semantics of the function changed to reflect values are not preserved, only intreps are, and all call sites changed to revert to Tcl_DuplicateObj when they fall outside those limited use cases.
Alternately, each type could revert back to its own specialized "internal copy" as the list implementation used to. This also avoid all the checks present in the "generalized" TclDuplicatePureObj.
The TIP #636 code should be reverted from trunk until it can be successfully merged without causing this regression. I've warned that TIP 636 is not ready for prime time, and this issue report is evidence of that. TclDuplicatePureObj() should not be compromised in order to accommodate TIP 636. Rather, the TIP 636 should be modified to not interact with TclDuplicatePureObj() at all. If the TIP 636 work does interact with TclDuplicatePureObj() it is a bug in the implementation of TIP 636. TclDuplicatePuerObj() should not be modified to be sensitive to internal representations that seem to implement a Tcl_Obj interface. Such a modification would be a hack in lieu of a correct implementation of TIP 636.
> In which case one wonders what's left and whether the whole exercise is worthwhile
I'm having the same doubt! The only type I see which doesn't have this problem is the ArithSeries objType. I would like to throw away the TclDuplicatePureObj() function, but first we need to discuss what to do instead ....
pooryorick: #636 is not the problem. TclDuplicatePureObj has been used incorrectly or indiscriminately, that is the problem.
@Nathan. Your TclDuplicatePureObj() changes, which broke he build in your first commit are the cause of the trouble with TIP #636. So I suggest to revert the changes you introduced, until they work well with TIP #636 :-)
Ashok wrote: > My analysis might be misplaced so would be useful to have @pooryorick comment but ... I think your analysis is well-done. It's very clear to me.
The TIP #636 code should be reverted from trunk until it can be successfully merged without causing this regression. I've warned that TIP 636 is not ready for prime time, and this issue report is evidence of that. TclDuplicatePureObj() should not be compromised in order to accommodate TIP 636. Rather, the TIP 636 should be modified to not interact with TclDuplicatePureObj() at all. If the TIP 636 work does interact with TclDuplicatePureObj() it is a bug in the implementation of TIP 636. TclDuplicatePureObj() should not be modified to be sensitive to internal representations that seem to implement a Tcl_Obj interface. Such a modification would be a hack in lieu of a correct implementation of TIP 636.
Oops, please disregard the previous repeated message. Here is the new message:
The last trouble reported with TclDuplicatePureObj() was fixed almost two months ago, in [c405bdd1f0]. Since then there have been no test failures until the merge of TIP 636. That clearly indicates that the trouble is with the TIP 636 merge, and that's what should be reverted here.
> The TIP #636 code should be reverted from trunk until it can be successfully merged without causing this regression Build is passing now, so no worries. I'm not closing this ticket yet, until we decided what to with TclDuplicatePureObj()
> How come...??
In GitHub, the Tk builds are done _before_ the Tcl builds. That means that when Tk builds, Tcl doesn't have the latest commits from fossil yet. So, I re-ran the Tk build after Tcl synced. :-)
This explanation indeed makes a lot of sense! Do we control when the jobs are launched in each particular project?
Doing some post-mortem analysis on this, Brian said below, "The Dup-Pure
removes the string rep, leaving the "index" ObjType internal rep.".
TclDuplicatePureObj() would not remove the string representation
of an individual item in the list when converting the type to tclListType, It
is only the full list representation which is discarded, and
SetListFromAny() sees to it that each individual list item has a
string representation when converting a value of another type to a string.
Therefore it is safe to use TclDuplicatePureObj() to duplicate
into a list type. There's something to this story that was not discovered.