-
Notifications
You must be signed in to change notification settings - Fork 8k
zend_compile: Fix array_map() optimization #21016
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --TEST-- | ||
| array_map(): foreach optimization - dynamic name | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.opt_debug_level=0x20000 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function plus1($x) { | ||
| return $x + 1; | ||
| } | ||
|
|
||
| $array = range(1, 10); | ||
|
|
||
| $plus1 = 'plus1'; | ||
| $foo = array_map($plus1(...), $array); | ||
|
|
||
| var_dump($foo); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| $_main: | ||
| ; (lines=%d, args=0, vars=%d, tmps=%d) | ||
| ; (after optimizer) | ||
| ; %s | ||
| 0000 INIT_FCALL 2 %d string("range") | ||
| 0001 SEND_VAL int(1) 1 | ||
| 0002 SEND_VAL int(10) 2 | ||
| 0003 V3 = DO_ICALL | ||
| 0004 ASSIGN CV0($array) V3 | ||
| 0005 ASSIGN CV1($plus1) string("plus1") | ||
| 0006 TYPE_ASSERT 131079 string("array_map") CV0($array) | ||
| 0007 T3 = INIT_ARRAY 0 (packed) NEXT | ||
| 0008 V4 = FE_RESET_R CV0($array) 0015 | ||
| 0009 T6 = FE_FETCH_R V4 T5 0015 | ||
| 0010 INIT_DYNAMIC_CALL 1 CV1($plus1) | ||
| 0011 SEND_VAL_EX T5 1 | ||
| 0012 V5 = DO_FCALL | ||
| 0013 T3 = ADD_ARRAY_ELEMENT V5 T6 | ||
| 0014 JMP 0009 | ||
| 0015 FE_FREE V4 | ||
| 0016 ASSIGN CV2($foo) T3 | ||
| 0017 INIT_FCALL 1 %d string("var_dump") | ||
| 0018 SEND_VAR CV2($foo) 1 | ||
| 0019 DO_ICALL | ||
| 0020 RETURN int(1) | ||
| LIVE RANGES: | ||
| 3: 0008 - 0016 (tmp/var) | ||
| 4: 0009 - 0015 (loop) | ||
| 5: 0010 - 0011 (tmp/var) | ||
| 6: 0010 - 0013 (tmp/var) | ||
|
|
||
| plus1: | ||
| ; (lines=3, args=1, vars=1, tmps=%d) | ||
| ; (after optimizer) | ||
| ; %s | ||
| 0000 CV0($x) = RECV 1 | ||
| 0001 T1 = ADD CV0($x) int(1) | ||
| 0002 RETURN T1 | ||
| array(10) { | ||
| [0]=> | ||
| int(2) | ||
| [1]=> | ||
| int(3) | ||
| [2]=> | ||
| int(4) | ||
| [3]=> | ||
| int(5) | ||
| [4]=> | ||
| int(6) | ||
| [5]=> | ||
| int(7) | ||
| [6]=> | ||
| int(8) | ||
| [7]=> | ||
| int(9) | ||
| [8]=> | ||
| int(10) | ||
| [9]=> | ||
| int(11) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be unified with zend_is_pipe_optimizable_callable_name IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense and I'm seeing it's already done with Arnaud's PFA PR. I want to avoid the file churn of forward-declaring or moving
zend_is_pipe_optimizable_callable_name()for a temporary thing.