Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perl_op_convert_list: Avoid unnecessary processing of CONST OPs #22116

Merged
merged 1 commit into from
Jun 10, 2024

Commits on Apr 3, 2024

  1. Perl_op_convert_list: No unnecessary processing of unfolded CONSTs

    When Perl_op_convert_list is called to stringify a CONST OP, but the
    `op_folded` flag has not been passed in, a fair amount of activity
    occurs before the function returns the original CONST OP unchanged.
    After this commit, the CONST OP is returned directly.
    
    For example, prior to this commit, given the statement 'print "2\n',
    the function is passed a simple CONST OP:
    
    1    const SVOP(0x55c99432c0b8) ===> [SELF]
         PARENT ===> [0x0]
         FLAGS = (SCALAR,SLABBED)
         SV = PV("2\n"\0)
    
    List context is forced upon it to yield:
    
    2    list LISTOP(0x55c99432c048) ===> [0x0]
         PARENT ===> [0x0]
         FLAGS = (UNKNOWN,KIDS,SLABBED)
         |
    3    +--pushmark OP(0x55c99432c088) ===> [SELF]
         |   FLAGS = (SCALAR,SLABBED,MORESIB)
         |
    1    +--const SVOP(0x55c99432c0b8) ===> [SELF]
             FLAGS = (SCALAR,SLABBED)
             SV = PV("2\n"\0)
    
    The pushmark is nullified and the parent type set:
    
    2    stringify LISTOP(0x55c99432c048) ===> [0x0]
         PARENT ===> [0x0]
         FLAGS = (UNKNOWN,KIDS,SLABBED)
         |
    3    +--null (ex-pushmark) OP(0x55c99432c088) ===> [SELF]
         |   FLAGS = (SCALAR,SLABBED,MORESIB)
         |
    1    +--const SVOP(0x55c99432c0b8) ===> [SELF]
             FLAGS = (SCALAR,SLABBED)
             SV = PV("2\n"\0)
    
    CHECKOP sets the number of non-null KIDS for the stringify:
    
    2    stringify LISTOP(0x55c99432c048) ===> [0x0]
         PARENT ===> [0x0]
         FLAGS = (UNKNOWN,KIDS,SLABBED)
         PRIVATE = (0x1)
         |
    3    +--null (ex-pushmark) OP(0x55c99432c088) ===> [SELF]
         |   FLAGS = (SCALAR,SLABBED,MORESIB)
         |
    1    +--const SVOP(0x55c99432c0b8) ===> [SELF]
             FLAGS = (SCALAR,SLABBED)
             SV = PV("2\n"\0)
    
    Then it is constant folded back to:
    
    1    const SVOP(0x55c99432c0b8) ===> [SELF]
         PARENT ===> [0x0]
         FLAGS = (SCALAR,SLABBED)
         SV = PV("2\n"\0)
    richardleach committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    4c49da4 View commit details
    Browse the repository at this point in the history