Artifact bbc95baa40514e08bf8f5e460117619594030c37b6078e1e89445a966162bd71:
- File typeparse/tests_tclsh/t76_lecture_champ.tcl — part of check-in [4269a60689] at 2026-10-24 13:29:48 on branch tip-764_tcl90 — Point 2 is complete and documented. All that remains is to wait for Valgrind and the full Tcl test suite—which are currently running in the background (taking about 40 minutes)—before sending the zip file. Previous behavior: Each read operation `$a(x)` would look up the field by its name and follow general path-resolution rules. Subsequently, `expr` would receive a typed value, causing it to exit its optimized "fast path" for numeric operations. Changes: Field caching: The index of a compiled read (the `x` in `$a(x)`) now stores the previously encountered type and the field's location. Subsequent reads involving the same type proceed directly to the element. Sums, variable links (`var`), and `list.any` continue to use the general path-resolution mechanism. Typed numbers in `expr`: An operand typed as `int` or `double` is now read directly from its underlying content. This is implemented via a new core patch, `expr-nombres-types.patch` (in `tclExecute.c`). The result is never written back into the operand; thus, a variable such as `{double}d` remains unchanged—a fact verified by the test suite. Measurements (10,000 points): Bare Tcl v15s current reading $a(x) within expr 0.05 µs (lindex) ≈ 0.52 µs 0.14 µs foreach a $P {set s [expr {$s + $a(x)}]} 0.64 ms 5.2 ms 1.5 ms Geometry, performance gap relative to the baseline (bare Tcl): calculation v15s v15u v15v area / 3.4 / 2.2 / 1.8 perimeter / 2.7 / 1.9 / 2.1 bounding box / 6.7 / 3.7 / 3.0 inside_all / 3.6 / 2.6 / 2.1 Bézier / 2.7 / 2.4 / 2.4 The perimeter figure shows a slight regression, from / 1.9 to / 2.1. This is likely measurement noise; this calculation primarily involves procedure calls. What remains during the read operation is the creation and subsequent release of the field's typed value. Eliminating this would require the `expr` command to know—at compile time—that it only requires a numeric value, which is a separate, more complex undertaking. Verified so far: All 54 tests pass, including the new `t76_lecture_champ` (field read) test, which produces the same output as it did before the change. Results are identical whether the compact form is used or not. (user: Florentis, size: 1960) [annotate] [blame] [check-ins using]
# t76 : lecture $a(champ) compilée (cache du champ dans l'objet index) et # nombres typés lus directement par expr. Même résultat qu'avant : type # du champ, champ de même nom à une autre place dans un autre produit, # somme, lien, list.any, opérandes typés jamais modifiés. type def point {{double}x; {double}y} type def rgb {{int(u,8)}r; {int(u,8)}g; {int(u,8)}b} type def pivot {{double}y; {double}x} proc lx {a} {list $a(x) [type get $a(x)]} proc sx {a} {expr {$a(x) * 2}} set {point}p 1.5 2.5 set {pivot}q 7.0 8.0 puts "point : [lx $p] [sx $p]" puts "pivot : [lx $q] [sx $q] (x à une autre place, même littéral)" puts "point : [lx $p]" type def etiquette {{string}nom; {double}x} set {etiquette}p2 a 3.25 puts "autre type : [lx $p2] [sx $p2]" proc lr {c} {list [expr {$c(r) + $c(g) + $c(b)}] [type get $c(g)] [expr {$c(r) / 2}] [expr {$c(r) & 0xF}]} set {rgb}c 200 100 50 puts "rgb : [lr $c]" type def forme {{double}cote, {double}rayon} type def objet {{string}nom; {forme}f} proc lf {o} {list $o(f) [type get $o(f)] $o(nom) [type get $o(nom)]} set {objet}o boule {rayon}2.0 puts "somme : [lf $o]" type def boite {{list.any}contenu; {double}x} set {list.any}C {int}1 {string}a set {boite}bx $C 4.0 proc lb {b} {list [type get $b(contenu)] [type get [lindex $b(contenu) 0]] [expr {$b(x) + 1}]} puts "list.any : [lb $bx]" set cible 5.0 type def ref {{var.double}v; {double}x} proc lv {r} {list $r(v) $r(x)} set {ref}rv cible 9.5 puts "lien : [lv $rv]" proc garde {} { set {double}d 1.5; set {point}p 2.0 3.0 set e [expr {$d + 1}]; set f [expr {$p(x) - 0.5}]; set g [expr {$d * $p(x)}] list $d [type get $d] $e [type get $e] $f $p $g [expr {$p(x) ** 2}] } puts "intacts : [garde]" proc boucle {L} {set s 0.0; foreach a $L {set s [expr {$s + $a(x) * $a(y)}]}; set s} set {list.point}L {1 2} {3 4} {5 6} puts "boucle : [boucle $L] [boucle $L]" proc mauvais {a} {catch {set a(z)} m; set m} puts "champ inconnu : [mauvais $p]"