Artifact 77e264391d40191a77750067dbbb7c578478c3072b68e34e1d1f2be4da498bc6:
- Executable file generic/tclTypesInt.h — 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: 8514) [annotate] [blame] [check-ins using]
- File typeparse/tclTypesInt.h — 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: 8514) [annotate] [blame] [check-ins using]
/* * tclTypesInt.h -- * * Interface INTERNE entre tclTypes.c (table de types, interning, * validation, cast) et tclTypeParse.c (analyseur et compilateur des * expressions de types). Rien ici n'est destiné au reste du noyau. */ #ifndef TCLTYPESINT_H #define TCLTYPESINT_H #include "tclTypes.h" /* * Types paramétrés : type def matrix({int}i, {int}j = 3) {list(i).list(j).int} * * TypeParam décrit un paramètre (déclaration) et, dans une instanciation, * la valeur de son argument. TypeGeneric est le type paramétré lui-même ; * chaque instance (matrix(3,3)) est un type nominal ordinaire, interné par * (nom, arguments). */ typedef struct TypeParam { Tcl_Obj *name; /* identifiant */ int isType; /* 1 : {type}T, l'argument est un type */ int isCmd; /* 1 : {cmd}c, l'argument est un nom de commande * pleinement qualifié (::ns::cmd) */ TclType *type; /* sinon : type de l'argument (int, string...) */ char *defText; /* texte du défaut ("= ..."), ou NULL */ Tcl_Obj *value; /* instance : texte canonique de l'argument */ TclType *typeValue; /* instance : l'argument, si isType */ } TypeParam; typedef struct TypeParams { TypeParam *p; Tcl_Size n; /* nombre de paramètres déjà liés */ } TypeParams; typedef struct TypeGeneric { char *name; Tcl_Size nparams; TypeParam *params; char *body; /* texte du type, avec les paramètres libres */ Tcl_Size bodyLen; int alias; /* 1 : type alias paramétré : l'instance est le type * du corps lui-même (structurel), pas un type * nominal de plus */ int bits; /* 1 : bitarray, l'instance reçoit bitWidth et * bitMsb0 et binEnd */ TclType *paramsType; /* produit anonyme des paramètres, construit à la * première règle de famille qui en a besoin */ } TypeGeneric; typedef struct TypeData { Tcl_HashTable names; /* nom -> TclType* (NULL pour "array") */ Tcl_HashTable generics; /* nom -> TypeGeneric* */ Tcl_HashTable instances; /* "nom, 0x01, arg, 0x01, arg" -> TclType* */ char **instLog; /* clés créées par l'instanciation en cours, * pour les retirer en cas d'échec */ Tcl_Size nInstLog, capInstLog; int instDepth; Tcl_HashTable canon; /* nom canonique -> type anonyme interné */ TclType *linkStack[32]; /* liens en cours de développement (BinRepr) */ int nLinkStack; Tcl_HashTable converts; /* "De\1Vers" -> lambda (Tcl_Obj*, compté) */ Tcl_HashTable derefs; /* type deref : TclType* -> son type sans liens * (produits et sommes, y compris récursifs) */ TclType **all; Tcl_Size nAll, capAll; TclType *tInt, *tDouble, *tString, *tList, *tDict, *tVar; TclType *tAt; /* constructeur at(EXPR).T (caché : pas un nom) */ TclType *tLink; /* constructeur *(...).T (caché : pas un nom) */ void **blobs; /* décorations binaires (TclBinDyn, textes), * partagées par les types, libérées à la fin */ Tcl_Size nBlobs, capBlobs; size_t uid; /* identifiant de cette table de types */ size_t gen; /* génération : augmente à chaque changement des * noms (type def, famille, annulation) ; un * classement d'annotation en cache n'est valable * que pour la même (uid, gen) */ Tcl_HashTable parsed; /* texte d'un type -> TclType* déjà analysé * (TclTypeParse), valable pour parsedGen */ size_t parsedGen; } TypeData; void TclTypesBump(TypeData *d); #define ERR(interp, code, ...) \ do { \ if ((interp) != NULL) { \ Tcl_SetObjResult((interp), Tcl_ObjPrintf(__VA_ARGS__)); \ Tcl_SetErrorCode((interp), "TCL", "TYPE", code, (char *) NULL); \ } \ } while (0) /* * Environnement de compilation d'un type : l'analogue de CompileEnv pour * TclCompileExpr. Il porte le contexte (le type en cours de définition) et * reçoit le résultat. */ typedef struct TypeEnv { TypeData *d; /* table de types de l'interpréteur */ const TypeParams *params; /* paramètres liés (corps d'un type paramétré * ou arguments d'une instanciation), ou NULL */ const char *selfName; /* type en cours de définition, ou NULL */ TclType *self; TclType *into; /* type nominal à remplir (racine), ou NULL */ TclType *result; /* résultat de la compilation */ void *stack; /* pile d'opérandes (privée à tclTypeParse.c) */ Tcl_Size nStack, capStack; } TypeEnv; /* tclTypeParse.c */ /* Un mot de valeur : "texte", {texte}, mot nu, ou $param. */ int TclTypeParseWord(Tcl_Interp *interp, const TypeEnv *envPtr, const char **pp, const char *end, int isValue, Tcl_Obj **objPtr); int TclCompileType(Tcl_Interp *interp, const char *script, Tcl_Size numBytes, TypeEnv *envPtr); int TclTypeIsNameChar(int c); int TclTypeIsCmdName(const char *s); /* La ")" qui ferme une "(" déjà lue, ou NULL. */ const char *TclTypeFindArgsEnd(const char *p, const char *limit); /* tclTypeGeneric.c : types paramétrés */ const TypeParam *TclTypeFindParam(const TypeParams *ps, const char *name, Tcl_Size len); TypeGeneric *TclTypesFindGeneric(TypeData *d, const char *w, Tcl_Size len); /* argText == NULL : aucun argument (tous les paramètres ont un défaut). */ TclType *TclTypesInstantiate(Tcl_Interp *interp, TypeData *d, TypeGeneric *g, const char *argText, Tcl_Size argLen, const TypeEnv *parent); int TclTypesDefineGeneric(Tcl_Interp *interp, TypeData *d, const char *spec, Tcl_Size specLen, const char *body, Tcl_Size bodyLen, int alias); void TclTypesFreeGenerics(TypeData *d); /* Marque le type paramétré NAME : 1 bitarray. */ void TclTypesMarkBits(TypeData *d, const char *name, int code); /* Octets du terminateur NUL de string(enc,z) pour un encodage Tcl. */ int TclTypesNulWidth(const char *tclName); /* tclTypes.c : services utilisés par le compilateur de types */ TclType *TclTypesNewType(TypeData *d, TclTypeKind kind, const char *name); int TclTypesInhabited(const TclType *tp, const TclType **stack, int depth); void TclTypesCopyInto(TclType *into, const TclType *res); int TclTypesCheckNewName(Tcl_Interp *interp, TypeData *d, const char *name); TclType *TclTypesResolve(Tcl_Interp *interp, TypeData *d, const char *selfName, TclType *self, const char *w, Tcl_Size len); /* int(u,16,be), double(32,le), string(utf-8,8) : le type de base (int, * double, string) avec sa représentation binaire. */ TclType *TclTypesBinaryType(Tcl_Interp *interp, TypeData *d, const char *base, Tcl_Size baseLen, const char *argText, Tcl_Size argLen, const TypeParams *params); /* Argument de taille, de nombre ou de position : N, z, un préfixe (type * entier non signé) ou une expression avec $champ. */ int TclTypesParseSize(Tcl_Interp *interp, TypeData *d, const char *what, const char *text, Tcl_Size len, int allowZ, const TypeParams *params, Tcl_WideInt *nPtr, int *zPtr, TclBinDyn **dynPtr); void *TclTypesKeep(TypeData *d, void *blob); char *TclTypesKeepText(TypeData *d, const char *s, Tcl_Size len); /* list(PRÉFIXE|$expr).T, at(EXPR).T, S($champ) : types décorés. */ TclType *TclTypesMakeListDyn(TypeData *d, TclType *elem, TclBinDyn *dyn); TclType *TclTypesMakeAt(TypeData *d, TclType *elem, const char *expr); TclType *TclTypesMakeLink(Tcl_Interp *interp, TypeData *d, TclType *elem, TclBinLink *link); TclType *TclTypesMakeTagged(Tcl_Interp *interp, TypeData *d, TclType *sum, const char *field, int isConst); /* list.T : liste de T, extensible. */ TclType *TclTypesMakeList(TypeData *d, TclType *elem); TclType *TclTypesMakeListExplicit(TypeData *d, TclType *elem); /* list(N).T : exactement N éléments (arity >= 0) ; arity < 0 : extensible. */ TclType *TclTypesMakeListN(TypeData *d, TclType *elem, Tcl_Size arity); /* var.T : nom d'une variable dont la valeur est un T ; typed != 0 exige * que la variable soit typée. */ TclType *TclTypesMakeVar(TypeData *d, TclType *elem, int typed); /* dict.T (clés quelconques) si keyed == 0, sinon dict(clés).T. Les clés * sont toujours du texte. Prend possession de keys. */ TclType *TclTypesMakeDict(TypeData *d, TclType *elem, int keyed, TclDictKey *keys, Tcl_Size nkeys); void TclTypesFreeKeys(TclDictKey *keys, Tcl_Size n); /* Prend possession de fields (même en cas d'échec). */ TclType *TclTypesFinish(Tcl_Interp *interp, TypeData *d, const char *selfName, TclTypeKind kind, TclTypeField *fields, Tcl_Size n, TclType *into); void TclTypesFreeFields(TclTypeField *fields, Tcl_Size n); #endif /* TCLTYPESINT_H */