Skip to content

Optimise away LIST/ex-LIST trees containing one item #23448

@richardleach

Description

@richardleach

Description
In scalar context, a (possibly-nulled) LIST OP may effectively contain a single item.
It seems like this container OP and redundant KID OPs could be removed entirely.

For example, my $x = (1,2,3) leaves Perl_scalar as:

2     <;> nextstate(main 2 -e:1) v:%,us,{,fea=15 ->3
7     <2> sassign vKS/2 ->8
5        <@> list sKP ->6
3           <0> pushmark v ->4
-           <0> ex-const v ->-
-           <0> ex-const v ->4
4           <$> const[IV 3] s ->5
6        <0> padsv[$x:2,3] sRM*/LVINTRO ->7

Could this be optimised to:

2     <;> nextstate(main 2 -e:1) v:%,us,{,fea=15 ->3
5     <2> sassign vKS/2 ->6
3        <$> const[IV 3] s ->4
4        <0> padsv[$x:2,3] sRM*/LVINTRO ->5

See also #23447.

Steps to Reproduce
perl -MO=Concise -E 'my $x = (1,2,3)'

Perl configuration
5.43.0 and previous.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions