Repository navigation
Fix GH-25379: Preserve array_map() semantics in foreach optimization - #25546
Open
prateekbhujel wants to merge 1 commit into
Open
prateekbhujel wants to merge 1 commit into
prateekbhujel wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the compiler regressions reported in #25379 inside
zend_compile_func_array_map():zend_partial_apply()/zend_is_pipe_optimizable_callable_name()checks (e.g.assert, multiple placeholders, named args before a variadic placeholder) before compilingclass_nodeandfunc_node.arrayargument is anIS_CONSTnon-array. Whenclass_nodeorfunc_nodealready emitted runtime opcodes intoIS_TMP_VAR, fall back in place to a regulararray_map()call reusing those already-evaluated nodes instead of emitting orphaned opcodes/TMPs and compiling the callee twice.ARG_MUST_BE_SENT_BY_REFfor the placeholder parameter (including variadic by-ref parameters and named placeholders), so calls likeinc(...),sort(...), andinc2(?, 2)continue to emit a warning and wrap the value instead of throwingError: Argument could not be passed by reference.ZEND_ACC2_FORBID_DYN_CALLS):ZEND_ACC2_FORBID_DYN_CALLS(such asextract,compact,func_get_arg,func_get_args,func_num_args, andget_defined_vars, including unqualified calls in namespaces that fall back to global internal functions), preservingCannot call X() dynamicallyinstead of running in the caller scope.Note on #25379 part 3 (late/empty-array callback validation such as
nope(...)on[]): intentionally left untouched here, as pre-validating unknown callbacks before the loop would break the closure-elision opcodes tested byarray_map_foreach_optimization_006.phpt/012.phpt, and bailing out on unknown classes/functions at compile time would disable the optimization for autoloaded static methods and functions declared later in a file.Refs GH-25379.
Local debug build checks:
Zend/tests/array_map_foreach_optimization_gh25379.phptpasses with bothopcache.enable_cli=0andopcache.enable_cli=1(0 memory leaks).ext/opcache/tests/andext/standard/tests/array/: 1,845 passed, 0 failed (58 skipped, 2 expected fail).Zend/tests/: 5,562 passed, 178 skipped, 1 expected fail (onlyZend/tests/new_oom.phptfailed locally due to an unquoted space in the local checkout path).