Skip to content

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.

@richardleach richardleach removed the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jul 4, 2025
@richardleach
Copy link
Contributor Author

@tonycoz - am I okay to merge this?

@richardleach richardleach merged commit cb83733 into Perl:blead Jul 14, 2025
33 checks passed
@richardleach richardleach deleted the fold_defined branch July 14, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defined operator not constant folded

2 participants