Author ncoghlan
Recipients Jeremy.Hylton, Trundle, alex, benjamin.peterson, brett.cannon, daniel.urban, dmalcolm, eltoder, eric.snow, georg.brandl, gregory.p.smith, jcon, mark.dickinson, meador.inge, nadeem.vawda, ncoghlan, pitrou, rhettinger, santoso.wijaya, techtonik, terry.reedy, vstinner
Date 2012-09-06.00:11:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346890302.71.0.713674854399.issue11549@psf.upfronthosting.co.za>
In-reply-to
Content
All of the optimisations that assume globals haven't been shadowed or rebound are invalid in the general case.

E.g. print(1.5) and print("1.5") are valid for *our* print function, but we technically have no idea if they're equivalent in user code.

In short, if it involves a name lookup and that name isn't reserved to the compiler (e.g. __debug__) then no, you're not allowed to optimise it at compile time if you wish to remain compliant with the language spec. Method calls on literals are always fair game, though (e.g. you could optimise "a b c".split())

Any stdlib AST optimiser would need to be substantially more conservative by default.
History
Date User Action Args
2012-09-06 00:11:42ncoghlansetrecipients: + ncoghlan, brett.cannon, georg.brandl, rhettinger, terry.reedy, gregory.p.smith, mark.dickinson, pitrou, vstinner, techtonik, nadeem.vawda, benjamin.peterson, alex, Trundle, dmalcolm, meador.inge, daniel.urban, Jeremy.Hylton, santoso.wijaya, eltoder, eric.snow, jcon
2012-09-06 00:11:42ncoghlansetmessageid: <1346890302.71.0.713674854399.issue11549@psf.upfronthosting.co.za>
2012-09-06 00:11:42ncoghlanlinkissue11549 messages
2012-09-06 00:11:41ncoghlancreate