Artifact 347fe20e66d9ac6e882eaa3673f7949f6c26d25bb4aa213d031a2dbf1826b3d3:
- File typeparse/tests_tclsh/t82_declaration_compilee.tcl — part of check-in [4a3a97279c] at 2026-10-25 09:50:31 on branch tip-764_tcl90 — Points 4 and 5 have been completed and delivered in v16c. Regarding geometry, the annotated Tcl is now only 1.1 to 1.5 times slower than "bare" Tcl for area, perimeter, and `dedans_tous` (contains_all). 4. `X is T = v` is now compiled into a procedure. There are no longer any calls to `::tcl::unsupported::declare`, nor any lookups of the variable by its name. I also took the opportunity to eliminate two unnecessary copies: the new list of `(a, b)` now becomes the direct content of the value; an `int` or `double` shares its content rather than being copied. The command can still be used outside of a procedure or with a qualified name (such as `{::G}`), with the same behavior and messages as before. 5. Within `expr`, `$a(x)` is read directly as a number when used in a calculation (`+`, `-`, `*`, `/`, `%`, `**`) or a numerical comparison (`<`, `>`, `<=`, `>=`, `==`, `!=`). For a compact list, the value is read directly from its storage slot, without creating a view of the element or a type wrapper. In all other cases (a true array, a non-numeric field, `eq`, or a variable monitored by a read trace), the results and error messages remain unchanged. Additionally, `name = v` within a procedure now writes to the variable without requiring a name-based lookup for every assignment. Previously, every `=` operation involved such a lookup. Measurements, in nanoseconds per operation on Linux (loop overhead subtracted): operation v16b v16c A = $x 50 28 A is double = $x 313 83 A is point = $p 147 33 A is point = (1.0, 2.0) 357 196 $p(x) * 2 91 59 $c(x) * 2, element of a compact list 113 64 Geometry benchmark, annotated Tcl relative to plain Tcl (two runs, hence the ranges): calculation |v16b | v16c | compact v16b | compact v16c| ----------------| ------:| --:| ------------:| -----:| area | / 1.8 | / 1.2 to 1.5 | / 3.1| / 1.9| perimeter |/ 1.9 to 2.3 | / 1.1 to 1.4 | / 3.0| / 1.7| inside_all |/ 1.9 to 2.2 | / 1.3 to 1.4 | / 3.9| / 2.2| What remains slow: The compact form is still about 1.5 times slower than the standard form, because each `lindex` operation still creates a view of the element. `set {point}A 1.0 2.0` takes about 1.2 µs—six times longer than `A is point = (1.0, 2.0)`. I have noted this as a point for further investigation. I attempted to bypass a lookup that Tcl performs whenever an object is released, but it cannot be avoided in this case; I have reverted the change. (user: Florentis, size: 2212) [annotate] [blame] [check-ins using]
# t82 : "X is T = v" compilé dans une procédure (instruction declareLocal) : # mêmes valeurs, mêmes contrats et mêmes messages que la commande # ::tcl::unsupported::declare (hors procédure, nom qualifié, tableau) ; # la liste neuve (a, b) devient le contenu, une valeur partagée est copiée. type def point {{double}x; {double}y} type def pdef {{double}x; {double}y = 0.5} type def {-compact}nuage list.point type def forme {{double}cote, {string}nom} proc compile {nom} {expr {[string first declareLocal [tcl::unsupported::disassemble proc $nom]] >= 0}} proc p1 {} {( A is point = (1.0, 2.0); [list $A [type get $A] [catch {set A abc} m] $m] )} puts "point : [p1] compilé [compile p1]" proc p2 {} {( A is pdef = [list 1.0]; [list $A [type get $A]] )} puts "défaut : [catch p2 m] $m" proc p3 {x} {( A is double = $x; [list $A [type get $A] [catch {set A z} m] $m] )} puts "double : [p3 1.5] [p3 3]" proc p4 {} {( A is point = (1.0, {abc}) )} puts "refus : [catch p4 m] $m" puts " $::errorInfo" proc p5 {} {( L = (1.0, 2.0); A is point = $L; [list $L [type get $L] $A [type get $A]] )} puts "partagée : [p5]" proc p6 {p} {( A is point = $p; [list $A [type get $A]] )} set {point}q 3.0 4.0 puts "déjà typée : [p6 $q]" proc p7 {} {( N is nuage = ((1.0, 2.0), (3.0, 4.0)); [list $N [expr {[tcl::unsupported::compact info $N] ne ""}]] )} puts "compacte : [p7]" proc p8 {s} {( S is forme = $s; [list $S [type get $S]] )} puts "somme : [p8 {cote}2.0] [p8 {nom}carré]" proc p9 {} { upvar 0 B A expr {A is point = (5.0, 6.0)} list $B [type get $B] [catch {set B x} m] $m } puts "lien : [p9]" proc p10 {} { set A 0 trace add variable A write {apply {{n i op} {lappend ::traces $n}}} expr {A is point = (7.0, 8.0)} list $A [type get $A] $::traces } set traces {} puts "trace : [p10]" proc p11 {} {expr {{::G} is point = (1.0, 1.0)}; list $::G [type get $::G]} puts "qualifié : [p11] compilé [compile p11]" puts "global : [expr {H is point = (2.0, 2.0)}] [type get $H]" proc p12 {n} {for {set i 0} {$i < $n} {incr i} {expr {A is point = ($i, 1.0)}}; list $A [type get $A]} puts "boucle : [p12 3]" proc p13 {} {( A is inconnu = 1 )} puts "type inconnu : [catch p13 m] $m"