<i>cmd literal sharing vs. cmd resolvers</i>.
by
.
D 2011-10-04T16:15:17
J assignee msofer
J cmimetype text/plain
J comment When\stesting\sour\sTcl's\sper-interp\sresolvers,\sin\sparticular\sfor\nresolving\scommands,\sagainst\s8.6b2\s(and\sthe\scurrent\ntrunk,\sas\sof\s20111004),\swe\sfound\san\sunwanted\sinteraction\sbetween\n"global"\sCmdName\sobj\ssharing\s(i.e.\scmd\sliterals)\sand\sthe\scmd\sresolver\ninfrastructure.\n\nIn\sshort:\sUsing\scommand\sresolvers\scan\seasily\slead\sto\ssituations\sin\nwhich\sCmdName\sobjs\sare\seffectively\sshared\sbetween\sBC-compiled\sscripts\n(procs,\s[namespace\seval])\sfor\sthe\sscope\sof\sa\sgiven\snamespace\s(global\nand\snon-global\sNS\salike)\swhile\stheir\scommand\sreferences\sturn\sout\nobsolete.\sAn\sinvalidation\sof\sthe\sCmdName\sobjs\sintrep\s(ResolvedCmdName)\nis\snot\sperformed.\sThe\somission\sof\sthe\sinvalidation\sis\sdue\sto\sseveral\nreasons,\sdepending\son\sthe\sBC\scompilation/execution\scontext.\sFor\ninstance,\sfor\sinstantly\scompiled\sscripts\s([namespace\seval])\swe\shit\nTclSetCmdNameObj()\swhich\ssimply\sreturns\swithout\stouching\s(existing)\sCmdName\nobj\sintreps.\n\nA\scondensed\sexample:\n\nConsider\sa\scmd\sresolver\swhich\sbinds\s"z"\sto\s::y\swhen\s"z"\sis\sbeing\nresolved\sin\sthe\scontext\sof\sthe\sproc\s::x\s(and\sin\sthis\sscope\sonly):\n\s\nproc\s::y\s{}\s{\sreturn\sY\s};\s#\sthe\sresolver-specific\sresolution\starget\n\s\s\nproc\s::x\s{}\s{\n\s\s\s\sz;\s#\sthe\stcl\sword\sbeing\sturned\sinto\sa\sCmdName\sobj\sand\sshared\sas\scmd\sliteral\safter\shaving\sbeen\sBC-compiled\n\s\s}\n\nThis\scmd\sresolution\sis\sperformed\sduring\sBC\scompilation\sof\s::x.\sThe\scmd\n(::y)\sreturn\sby\sthe\scmd\sresolver\sis\sreferenced\sby\sthe\sintrep\sof\sa\nCmdName\sobj\s"z"\sfor\sthe\sNS\sscope\sof\sthe\s[namespace\scurrent]\sduring\ncompilation\s("::").\sNext\stime,\sa\sscript\sis\scompiled\sin\sthis\ssharing\ncontext,\sthis\swill\swork\s(unexpectedly?):\n\nnamespace\seval\s::\s{\n\s\s\s\sz;\s#\sreturns\s"Y"?!\n}\n\nHowever,\swhen\srequesting\sa\sdifferent\scmd\sto\sbecome\savailable\sunder\sthe\ntoken\s"z",\se.g.,\s::ns1::z:\n\s\s\nnamespace\seval\s::ns1\s{\n\s\s\s\sproc\sz\s{}\s{\sreturn\sZ\s}\n\s\s\s\snamespace\sexport\sz\n\s\s}\n\s\s\n...\sby\se.g.\s[namespace\simport]'ing,\sthis\swon't\sshow\sany\seffect\son\sthe\sshared\scmd\sliteral:\n\n\snamespace\seval\s::\s{\n\s\s\s\snamespace\simport\s::ns1::z\n\s\s\s\sz;\s#\sstill\sreturns\s"Y",\sthough\sexpecting\s"Z"\n\s\s}\n\s\nOne\scan\salter\sthis\s(mis-)behaviour\sat\svarious\sspots,\sfor\sinstance,\sby\ncausing\sthe\scompiled\sscript\sto\somit\scmd\sliteral\ssharing\sfor\sthe\sgiven\ntoken\s"z":\n\n\snamespace\seval\s::\s{\n\s\s\s\sproc\sz\s{}\s{\sreturn\sZ\s}\n\s\s\s\sz;\s#\syields\s"Z",\sas\sexpected\n\s\s}\n\nThis\s"works"\ssimply\sbecause\sthere\sis\sno\scmdname\sobj\semitted.\sChanging\nthe\sscript\sback\sto\susing\sa\squalified\stoken\s"::z"\sgives\sus\sthe\sunwanted\nbehavior\sagain:\n\n\snamespace\seval\s::\s{\n\s\s\s\sproc\s::z\s{}\s{\sreturn\sZ\s}\n\s\s\s\sz;\s#\syields\s"Y",\snot\s"Z"\n\s\s}\n\n(This\sexample\sis\scontained\sas\sa\stcltest\s(plus\scomments)\slit-1.1\sby\sthe\spatch\sattached)\n\nIn\sour\sreading,\scmd\sresolvers\sare\scapable\sof\scausing\syet\sanother\sform\nof\s"command\sshadowing"\sat\sthe\slevel\sof\scmd\sliterals,\sgiven\sthe\naggressive\scmd\sliteral\ssharing\sin\sTcl\s8.6.\sCommand\sresolution\sthrough\ncmd\sresolvers\sin\sTcl_FindCommand\s&\sfriends\sgives\sbirth\sto\scmd\sliterals\nwhich\ssilently\s"import"\scommands\sfrom\salien\scontexts\s(resolver\nspecific)\sinto\sa\snamespace\scontext\swithout\s"registering"\sthe\scommands\nin\sa\smanner\sto\smake\sthem\svisible\sto\sthe\svarious\sinvalidation\nroutines.\sCommand\sepochs\sdo\snot\scome\sinto\splay\seither\sbecause\sthe\n"resolver-imported"\scommand\smight\ssimply\snot\sbe\stouched\sitself\sor\nintrep\sinvalidation\sis\snever\striggered\n(TclSetCmdNameObj()).\sNS-specific\sinvalidation\s(cmdRefEpoch)\ssimply\ndoes\snot\sapply\sbecause\sliterals\sare\snot\spart\sof\sany\sinvalidation\nscheme,\se.g.,\sTclResetShadowedCmdRefs,\sNS\spath\sinvalidation\setc.\sFrom\nwithin\sthe\scmd\sresolvers,\sthere\sis\sno\sway\sof\sinterfering\s(in\sour\nunderstanding).\n\nThe\spatch\sattached\sto\sthis\sbug\sreport\sfeatures\sthe\sfollowing:\n\na)\sA\sminimal\sinfrastructure\sfor\stesting\sresolvers\s(tclTest.c):\n[testinterpresolver\sup|down]\n\nb)\sA\scollection\s(resolvers.test)\sof\scharacteristic\stcltests\swhich\sshow\nthe\sissue\sin\svarious\ssettings\s([namespace\simport],\s[interp\salias],\n[interp\sexpose],\s[proc]).\sSee\stcltest\slit-1.1\sfor\sa\sstep-by-step\nexplanation\sof\sa\sprototypical\sscenario\n\nc)\sFinally,\sa\ssuggested\spatch\saround\sa\snewly\sintroduced\nTclInvalidateCmdLiteral()\shelper.\sWhile\sthis\shelper\saddresses\sthe\nissue\ssufficiently\sas\sindicated\sby\sthe\stcltest\scollection,\sthere\smight\scertainly\nbe\salternative\sstrategies.\sThe\sprimary\spurpose\sof\sthis\spatch\sis\sto\npoint\syou\sinto\sthe\sright\sdirection.\sTclInvalidateCmdLiteral()\ssimply\nqueries\sthe\sliteral\stables\sfor\scandidates\susing\sthe\sTcl_CreateLiteral\nAPI\sand,\sif\sfound,\sresets\sthe\sintrep\safter\scritical\soperations\ssuch\nas\se.g.\s[namespace\simport].\n\nd)\sIncluded\sis\salso\sa\stcltest\scovering\s(the\sunrelated)\sbug\s#3383616\n\nStefan\sSobernig\nGustaf\sNeumann
J foundin obsolete:\s8.6b2
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter foxcruiser
J subsystem 47.\sBytecode\sCompiler
J title cmd\sliteral\ssharing\svs.\scmd\sresolvers
J type Bug
K 3418547fffffffffffffffffffffffffffffffff
U foxcruiser
Z 4d287a85230c2e3e9895910ae1ebc4ca