Skip to content

Make OP_DEFINED eligible for constant folding #23349

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

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from

Conversation

richardleach
Copy link
Contributor

@richardleach richardleach commented Jun 1, 2025

Prior to this, the condition in the following example did not fold:

'use constant ONE => 1; my $x = (defined(ONE)) ? 1 : 0;'

With this commit, the final op tree produced for the above is just:

5  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter v ->2
2     <;> nextstate(main 193 -e:1) v:%,us,{,fea=15 ->3
4     <1> padsv_store[$x:193,194] vKS/LVINTRO ->5
3        <$> const[IV 1] s/FOLD ->4
-        <0> ex-padsv sRM*/LVINTRO ->4

Closes #16266


  • This seems like a bit of an edge case, so I don't think it needs a perldelta entry.

@richardleach richardleach added the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jun 1, 2025
@tonycoz
Copy link
Contributor

tonycoz commented Jun 4, 2025

The op tree in the commit message doesn't match the perl code (where did $x come from?)

Prior to this, the condition in the following example did not fold:

    'use constant ONE => 1; my $x = (defined(ONE)) ? 1 : 0'

With this commit, the final op tree produced for the above is just:

    5  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter v ->2
    2     <;> nextstate(main 193 -e:1) v:%,us,{,fea=15 ->3
    4     <1> padsv_store[$x:193,194] vKS/LVINTRO ->5
    3        <$> const[IV 1] s/FOLD ->4
    -        <0> ex-padsv sRM*/LVINTRO ->4
@richardleach
Copy link
Contributor Author

The op tree in the commit message doesn't match the perl code (where did $x come from?)

Sorry about that. I changed examples a couple of times while writing. Now updated to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defer-next-dev This PR should not be merged yet, but await the next development cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

defined operator not constant folded
2 participants