Artifact 7812bf6641cf55faf17088b7719a1a35187d07ba5640b5754f94347dfb31f758:
- File typeparse/tests_tclsh/t73_procedures_typees.tcl — part of check-in [9ac2319e26] at 2026-10-24 09:52:53 on branch tip-764_tcl90 — Version v15s is included in typeparse.zip: the annotated scope execution time drops from 163 ms to 46–52 ms (compared to 17–19 ms for "bare" Tcl). Profiling revealed that an expression like `X is T = $x` took 3.3 µs. About a third of this time was spent re-parsing the type definition text with every call, while the remainder was consumed by pushing and popping an annotation (a "note"). Changes implemented: Cached classification: The classification of an annotation is now stored within the text object. It is reused as long as the type table remains unchanged; a `type def` operation invalidates this cache. Direct declaration: An expression like `X is T = v` treats the value—which is already of type `T`—as-is. Values without annotations are constructed directly, without an associated "note." Compiled local variables: Within a procedure, names assigned via expressions (e.g., `x = …`, `x is T = …`) are now handled as compiled local variables. Compiled `$a(x)` access: The result is passed directly via the stack, bypassing the interpreter's general result mechanism. These last two improvements are part of the new kernel patch `procedures-typees.patch`, listed last in `ORDRE.txt`. Measurements: Measurement Before After Bare Tcl `X is point = $a` 3.3 µs 0.6 µs — `geo::distance` 14.6 µs 4.7 µs 1.9 µs Bézier 99 ms 53 ms — Area 15 ms 11–13 ms — Bug fixed during development: This issue had existed since version v15g. An element of a `list.T` accessed via a path (e.g., `lindex $t(children) 0`) would lose its type information whenever the list content was shared. It is now correctly typed in all cases. The file `arbre_graphe.tcl` relied on this behavior and broke during the development process, prior to this fix. Verifications: The new t73 test produces the same output as v15. Valgrind reports no issues in either compact mode, aside from the usual leaks upon exiting `executable_pe`. The full Tcl test suite shows the same 61 failures as v15. Version v15s is documented in `LISEZMOI.md` and in section 15 of `ANNOTATIONS.fr.md`. I have updated the "Performance" item in the roadmap and removed `tclTypePath.c.avant_index` from the package—a backup file that had been included by mistake since October 19th. `dedans_tous` remains unchanged (≈ 255 ms, compared to 65 ms in raw Tcl). Most of this time is spent on `$a(y)` lookups within `expr` (≈ 0.2 µs each, versus 0.06 µs for an index-based lookup). This is the next target on the roadmap. (user: Florentis, size: 1746) [annotate] [blame] [check-ins using]
# t73 : procédures typées plus rapides, même sens. Éléments d'une liste typée # lue par chemin (V partagé) : toujours typés, par lindex comme par foreach # (avant : selon le partage de l'objet). Déclarations X is T = v : valeur # déjà de type T, valeur nue, valeur à convertir. Noms affectés dans expr : # variables locales compilées, global et upvar compris. proc t {l s} { set rc [catch {uplevel 1 $s} m]; puts [format "%-34s %s %s" $l $rc $m] } type def {tree({type}T)} { {$T}value; {list.tree($T)}children } set {tree(string)}A /usr {{bin {}} {lib {{tcl9.0 {}}}}} t "lindex \$A(children) 0" {type get [lindex $A(children) 0]} t "copie puis lindex" {set x $A(children); type get [lindex $x 1]} proc prof {t} { set d 0 foreach c $t(children) { set d [expr {max($d, [prof $c])}] } return [expr {$d + 1}] } t "foreach en procédure (récursif)" {prof $A} type def point {{double}x; {double}y} type def mm double proc d1 {a} {( P is point = $a; [list [type get $P] $P(x)] )} t "déclaration, déjà typé" {d1 [type cast point {1.5 2.5}]} t "déclaration, valeur nue" {d1 {3.5 4.5}} t "déclaration, refus" {d1 {a b}} proc d2 {v} {( L is mm = $v; [type get $L] )} t "déclaration nominal" {d2 2.5} t "déclaration d'une note" {d2 {cm}3.5} proc g1 {} {( global gx; gx = 7; $gx )} t "global puis affectation" {list [g1] $::gx} proc u1 {nom} {( upvar 1 $nom y; y = 9; $y )} t "upvar puis affectation" {set z 1; list [u1 z] $z} proc v1 {} {( a = 1; b = $a + 1; [info locals] )} t "locales" {lsort [v1]} type def {-compact}poly list.point set {poly}P {0 0} {1 1} t "compact : lindex typé" {type get [lindex $P 1]}