Artifact 99fb30635ebeaa4b0c939dbaba93453b4f9c1638d6cf9706bf85260d3f13bf03:
- File typeparse/noyau/expr-nombres-types.patch — part of check-in [4269a60689] at 2026-10-24 13:29:48 on branch tip-764_tcl90 — Point 2 is complete and documented. All that remains is to wait for Valgrind and the full Tcl test suite—which are currently running in the background (taking about 40 minutes)—before sending the zip file. Previous behavior: Each read operation `$a(x)` would look up the field by its name and follow general path-resolution rules. Subsequently, `expr` would receive a typed value, causing it to exit its optimized "fast path" for numeric operations. Changes: Field caching: The index of a compiled read (the `x` in `$a(x)`) now stores the previously encountered type and the field's location. Subsequent reads involving the same type proceed directly to the element. Sums, variable links (`var`), and `list.any` continue to use the general path-resolution mechanism. Typed numbers in `expr`: An operand typed as `int` or `double` is now read directly from its underlying content. This is implemented via a new core patch, `expr-nombres-types.patch` (in `tclExecute.c`). The result is never written back into the operand; thus, a variable such as `{double}d` remains unchanged—a fact verified by the test suite. Measurements (10,000 points): Bare Tcl v15s current reading $a(x) within expr 0.05 µs (lindex) ≈ 0.52 µs 0.14 µs foreach a $P {set s [expr {$s + $a(x)}]} 0.64 ms 5.2 ms 1.5 ms Geometry, performance gap relative to the baseline (bare Tcl): calculation v15s v15u v15v area / 3.4 / 2.2 / 1.8 perimeter / 2.7 / 1.9 / 2.1 bounding box / 6.7 / 3.7 / 3.0 inside_all / 3.6 / 2.6 / 2.1 Bézier / 2.7 / 2.4 / 2.4 The perimeter figure shows a slight regression, from / 1.9 to / 2.1. This is likely measurement noise; this calculation primarily involves procedure calls. What remains during the read operation is the creation and subsequent release of the field's typed value. Eliminating this would require the `expr` command to know—at compile time—that it only requires a numeric value, which is a separate, more complex undertaking. Verified so far: All 54 tests pass, including the new `t76_lecture_champ` (field read) test, which produces the same output as it did before the change. Results are identical whether the compact form is used or not. (user: Florentis, size: 2380) [annotate] [blame] [check-ins using]
--- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -452,7 +452,17 @@ * void **ptrPtr, int *tPtr); */ +/* + * Un opérande typé int ou double ($q(x), une variable {double}) dont le + * contenu est déjà un nombre : lu directement dans le contenu (TIP 764). + */ +static inline int +GetNumberFromObjT(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptrPtr, + int *tPtr); #define GetNumberFromObj(interp, objPtr, ptrPtr, tPtr) \ + (TCL_ANNOT_P(objPtr) ? GetNumberFromObjT((interp), (objPtr), (ptrPtr), \ + (tPtr)) : GetNumberFromObjP((interp), (objPtr), (ptrPtr), (tPtr))) +#define GetNumberFromObjP(interp, objPtr, ptrPtr, tPtr) \ ((TclHasInternalRep((objPtr), &tclIntType)) \ ? (*(tPtr) = TCL_NUMBER_INT, \ *(ptrPtr) = (void *) \ @@ -467,6 +477,32 @@ ? TCL_ERROR : \ Tcl_GetNumberFromObj((interp), (objPtr), (ptrPtr), (tPtr))) +static inline Tcl_Obj * +NumObj(Tcl_Obj *objPtr) +{ + Tcl_Obj *c; + + if (TCL_ANNOT_P(objPtr) && (c = TclAnnotNumericContent(objPtr)) != NULL) { + return c; + } + return objPtr; +} + +static inline int +GetNumberFromObjT( + Tcl_Interp *interp, + Tcl_Obj *objPtr, + void **ptrPtr, + int *tPtr) +{ + Tcl_Obj *c = TclAnnotNumericContent(objPtr); + + if (c != NULL) { + objPtr = c; + } + return GetNumberFromObjP(interp, objPtr, ptrPtr, tPtr); +} + /* * Macro used to make the check for type overflow more mnemonic. This works by * comparing sign bits; the rest of the word is irrelevant. The ANSI C @@ -8516,8 +8552,9 @@ unsigned short base; if ((type1 == TCL_NUMBER_DOUBLE) || (type2 == TCL_NUMBER_DOUBLE)) { - Tcl_GetDoubleFromObj(NULL, valuePtr, &d1); - Tcl_GetDoubleFromObj(NULL, value2Ptr, &d2); + /* opérande typé : son contenu, déjà un nombre (TIP 764) */ + Tcl_GetDoubleFromObj(NULL, NumObj(valuePtr), &d1); + Tcl_GetDoubleFromObj(NULL, NumObj(value2Ptr), &d2); if (d1==0.0 && d2<0.0) { return EXPONENT_OF_ZERO; @@ -8727,8 +8764,9 @@ * floating point calculations. */ - Tcl_GetDoubleFromObj(NULL, valuePtr, &d1); - Tcl_GetDoubleFromObj(NULL, value2Ptr, &d2); + /* opérande typé : son contenu, déjà un nombre (TIP 764) */ + Tcl_GetDoubleFromObj(NULL, NumObj(valuePtr), &d1); + Tcl_GetDoubleFromObj(NULL, NumObj(value2Ptr), &d2); switch (opcode) { case INST_ADD: