Artifact 4b0693dd9f4676972ce15a004524b5bab53e4c4d4c48547f53d4a6c1e9b1b68f:
- File typeparse/tests_tclsh/t70_compact.out — part of check-in [40e39579b9] at 2026-10-23 16:08:45 on branch tip-764_tcl90 — The three points are complete: this is version v15p, found in `typeparse.zip`. Along the way, `valgrind` uncovered six memory errors, all of which have been fixed. 1. `tcl::unsupported::abi` provides the byte order, pointer size, and the size and alignment—within a structure—for `i8` through `i64`, `f32`, `f64`, and `ptr` types. These values are determined at compile time. 2. The compact (prototype) form is enabled via `tcl::unsupported::compact on`. For testing purposes, setting the environment variable `TCL_TYPES_COMPACT=1` achieves the same result. The state of a value can be inspected using `... info $P`, and the layout of a type can be viewed using `... layout T`. Four key design decisions have been implemented: use of a canonical form only, support for `int(s,n)`, `int(u,n)`, and `double` types, natural alignment, and the inclusion of an `unsupported` command. From the script perspective, nothing changes; all tests and examples produce identical output regardless of whether the compact form is enabled. The new test `t70_compact` verifies this on a case-by-case basis. Reading: `lindex` and `foreach` provide a view into a memory slot without copying the element. The syntax `$P(i.x)` reads the value directly from the slot. Writing: `set P(i.x)`, `lset`, and `lappend` perform writes directly into the slots. A copy—or a previously read view—retains its original value. C-side: `typeparse/tclCompact.h` provides access to these memory slots. `geo.c` now reads points in-place. standard form compact form memory, 200,000 points 264 bytes/point 16 bytes/point 10,000-point array in C (object-based approach) 564 µs 29 µs `lappend` of 20,000 points 8.7 s 0.25 s array in Tcl (using `lindex` followed by `$a(x)`) 15 ms 23 ms The last row represents the trade-off: when accessed element-by-element from Tcl, each access creates a view and a number. The gains are in memory usage, at the C interface, and during modifications. The `lappend` figure for the standard form is a separate issue: each addition copies the entire typed list. I have added this to the roadmap. 3. type c T … generates a C header containing: `struct`, `enum`, or `union` definitions for sum types; a flexible array member as the final field for variable-length lists; an `_INIT` macro for default values; and `_Static_assert` checks for `sizeof` and `offsetof`. I have verified this using `gcc`. When compiled in 32-bit mode (`-m32`), a structure like `{int(s,32); double}` causes the assertions to fail, as expected. `geo.c` now includes `geo_types.h`, which is generated by running `tclsh geo_types.tcl > geo_types.h`. Memory errors: I identified these using `Valgrind` on a `tclsh` build configured with `-DPURIFY`, which ensures that Tcl objects are allocated via `malloc`. Most of these were already present in v15: The most serious issue: after executing `set e [lindex $P 0]`, attempting to read `$P(0.x)` would cause a crash; furthermore, executing `set P(0.x) 7.5` would overwrite the entire point structure with the value `7.5`. In my v15m version: the error message "fits variants … equally" would inadvertently free the value it was referencing. Rejected declarations: when a declaration failed (e.g., `x is T = v`, `set {T}x`), the code would attempt to set a flag on a variable that had already been destroyed. Memory leak in `type binary decode`: fields that had already been read would leak when the C codec handed control back to the Tcl layer. Regarding the code in your TIP 759 branch: `ParseExpr` would read `nestedPtr->term` after it had already been freed; additionally, every evaluated word `(...)` would leak the result returned by `Tcl_ExprObj`. The fix is included in the `tip759-memoire.patch` file. I have added it to `ORDRE.txt`, but since this is your code, you will need to merge it into your branch. Feel free to remove it from `ORDRE.txt` if you would prefer to handle the fix yourself. Following corrections, Valgrind reports no issues for any tests or examples in either format. The only exception—which is inconsequential—involves a few objects that remain unreleased when a script terminates via an `exit` command mid-execution (in `executable_pe.tcl`). Compared to v15: Project: The only new differences are expected ones—the error message for type-related subcommands now references `c`, and there are new tests: `t69_abi`, `t70_compact`, and `t71_type_c`. All `.out` outputs pass. Full Tcl test suite: 61 failures out of 51,090—exactly the same as in v15. Everything is documented: `doc/ANNOTATIONS.fr.md`: § 12.1 (compact format) and § 12.2 (type `c`), with § 17 also updated; `noyau/LISEZMOI.md`: `v15p` section; `exemples/geometrie/LISEZMOI.md`. Regarding the TIP 764 roadmap, all three items are checked off; I have also added the following: pointer-based cases, direct reading via compiled `expr`, stub functions, and `lappend`. The two TIP 759 fixes are noted in their own dedicated roadmap. (user: Florentis, size: 2483) [annotate] [blame] [check-ins using]
disposition point : size 16 align 8 fields {{x float 8 0} {y float 8 8}} disposition pt3 : size 32 align 8 fields {{id int 4 0} {p.x float 8 8} {p.y float 8 16} {w float 4 24}} string : prod<s:string;> has no compact layout: only fixed-size scalars (int(s,n), int(u,n) with n = 8, 16, 32 or 64, double, double(32|64)) and products of them int : int has no compact layout: only fixed-size scalars (int(s,n), int(u,n) with n = 8, 16, 32 or 64, double, double(32|64)) and products of them construire identique compacte 0 {0.5 1.5} {2.5 3.5} {-1.0 4.0} type, llength identique compacte 0 list<point> 2 lindex, type identique compacte 0 {2.5 3.5} point 3.5 chemin P(1.y) identique compacte 0 3.5 double 2.5 foreach identique compacte 0 0.5 point 2.5 point écrire P(1.y) identique compacte 0 {0.5 1.5} {2.5 9.5} écrire 9 (non canonique) identique ordinaire 0 {0.5 1.5} {2.5 9} lappend identique compacte 0 {0.5 1.5} {7.5 8.5} lappend invalide identique compacte 1 expected floating-point number but got "a" lset identique compacte 0 {1.25 2.25} {2.5 3.5} lrange, lsort identique compacte 0 {{0.5 1.5}} {{0.5 1.5} {2.5 3.5}} non canonique 1 2 identique ordinaire 0 {1 2} {3 4} espaces gardés identique compacte 0 {0.5 1.5} {2.5 3.5} produit imbriqué identique compacte 0 {{7 {0.5 0.25} 0.5} {-3 {1.0 2.0} 0.25}} 2.0 point int(s,32) trop grand identique compacte 1 value "99999999999" does not fit in int(s,32) double(32) inexact identique ordinaire 0 {7 {0.5 0.25} 0.1} u8 identique compacte 0 {1 2 3 255} 1 {value "256" does not fit in int(u,8)} {1 2 3 255} vecteur de double identique compacte 0 {0.1 0.2 0.30000000000000004} 0.4 lire après lindex identique compacte 0 0.5 1.5 vue gardée après écriture identique compacte 0 {0.5 1.5} {{7.5 1.5} {2.5 3.5}} copie puis écriture identique compacte 0 {{0.5 1.5}} {{0.5 5.5}} élément vers autre liste identique compacte 0 {2.5 3.5} {0.5 1.5} string length identique ordinaire 0 9 list<point> contenu identique compacte 0 {0.5 1.5} binary decode identique compacte 0 {1.5 2.5} {3.5 4.5}