The version of perl that is executing any particular piece of code is
really expected to remain constant. I think that is fairly
uncontentious ;)
However, because the value is only available in scalar variables like
$] and $^V, it means that conditional expressions that one would hope
should be "constant" are not in fact subject to const-folding. For
example:
$ perl -MO=Concise -E 'say "Old" if $] < 5.014'
a <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter v ->2
2 <;> nextstate(main 2 -e:1) v:%,us,{,fea=15 ->3
- <1> null vK/1 ->a
6 <|> and(other->7) vK/1 ->a
5 <2> lt sK/2 ->6
- <1> ex-rv2sv sK/1 ->4
3 <#> gvsv[*]] s ->4
4 <$> const[NV 5.01] s ->5
9 <@> say vK ->a
7 <0> pushmark s ->8
8 <$> const[PV "Old"] s ->9
and similar for `... if $^V lt v5.14`
I would like to propose a new double-under special symbol containing
the same value, that expands to a real constant in the code; and
therefore such a conditional expression would const-fold correctly.
Hypothetically then
perl ... -E 'say "Old" if __PERLVER__ lt v5.14'
would compile to either nothing at all, or a simple unconditional say()
statement.
Alternative ideas include: recognising that $^V or $] are readonly
during the peephole optimiser and inlining the values, but.. eugh.
That's a mess that easily leads to craziness...
--
Paul "LeoNerd" Evans
leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
really expected to remain constant. I think that is fairly
uncontentious ;)
However, because the value is only available in scalar variables like
$] and $^V, it means that conditional expressions that one would hope
should be "constant" are not in fact subject to const-folding. For
example:
$ perl -MO=Concise -E 'say "Old" if $] < 5.014'
a <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter v ->2
2 <;> nextstate(main 2 -e:1) v:%,us,{,fea=15 ->3
- <1> null vK/1 ->a
6 <|> and(other->7) vK/1 ->a
5 <2> lt sK/2 ->6
- <1> ex-rv2sv sK/1 ->4
3 <#> gvsv[*]] s ->4
4 <$> const[NV 5.01] s ->5
9 <@> say vK ->a
7 <0> pushmark s ->8
8 <$> const[PV "Old"] s ->9
and similar for `... if $^V lt v5.14`
I would like to propose a new double-under special symbol containing
the same value, that expands to a real constant in the code; and
therefore such a conditional expression would const-fold correctly.
Hypothetically then
perl ... -E 'say "Old" if __PERLVER__ lt v5.14'
would compile to either nothing at all, or a simple unconditional say()
statement.
Alternative ideas include: recognising that $^V or $] are readonly
during the peephole optimiser and inlining the values, but.. eugh.
That's a mess that easily leads to craziness...
--
Paul "LeoNerd" Evans
leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/