Open
Conversation
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.
RFC: https://wiki.php.net/rfc/partial_function_application_v2
This follows #20717. This implements most of the RFC, except PFAs in constant expressions, and some optimization.
I wanted to split this PR more, but I didn't find a way to achieve this that makes sense.
A partial application is compiled to the usual sequence of function call
opcodes (
INIT_FCALL,SEND_VAR, etc), but the sequence ends with aCALLABLE_CONVERT_PARTIALopcode instead ofDO_FCALL, similarly tofirst class callables. Placeholders are compiled to
SEND_PLACEHOLDERopcodes:SEND_PLACEHOLDERsets the argument slot type to_IS_PLACEHOLDER.CALLABLE_CONVERT_PARTIALuses the information available on the stack tocreate a Closure and return it, consuming the stack frame in the process
like an internal function call.
We create the Closure by generating the relevant AST and compiling it to an
op_array.
The op_array is cached in the Opcache SHM and inline caches. The SHM key is prefixed with
pfa://to avoid any collision with actual files. When Opcache is disabled, we cache PFA op_arrays a global hash table. This is mainly useful for polymorphic PFAs, as the inline cache stores only a single entry.