Artifact d233fc519748eb7119f9651b9b7682aa63a3958a8298deeed02c8389432bfc66:
- File typeparse/noyau/donnees-interp.patch — part of check-in [203a80b8f5] at 2026-10-25 08:04:02 on branch tip-764_tcl90 — `lappend` under contract. When the variable is the sole holder of its value—which is the typical scenario in an `lappend L ...` loop—the element is validated individually and then added directly to the content. The existing elements are already guaranteed to be valid by the contract. If the element is rejected, the state remains unchanged: the standard execution path proceeds, issuing the usual error message, and the variable remains exactly as it was. The standard execution path is still used in three cases: the value is shared (e.g., copied into another variable or currently being iterated over by a `foreach` loop); the list has a fixed size, `list(N)`; the element is a sum type, a `var` link, `list.any`, or a binary link. For 20,000 `lappend` operations within a procedure: list v15y v15z "Bare" Tcl `list.point` 7.7 s ≈ 15 ms ≈ 10 ms compact form 0.19 s ≈ 15 ms Performance returns to linear time, at approximately 1.4 times the speed of "bare" Tcl. I encountered a crash during development. An earlier version of the shortcut also handled lists containing `var` links, which caused a crash in `t62` because canonical names must be constructed in those cases. I have restricted it to simple element types, and all tests now pass again. Verified so far: All 58 tests pass, including the new `t80_lappend_contrat`. It produces the same output as in `v15y` across various scenarios: shared copies, rejected elements, multiple elements, compact form, sum types, `list.any`, `list(2)`, and `lappend` operations during a `foreach` loop. The output remains identical regardless of whether the compact form is used. A bug was identified while writing the test; it was already present in `v15y` and has not been fixed here. With the `forme` structure (`{double}cote`, `{string}nom`), appending `S {nom}` to a list stores the element without its variant; the `get` method returns an empty string instead of `forme.nom`. I have noted this in the schedule and in the README. ----------------------------- Version v15z. The contracted `lappend` implementation is delivered, following a fix for the memory leak detected by Valgrind. Valgrind now reports no issues, and the full Tcl test suite shows the same 61 failures as in v15. Additional features covered by the C-based codec (v16a): Fixed-size strings: `string(raw,8)` for raw bytes, `string(utf-8,8)` for text. These are padded with zeros upon writing, and trailing zeros are stripped upon reading. Null-terminated strings: `string(…,z)`, using a two-byte null terminator for UTF-16. Literal-based tags: signatures such as "MZ". Tagged fields—`S($field)`: the tag (already read) determines the variant, and the parsed value retains that variant. Any case that the C implementation cannot handle is passed back to the Tcl layer, accompanied by appropriate error messages—for instance, in the event of an unknown tag, an incorrect literal, truncated data, or text that cannot be represented by the specified encoding. Benchmarks: Tcl codec C codec 34-byte header, encoding 41 µs 1.0 µs 34-byte header, decoding 57 µs 1.3 µs Tagged-field block, decoding 66 µs 1.2 µs A performance bottleneck was identified during benchmarking, affecting the C-based decoding codec. The `binary decode` operation was converting data into a byte array before even checking whether the C codec supported that specific type. If it did not, the Tcl layer would then convert the data back into a string to search for the null terminator (as required for a C-style string). Consequently, the entire file’s representation was being toggled back and forth with every single call. The type is now examined first. niveau2.tcl, which reads the tclsh executable, goes from 1.8 s to 0.1 s. Furthermore, these examples maintain the same speed, as their types still rely on calculated sizes, `at(...)` constructs, or links—this corresponds to point 3. Verified thus far: All 59 tests pass, including the new `t81_codec_c_chaines`, which yields the same bytes, values, types, and variants as the Tcl layer. All examples produce identical output whether using the C codec or with `set ::tcl_typebinaryc 0`. Outputs remain the same both with and without the compact format. --------------------------- Version v16a is included in typeparse.zip: the C-based codec can now handle strings, sums of literals, and tagged sums. When processing a small header, encoding and decoding are 40 to 50 times faster than with the Tcl-based codec. Regarding verification: Valgrind reports a clean run, aside from the usual leaks upon exiting `executable_pe`. The full Tcl test suite shows the same 61 failures as in v15. Only `tclTypes.c` has been modified; there are no kernel patches. Version v16a also addresses the performance issues with `type binary decode` for types not covered by the C implementation—previously, the entire file was being converted with every call. As a result, the execution time for `niveau2.tcl` has dropped from 1.8 seconds to 0.1 seconds. As for the C-based codec, the next item to address is point 3: calculated sizes and prefixes (e.g., `string(raw,$len)`, `list(u16).T`). This will provide significant gains for real-world file formats, such as the ELF or PE examples. Following this, the next steps will be to implement `at(...)` and, finally, support for links. (user: Florentis, size: 1030) [annotate] [blame] [check-ins using]
--- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -983,6 +983,9 @@ iPtr->rootFramePtr = NULL; /* Initialise as soon as :: is available */ iPtr->lookupNsPtr = NULL; + iPtr->typesData = NULL; /* TIP 764: set by the type system */ + iPtr->typeRefsData = NULL; + iPtr->varRefData = NULL; Tcl_InitHashTable(&iPtr->packageTable, TCL_STRING_KEYS); iPtr->packageUnknown = NULL; --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2356,6 +2356,15 @@ Tcl_Obj *innerContext; /* cached list for fast reallocation */ int resetErrorStack; /* controls cleaning up of ::errorStack */ + /* + * TIP 764: per-interpreter data of the type system (tclTypes.c, + * tclAnnotObj.c, tclVarRef.c), also registered as assoc data; kept here + * so that each access avoids a Tcl_GetAssocData hash lookup. + */ + void *typesData; + void *typeRefsData; + void *varRefData; + #ifdef TCL_COMPILE_STATS /* * Statistical information about the bytecode compiler and interpreter's