Overview
| Comment: | 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. |
|---|---|
| Timelines: | family | ancestors | descendants | both | tip-764_tcl90 |
| Files: | files | file ages | folders |
| SHA3-256: |
40e39579b9692e83613beaad5e2a4b33 |
| User & Date: | Florentis on 2026-10-23 16:08:45.392 |
| Other Links: | branch diff | manifest | tags |
Context
|
2026-10-24
| ||
| 04:37 | V15q `type def {-compact}T`, `type is {compact?}`, and `type {c!}export` are now in place, following... check-in: 7952bb1028 user: Florentis tags: tip-764_tcl90 | |
|
2026-10-23
| ||
| 16:08 | The three points are complete: this is version v15p, found in `typeparse.zip`. Along the way, `valgr... check-in: 40e39579b9 user: Florentis tags: tip-764_tcl90 | |
| 11:38 | Addressing "lset leak via TclLsetList (Claude)" Shared a file, used Claude Docs, executed 29 command... check-in: d03339047e user: Florentis tags: tip-764_tcl90 | |
Changes
Modified generic/tclAnnotObj.c
from [9b1cec1038]
to [2ca15dee68].
[diff]
Modified generic/tclCompExpr.c
from [55d11be9b4]
to [0b037260ac].
[diff]
Modified generic/tclParse.c
from [91fcef2f82]
to [268a2e7d14].
[diff]
Modified generic/tclTypePath.c
from [ebb6e8d853]
to [b8eb88c334].
[diff]
Modified generic/tclTypedVar.c
from [6c7b9c8a53]
to [0a1d9f233c].
[diff]
Modified generic/tclTypes.c
from [6227105702]
to [0c60184813].
[diff]
Modified generic/tclTypes.h
from [4068312d59]
to [23a3ed9d58].
[diff]
Modified typeparse/doc/ANNOTATIONS.fr.md
from [cbfbc97645]
to [f3f45098b9].
[diff]
Modified typeparse/exemples/geometrie/LISEZMOI.md
from [968b924ed8]
to [4aefe9c768].
[diff]
Modified typeparse/exemples/geometrie/geo.c
from [c7fa159653]
to [56056eec4a].
[diff]
Added typeparse/exemples/geometrie/geo_types.h version [a3cf44aa24].
Added typeparse/exemples/geometrie/geo_types.tcl version [a4caba934c].
Modified typeparse/noyau/LISEZMOI.md
from [87f33cc4c0]
to [5a7041a492].
[diff]
Modified typeparse/noyau/ORDRE.txt
from [1b7fbc343e]
to [c28e02fb38].
[diff]
Added typeparse/noyau/tip759-memoire.patch version [2c4f5cd71b].
Modified typeparse/tclAnnotObj.c
from [9b1cec1038]
to [2ca15dee68].
[diff]
Added typeparse/tclCompact.h version [ab0faf8753].
Modified typeparse/tclTypePath.c
from [ebb6e8d853]
to [b8eb88c334].
[diff]
Modified typeparse/tclTypedVar.c
from [cdb7dd777a]
to [0a1d9f233c].
[diff]
Modified typeparse/tclTypes.c
from [6227105702]
to [0c60184813].
[diff]
Modified typeparse/tclTypes.h
from [4068312d59]
to [23a3ed9d58].
[diff]
Added typeparse/tests_tclsh/t69_abi.out version [d5292313c8].
Added typeparse/tests_tclsh/t69_abi.tcl version [132b07913a].
Added typeparse/tests_tclsh/t70_compact.out version [4b0693dd9f].
Added typeparse/tests_tclsh/t70_compact.tcl version [e78b7d6064].
Added typeparse/tests_tclsh/t71_type_c.out version [0f1ed6f91a].
Added typeparse/tests_tclsh/t71_type_c.tcl version [998779dc79].