Skip to content
Tcl Source Code Artifact [c974e02b66]
Login

Artifact [c974e02b66]

Artifact c974e02b661b087afef5b0fe561f949504897c81dd0a4742879a881a70004b15:

Ticket change [c974e02b66] - New ticket [057b7dbd3d558921|057b7dbd3d] <i>Const-folding by Expression Compiler borks Ensemble rewrite machinery</i>. by aku on 2021-12-01 21:13:37.
D 2021-12-01T21:13:37.808
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment Wrt\sversion:\sAlready\spresent\sin\s8.6.10.\sPossibly\searlier.\r\n\r\nThis\sstarted\swith\sa\s`this\sis\sweird`\smoment\swhen\sin\sthe\stestsuite\sof\sa\spersonal\sproject\sthe\serror\smessage\sfor\sa\swrong#args\sinvokation\sof\sa\s(oo::util)\sclassmethod\sfor\sa\sclass\sin\san\sensemble\scommand\swas\snot\sof\sthe\sexpected\sform,\swith\sthe\scommand\sproperly\srewritten.\r\n\r\nUsing\sthe\sdemo\sscript\sI\sreduced\sthis\sto\sthe\sinvokation\r\n\r\n\t::x\spoint\svalidate\r\n\r\nwhich\sgot\r\nreported\sas\t\s\swrong\s#\sargs:\sshould\sbe\s"::x::point\svalidate\sx"\r\ninstead\sof\s\t\s\swrong\s#\sargs:\sshould\sbe\s"x\spoint\svalidate\sx"\r\n\r\nI\sfound\sthat\sI\swas\sable\sto\sget\sthe\scorrect\smessage\sby\schanging\sthe\sbody\sof\sthe\sclassmethod\sfrom\r\n\r\n\s\s\s\s\sexpr\s{$z\s<=\s-1}\r\nto\s\s\sexpr\s{$z\s<=\s1}\r\nor\s\s\sexpr\s{$z\s<=\s$z}\r\n\r\nWhile\sI\sinitially\ssuspected\sa\smemory\scorruption\sissue\sboth\sbuiltin\smemory\sdebugging\sand\svalgrind\swere\sclean.\sI\stracked\sthe\sissue\sthen\sdown\sto\s`ExecConstantExprTree`\s(ECET).\r\n\r\nThe\sgood\scases\s(`1`,\s`$z`)\sdo\snot\sinvoke\sit.\sThe\s`-1`\showever\sis\sactually\san\sunary\s`-`\soperating\son\s`1`,\si.e.\ssomething\swhich\scan\sand\sis\sconst-folded.\r\n\r\nAs\spart\sof\sthis\sECET\sessentially\scompiles\sthe\sexpression\sto\sbyte\scode\sand\sthen\sinvokes\s`TclNRExecuteByteCode`\s(TNEBC)\sto\sget\sthe\sconst\sresult\sto\sput\sinto\sthe\souter\sbytecode.\r\n\r\nThe\sproblem\sis,\sthis\stouches\son\sthe\smachinery\sfor\srewriting\sensembles\sin\serror\smessages.\sSpecifically,\swe\sget\sadditional\scalls\sto\s`TclResetRewriteEnsemble`\s(TRRE),\sand\sthis\smesses\swith\sthe\sdata\sstructures\salready\sset\sup\sby\sthe\sdispatcher\sfor\s`x\spoint`\sbefore\scompilation\shappened.\r\n\r\nIn\sthe\sgood\scases\snothing\scan\sbe\sconst\sfolded,\sneither\sTNEBC\snor\sTRRE\sare\scalled,\sthe\srewrite\sdata\sstructures\sare\sleft\sin\sa\sgood\sstate,\sand\sthe\smessage\sis\sas\sexpected.\r\n\r\nFrom\smy\slook\sat\sthings\sI\sbelieve\sthat\sECET\shas\sto\ssave/restore\sthe\srewrite\smachinery\sstate\sbefore\sand\safter\sit\sinvokes\sTNEBC\sto\smake\sthings\sgood\sagain.\r\n\r\nNote:\sWhile\sdebugging\sand\stracing\sthis\sissue\swas\sdone\sfor\sTcl\s8.7a6,\r\ncommit\s`010d43daee`\sthe\sinitial\sissue\swas\sseen\swith\s8.6.10.\r\n\r\nAttached\sa\szip\sfile\scontaining:\r\n\r\n\s\s-\sDemo\sscript\sgood\scase\s`weird-good.tcl`,\splus\soutput\s`GOOD`.\r\n\s\s-\sDemo\sscript\sgood\scase\s`weird-bad.tcl`,\splus\soutput\s`BAD`\r\n\r\n\s\s-\sMy\schanges\sto\scommit\s`010d43daee`\sas\s`TRACE.patch`.\r\n\s\s\s\sI.e.\sprintf's\sadded\sas\sinvestigation\szeroed\sin.\r\n\s\s\s\sPresent\sonly\sto\senable\sreproduction\sof\sthe\slogs,\sif\sneeded.\r\n\r\n\s\s-\s`PushMethodCallFrame`\swas\sfound\sby\sstepping\sthrough\sthings\sin\sgdb\r\n\s\s\s\sbecause\sit\swas\sunclear\swhere\sexactly\sthe\sbogus\sTRRE\scalls\sgot\r\n\s\s\s\striggered.\r\n\r\nThe\simportant\sparts\sof\sGOOD\sand\sBAD\sare\sfound\safter\sthe\smarker\sline\r\n\r\n`________________________________________________________________/////////`\r\n\r\nYou\scan\sclearly\ssee\sthe\sadditional\sTRRE\sin\sthe\sBAD\scase,\sand\show\sit\sgot\scalled\sfrom\sthe\sconst-folding\scode.
J foundin 8.7a6
J is_private 0
J login aku
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter aku
J subsystem 47.\sBytecode\sCompiler
J title Const-folding\sby\sExpression\sCompiler\sborks\sEnsemble\srewrite\smachinery
J type Bug
K 057b7dbd3d558921a9b1f33268035521ec39e6b3
U aku
Z a6cc37c3f483465198a6dc9d3cbdaf53