Skip to content
Tcl Source Code Artifact [936036b030]
Login

Artifact [936036b030]

Artifact 936036b030dc5f97eb469f2bfe7df74fe5dcfe3e:

Ticket change [936036b030] - New ticket [3017879fffffffff|3017879fff] <i>proc emptyness is cached too aggressively</i>. by a_kovalenko on 2010-06-18 04:24:07.
D 2010-06-18T04:24:07
J assignee msofer
J cmimetype text/plain
J comment There\sis\sone\sknown,\slong-standing\sfeature\sof\sthe\sTCL\sbytecode\ncompiler:\sif\sa\sprocedure\sis\sdefined\swith\sempty\sbody\sand\sall-matching\nparameter\slist\s{args},\sTCL\sdoesn't\scompile\sany\sreal\sprocedure\scall\sfor\nits\scallers.\sIn\sthe\soutput\sof\stcl::unsupported::disassemble,\sit's\svisible\sas\san\sabsence\sof\sinvokeStk1\sinstruction\swhere\san\sempty\sproc\sis\scalled.\n\nThis\soptimization\smay\sbe\sregarded\sas\sa\sspecial\scase\sof\sinlining,\slike\ninlining\san\sempty\sproc\sbody\sand\san\sall-accepting\sargument\ncheck.\sInlining\sdoesn't\splay\swell\swith\sredefinitions\sand\straces,\sbut\nfor\sall\syears\sI\slook\sat\sthat,\sTCL\sdevelopers\scounted\sonly\n_transparent_\soptimizations\sas\sacceptable.\sVarious\s`bytecode\sepoch'\ncounters\striggering\sbytecode\srecompilation\screate\san\sillusion\sthat\nthere\sis\sno\sbyte-compiler\sat\sall,\sit's\sjust\sa\scode\sruns\sfaster.\n\n#\s====\sExample\s1,\sall\sok\s======\nproc\sdo-nothing\s{args}\s{}\nproc\stalk\s{}\s{\n\s\sputs\s"Going\sto\sdo\snothing.."\n\s\sdo-nothing\s1\s2\s3\s4\n\s\sputs\s"Done\snothing\ssuccessfuly."\n}\n#\sHere\swe\smay\stake\sa\slook\sat\s\n\s\sputs\s[tcl::unsupported::disassemble\sproc\stalk]\n#\sno\sinvokeStk1,\sjust\sa\s{push1\s"";\spop}\spair.\n\n#.......later......\nproc\sdo-nothing\s{args}\s{\n\s\sputs\s"You\shave\sto\sdo\s_something_.."\n}\n\nputs\s[tcl::unsupported::disassemble\sproc\stalk]\n#\sAnd\snow\swe\ssee\sinvokeStk1,\sdo-nothing\sis\sreally\scalled\s\ntalk\n#\sand\sdoes\ssomething.\n\nUnfortunately,\sredefining\san\s_imported_\starget\sprocedure\s\nis\snot\snoticed\sin\simporting\snamespaces:\n\nnamespace\seval\sfoo\s{namespace\sexport\s*}\nproc\sfoo::do-nothing\s{args}\s{}\nproc\stalk\s....................\nproc\sfoo::do-nothing\s{args}\s{puts\s"doing\ssomething.."}\ntalk\s;#\ssays\snothing.\s\n#\sImported\scommand\sretained\sthe\sinformation\ssomewhere,\n#\sthat\sits\starget\sis\san\sempty\sproc.\nnamespace\simport\s-force\sfoo::*\n#\sReimporting\swith\s-force\sactually\sdestroys\starget\scommand\n#\sbefore\sreimport,\sand\striggers\sbyte-recompilation\sof\s`talk'\n#\sReimporting\swithout\s-force\sis\sregarded\sas\sa\sno-op,\n#\sas\slong\sas\starget\sis\sthe\ssame\s(and\sas\san\serror\sotherwise).\n\nI\shope\sfor\sa\ssolution\spropagating\scommand\sredefinition\sdown\sto\seach\nimporting\snamespace,\striggering\sbytecode\srecompilation\sthere\s(it's\ncurrently\spossible\son\sthe\sscript\slevel,\straversing\sall\snamespaces\sand\ntheir\simports\sand\sreimporting\sa\sredefined\scommand\swith\s-force).\nOr,\sif\sit\sturns\sout\sto\sbe\stoo\scomplicated,\sI'd\sprefer\sto\ssee\sthis\skind\nof\sbytecode\soptimization\sabandoned.\n\nRedefinition\sof\san\simported\starget\sis\sa\sconvenient\sway\sto\sprovide\ne.g.\sdebugging\sfacilities\s(zero-cost\swhile\sdisabled,\striggering\nrecompilation\swhen\sturned\son,\slow-cost\safterwards).\sIt\sturned\sout\sto\nbe\sa\sfine\stechnique\sto\smanage\sbuilt-in\scommand\sinterception\s(consider\nan\simported\s::puts\sthat\spoints\seither\sto\srenamed\soriginal\s`puts'\sor\sto\na\sredefined,\sredirecting\sversion).\sBut\sfor\sthe\slatter,\sbytecode\snot\ninvalidated\swhen\sappropriate\smay\scause\smore\ssevere\ssemantical\sproblems\nthan\ssimply\snot\srunning\sa\sprocedure\sthat\sused\sto\sbe\sempty.\n\nSeveral\sthings\son\sthe\ssame\ssubject:\n\n1.\sTCL\s8.5.8\srelease\sand\sCVS\shead\sexpose\ssimilar\sbehavior\swith\n\s\s\simported\sproc\sredefinitons;\sthe\sproblem\saffects\sboth.\n\n2.\sIf\sa\scommand\sin\sa\sforeign\snamespace\sis\sresolved\svia\s\n\s\s\snamespace\spath\sand\s_not_\simported,\sthe\sproblem\svanishes:\n\s\s\sall\sbytecode\scalling\sit\sis\sinvalidated\sas\sit's\sredefined\n\s\s\sfrom\s"proc\sname\sargs\s{}"\sto\ssomething\sother,\sand\sback.\n\n3.\sExecution\straces\s(enter,\sleave)\son\san\sempty\sproc\saren't\sinvoked\n\s\s\s(even\sif\sno\snamespace\simport\sis\sinvolved,\si.e.\sin\sthe\ssame\s(root)\s\n\s\s\snamespace).\sHowever,\sI'm\snot\ssure\sthat\srecompiling\scallers\n\s\s\swhen\sa\strace\sis\sadded\sis\sa\sgood\sthing.\n\n4.\sIf\swe\sforget\sabout\sredefining\srenamed\scompilable\sbuilt-ins,\sthe\n\s\s\sonly\stransition\sthat\sis\ssemantically\sproblematic\sis\sthe\sone\sfrom\san\n\s\s\sempty\sproc\sto\sa\snon-empty\sone.\sA\scode\sgenerated\sfor\snon-empty\sproc\n\s\s\s(pushes\s+\sinvokeStk1)\sremains\svalid\sfor\sany\sother\sproc\sor\scommand\n\s\s\sdefinition,\sincluding\sthe\sempty\sone\s(if\sit's\sever\sredefined\sback).\n\n5.\sThere\sis\sa\smissing\sfeature\sin\snamespace\simports\sintrospection:\n\s\s\s[namespace\sorigin]\sspec\screates\san\sillusion\sthat\sall\simports\sof\sa\n\s\s\scommand\sare\slike\sindependent\slinks\sto\sthe\ssame\starget,\sand\sonly\sthe\n\s\s\starget\sis\s`special'\samong\sthem.\sIn\sfact,\simports\sof\sthe\ssame\scommand\n\s\s\smay\sform\sa\scomplicated\sdependency\sgraph,\sand\sfor\snow\sits\sstructure\s\n\s\s\scan't\sbe\sintrospected\son\sscript\slevel\sin\sany\snon-intrusive\sway.\n\s\s\s(of\scourse\sit's\sa\sreason\sfor\sa\sseparate\sreport,\smaybe\sa\sTIP).\n
J foundin obsolete:\s8.6b1.1
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter a_kovalenko
J subsystem 47.\sBytecode\sCompiler
J title proc\semptyness\sis\scached\stoo\saggressively
J type Bug
K 3017879fffffffffffffffffffffffffffffffff
U a_kovalenko
Z 84728520a7f5a17a479c0e6f085eb712