<i>lappend/linsert ignore the abstract-list Replace hook on some code paths</i>.
by
.
D 2026-10-13T22:02:13.330
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment #\sAppending\sto\san\sabstract\slist\swith\sa\sReplace\shook\skeeps\sor\sloses\sthe\stype\sdepending\son\show\sthe\scommand\sis\sevaluated\r\n\r\n##\sSummary\r\n\r\nAn\sabstract\slist\swhose\stype\sprovides\sa\s`replaceProc`\scan\slose\sits\stype\swhen\selements\sare\sappended.\sIn\sthis\sreport:\r\n\r\n*\s**What\shappens:**\s"append\sat\sthe\send"\stakes\sone\sof\stwo\spaths\sin\sthe\score.\r\n\s\s*\s`Tcl_ListObjReplace`:\sthe\stype\sis\skept\sand\sthe\sReplace\shook\sis\scalled.\r\n\s\s*\s`Tcl_ListObjAppendElement`\s/\s`TclListObjAppendElements`:\sthe\sobject\sis\sconverted\sin\splace\sto\san\sordinary\slist,\sand\sthe\shook\r\n\s\s\s\sis\snever\sconsulted.\r\n*\s**What\sdecides\sthe\spath:**\sonly\show\sthe\scommand\sis\sevaluated.\r\n\s\s*\s`linsert`\sof\sone\selement\sat\sthe\send:\skept\sif\sbytecode-compiled,\slost\sif\snot\scompiled.\r\n\s\s*\s`lappend`:\slost\swhen\scompiled\sinside\sa\sproc\s(compiled\slocal\svariable),\skept\sat\sglobal\sor\snamespace\slevel.\r\n*\s**Effect:**\sthe\sresulting\slist\sis\salways\scorrect.\sOnly\sthe\srepresentation\sdiffers,\sand\swith\sit\smemory\suse\sand\sspeed.\r\n*\s**Reproduction:**\sstock\sTcl\sonly,\susing\sthe\score's\sown\s`lstring`\stest\stype\sin\sthe\s`tcltest`\sshell\s(below).\r\n*\s**Open\squestion:**\sI\sdo\snot\sknow\swhether\sthis\sis\sintended.\s`doc/ObjectType.3`\sdocuments\s`ReplaceProc`\sonly\sas\scorresponding\sto\r\n\s\s`Tcl_ListObjReplace`\sand\ssays\snothing\sabout\sappend,\sso\sI\sam\sreporting\sit\sas\san\sinconsistency\sto\sbe\sjudged,\snot\sas\sa\scertain\sbug.\r\n\r\n##\sReproduction\s(no\sextension\sneeded)\r\n\r\nThe\score\stest\sbuild\shas\san\sabstract\slist\swith\sa\sReplace\shook,\s`lstring`\s(`generic/tclTestABSList.c`,\sused\sby\s`tests/abstractlist.test`).\r\nIt\sexists\sonly\sin\sthe\s`tcltest`\sshell\s(`make\stcltest`);\sin\san\sordinary\s`tclsh`\sor\s`wish`\sthe\sscript\sfails\swith\s`invalid\scommand\sname\s"lstring"`.\r\n\r\n```tcl\r\n#\sReproduction\swith\sstock\sTcl\sonly:\sneeds\sa\stcltest\sshell\s(test\scommands\sbuilt\sin),\swhich\sprovides\s[lstring].\r\n#\s[lstring]\smakes\san\sabstract\slist\sthat\sHAS\sa\sReplace\shook.\s\s\sUsage:\stcltest\slstring_repro.tcl\r\nproc\stype\s{v}\s{\slindex\s[tcl::unsupported::representation\s$v]\s3\s}\r\nproc\smk\s{}\s{\slstring\sabcdef\s}\r\nproc\scompiled\s{}\s{\r\n\s\s\s\sset\sb\s[mk];\sset\sc\s[linsert\s$b\send\sz];\s\sputs\s"linsert\send\s1\selem\s\scompiled\s(INST_LREPLACE)\s\s\s\s\s:\s[type\s$c]"\r\n\s\s\s\sset\sb\s[mk];\slappend\sb\sz;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sputs\s"lappend\s1\selem\s\s\s\s\s\s\scompiled\sin\sa\sproc\s\s\s\s\s\s\s\s\s\s\s:\s[type\s$b]"\r\n\s\s\s\sset\sb\s[mk];\slappend\sb\sy\sz;\s\s\s\s\s\s\s\s\s\s\s\s\sputs\s"lappend\s2\selems\s\s\s\s\s\scompiled\sin\sa\sproc\s\s\s\s\s\s\s\s\s\s\s:\s[type\s$b]"\r\n}\r\nproc\sinterpreted\s{}\s{\s\s\s;#\scommand\sname\sin\sa\svariable\s=>\snot\scompiled\s=>\sthe\sTcl_*ObjCmd\sfunctions\srun\sdirectly\r\n\s\s\s\sset\sli\slinsert;\sset\sla\slappend\r\n\s\s\s\sset\sb\s[mk];\sset\sc\s[$li\s$b\send\sz];\s\s\s\s\s\sputs\s"linsert\send\s1\selem\s\s\sNOT\scompiled\s(Tcl_LinsertObjCmd):\s[type\s$c]"\r\n\s\s\s\sset\sb\s[mk];\sset\sc\s[$li\s$b\send\sy\sz];\s\s\s\sputs\s"linsert\send\s2\selems\s\sNOT\scompiled\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s:\s[type\s$c]"\r\n\s\s\s\sset\sb\s[mk];\sset\sc\s[$li\s$b\s2\sz];\s\s\s\s\s\s\s\sputs\s"linsert\smiddle\s\s\s\s\s\s\sNOT\scompiled\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s:\s[type\s$c]"\r\n\s\s\s\sset\sb\s[mk];\s$la\sb\sz;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sputs\s"lappend\s1\selem\s\s\s\s\s\s\sNOT\scompiled\s(Tcl_LappendObjCmd):\s[type\s$b]"\r\n}\r\ncompiled;\sinterpreted\r\n```\r\n\r\nRun\sas\s`./tcltest\slstring_repro.tcl`.\sOutput:\r\n\r\n```\r\nlinsert\send\s1\selem\s\scompiled\s(INST_LREPLACE)\s\s\s\s\s:\slstring\r\nlappend\s1\selem\s\s\s\s\s\s\scompiled\sin\sa\sproc\s\s\s\s\s\s\s\s\s\s\s:\slist\r\nlappend\s2\selems\s\s\s\s\s\scompiled\sin\sa\sproc\s\s\s\s\s\s\s\s\s\s\s:\slist\r\nlinsert\send\s1\selem\s\s\sNOT\scompiled\s(Tcl_LinsertObjCmd):\slist\r\nlinsert\send\s2\selems\s\sNOT\scompiled\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s:\slstring\r\nlinsert\smiddle\s\s\s\s\s\s\sNOT\scompiled\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s:\slstring\r\nlappend\s1\selem\s\s\s\s\s\s\sNOT\scompiled\s(Tcl_LappendObjCmd):\slstring\r\n```\r\n\r\n##\sWhich\score\scode\sdoes\swhat\r\n\r\nForm,\sthen\spath\staken\sin\sthe\score,\sthen\sthe\stype\safterwards:\r\n\r\n```\r\nkept\s\slinsert\s$l\send\sX,\scompiled\r\n\s\s\s\s\s\s->\sINST_LREPLACE\s->\sTcl_ListObjReplace\r\nLOST\s\slinsert\s$l\send\sX,\sNOT\scompiled\s(dynamic\scommand\sname,\s{*}\scommand\sword,\s...)\r\n\s\s\s\s\s\s->\sTcl_LinsertObjCmd,\sspecial\scase\s"insert\sone\selement\sat\sthe\send"\s->\sTcl_ListObjAppendElement\r\nkept\s\slinsert\swith\s2+\selements,\sor\snot\sat\sthe\send\r\n\s\s\s\s\s\s->\sTcl_ListObjReplace\r\nLOST\s\slappend\sv\sX,\scompiled\sin\sa\sproc\s(compiled\slocal),\s1\selement\r\n\s\s\s\s\s\s->\slappendScalar\s->\sListAppendInVar\s->\sTcl_ListObjAppendElement\r\nLOST\s\slappend\sv\sX\sY,\scompiled\sin\sa\sproc\r\n\s\s\s\s\s\s->\slappendList\s->\slappendListDirect\s->\sTclListObjAppendElements\r\nkept\s\slappend\scompiled\sat\sglobal/namespace\slevel\s(source,\seval,\suplevel)\r\n\s\s\s\s\s\s->\slappendListStk\s->\sTcl_ListObjReplace\r\nkept\s\slappend,\sNOT\scompiled\r\n\s\s\s\s\s\s->\sTcl_LappendObjCmd\r\n```\r\n\r\nBoth\spaths\smarked\s"lost"\send\sin\s`TclListObjGetRep`\s->\s`SetListFromAny`\s(`generic/tclListObj.c`),\swhich\sconverts\sthe\sobject\sto\sa\sreal\slist\r\nin\splace.\s`Tcl_ListObjReplace`\sinstead\scalls\sthe\stype's\sReplace\shook\s(`TclObjTypeHasProc(listObj,\sreplaceProc)`).\r\n\r\nSide\sobservation\sthat\smade\sthis\slook\srandom\sat\sfirst:\sthe\smain\sscript\sgiven\sto\s`tclsh`\sis,\sfrom\smy\sreading\sof\s`Tcl_FSEvalFileEx`\r\n(`TclEvalEx`),\sevaluated\sdirectly\sand\snot\scompiled,\swhile\sa\s`source`d\sfile\sand\sprocs\sare\scompiled,\sso\sthe\ssame\sline\sof\scode\sbehaves\r\ndifferently\sat\sthe\stop\sof\sthe\smain\sscript\sthan\sinside\sa\sproc.\sI\sdid\snot\sconfirm\sthat\sin\sa\sdebugger.\r\n\r\n##\sWhy\sit\smatters\r\n\r\nAn\sextension\sthat\sprovides\sa\scompact\sabstract\slist\s(I\sfound\sthis\swith\sa\spacked\sbit-array\stype\sthat\sstores\s1\sbit\sper\selement)\r\nloses\sits\srepresentation\ssilently\son\sa\ssingle\s`lappend`.\sFor\sa\sten-million-element\sarray\sthat\sturns\sa\sfew\sMB\sinto\san\sordinary\r\nlist\s(I\smeasured\s+76\sto\s152\sMB\sfor\s`{*}$a`\sexpansion\sof\ssuch\san\sarray;\sI\sdid\snot\smeasure\sthe\scost\sof\sthe\sin-place\sconversion\sitself).\r\n\r\n`lseq`\s(arithseries)\scannot\sshow\sthis,\sbecause\sit\shas\sno\sReplace\shook\sand\sappending\sto\san\sarithmetic\ssequence\shas\sto\sleave\sthe\stype\r\nanyway;\sthat\sis\swhy\sthe\sreproduction\suses\s`lstring`.\r\n\r\n##\sTest\scoverage\r\n\r\n`tests/abstractlist.test`\salready\schecks\stype\spreservation,\sso\sthis\sis\snot\san\suntested\sarea:\r\n\r\n*\sIt\shas\smany\s"no\sshimmer\s..."\stests,\sand\ssome\sthat\sassert\sthe\sopposite\son\spurpose\s("shimmer\slassign",\s"shimmer\slset",\r\n\s\s"!no\sshimmer\slreplace").\r\n*\sIts\s`linsert`\stests\s(abstractlist-2.7,\s3.7\sand\sthe\s4.7\svariant)\sinsert\sseveral\selements\sin\sthe\smiddle\sof\san\s`lstring`\r\n\s\s(positions\s11,\s35\sand\s12).\sThat\sgoes\sthrough\s`Tcl_ListObjReplace`,\sand\sthe\stests\sconfirm\sthe\stype\sis\skept.\r\n\r\nWhat\sI\sfound\sno\stest\sfor\s(`lstring`\sappears\sin\sno\sother\stest\sfile):\r\n\r\n*\s`lappend`\sonto\san\s`lstring`.\r\n*\s`linsert`\sof\sa\ssingle\selement\sat\sthe\send.\r\n*\sThe\ssame\soperation\srun\sboth\scompiled\sand\snot\scompiled.\r\n\r\nThose\swould\sbe\snatural\splaces\sfor\sa\sregression\stest,\swhichever\sway\sthis\sis\sresolved.\r\n\r\n##\sPossible\sdirections\s(for\sdiscussion\sonly)\r\n\r\n*\sHave\s`TclListObjAppendElements`\s(and\sso\s`Tcl_ListObjAppendElement`)\suse\sthe\sReplace\shook\swhen\sthe\sobject\shas\sone,\sthe\sway\r\n\s\s`Tcl_ListObjReplace`\sdoes;\sor\r\n*\sdocument\sthat\sappend\signores\sthe\shook,\sso\sextension\sauthors\sknow\sto\sexpect\sthe\sconversion.\r\n\r\n##\sEnvironment\r\n\r\n*\sClean\scheckout\sof\s`github.com/tcltk/tcl`\sat\s`e36db3376a2d7d4857f6c766bd6133fc7b29e821`\s(2026-10-02,\s"Update\sto\sthe\s'official'\r\n\s\sutf8proc\s2.12.0"),\s`git\sstatus`\sclean.\r\n*\sLinux\sx86-64,\sgcc,\s`./configure\s--disable-shared\s&&\smake\stcltest`.\r\n*\sThe\ssame\sresults\swere\salso\sseen\swith\san\sextension\son\san\searlier\strunk\s(`3d77be8951`).\r\n*\sIndependently\sreproduced\sby\sthe\sreporter\son\sa\ssecond\sLinux\smachine\s(a\svirtual\smachine),\swith\sa\sstock\stree\sbuilt\sfrom\sa\sFossil\r\n\s\scheck-in\swhose\s`tcl::build-info`\sreads\s`9.1.1+4991a47b94705ddff07bd81cab83291e5f6d219a8a75b54a32c954e73b05eaae.gcc-1303.tommath-0103`\r\n\s\s(shared\sbuild,\sgcc);\s`./tcltest\slstring_repro.tcl`\sprinted\sthe\ssame\sseven\slines.\sThe\sreporter\sbuilt\sthat\stree\sfrom\sa\sstock,\sunmodified\scheckout\r\n\s\sfetched\sa\sday\sor\stwo\sbefore\s2026-10-13.\sIt\sis\sa\sFossil\sid,\sso\sit\sis\snot\sdirectly\scomparable\swith\sthe\sgit\scommit\sabove.\r\n*\sNot\stested:\sother\splatforms,\sTcl\s9.0.x\s(the\sversion-2\sabstract-list\shooks\sare\s9.1\sonly),\sother\scompilers.\r\n\r\n##\sNote\son\show\sthis\swas\sproduced\r\n\r\nThe\sanalysis\sand\sthe\sreproduction\sscript\swere\sproduced\swith\sClaude\s(an\sAI\sassistant\smade\sby\sAnthropic)\sworking\swith\sme;\sthe\r\nresults\sabove\sare\sfrom\sruns\sof\sthe\sscript,\sand\sthe\ssource\sreferences\sare\sfrom\sreading\sthe\sfiles\snamed.
J foundin 9.1.1
J is_private 0
J login rocketship98
J priority 5\sMedium
J private_contact b5d6d6e631648ab8145961ecf2e3fa064603ac0a
J resolution None
J severity Minor
J status Open
J submitter rocketship98
J subsystem 14.\sList\sObject
J title lappend/linsert\signore\sthe\sabstract-list\sReplace\shook\son\ssome\scode\spaths
J type Bug
K 0c82728f85760f36361fe42a15f55453c94d285d
U rocketship98
Z e71359b63c83c0a673c9a13d8ba7e624