如何在Perl中禁用常量折叠? [英] How can I disable constant folding in Perl?
问题描述
给出类似的命令
perl -MO=Deparse -E'use constant FOO => 42; print FOO()'
如何禁用这样的恒定折叠
How can I disable constant folding such that
print 42;
告诉我
print FOO();
之类的.理想情况下,我希望这是一个适用于所有Perl的编译器选项.您可以在perl邮件列表 [perl#97942] [PATCH]添加 -DO
选项以禁用优化,并禁用常量折叠和窥视孔优化器(在使用时). .我尝试了 -DO
,但没有成功.如果该选项不起作用,则我可以采用变通办法,但是可能会出现.
Or the like. Ideally, I would like this to be a compiler option that works for all of Perl. You can see this talked about in this thread on the perl mailing list, [perl #97942] [PATCH] Add -DO
option to disable optimizations and disable constant folding and the peephole optimizer when used.. I tried -DO
and it didn't work. If that option doesn't work, I'm open to workarounds however they may come.
推荐答案
您可以做的一种方法是在常量前面加上&
,
One method you can do is to prefix the constant with &
,
perl -MO=Deparse -E'use constant FOO => 42; print &FOO()'
来自 perldoc perlsub
恒定功能具有()"原型的函数;是内联的潜在候选人.如果优化和常量折叠后的结果是常量或没有其他引用的词法范围标量,则将使用它代替没有
&
进行的函数调用.使用&
进行的呼叫永远不会内联.
Constant Functions Functions with a prototype of "()" are potential candidates for inlining. If the result after optimization and constant folding is either a constant or a lexically-scoped scalar which has no other references, then it will be used in place of function calls made without
&
. Calls made using&
are never inlined.
这篇关于如何在Perl中禁用常量折叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!