Repository navigation
usort(): exact zend_sort + php_array_user_compare; user-function-name callbacks for usort/array_map - #37726
Merged
Conversation
…nction name callbacks
usort() on a packed list was a bubble sort capped at n² passes that read the
comparator result by sign (0.5 sorted as "greater"; php-src truncates via
zval_get_long) and ignored php-src's bool-return protocol. Now:
- UsortPackedLlvm on ZendSortLlvm with php_array_user_compare_unstable:
zval_get_long + ZEND_NORMALIZE_BOOL, the once-per-call E_DEPRECATED for a
bool return, `false` retried with swapped operands, RETURN_STABLE_SORT
tiebreak. Same comparator call sequence as php-src.
- usort($a, 'userFunction') and array_map('userFunction', ...) now compile
(were "callback form not lowerable" / "not a registered internal
function"): UserCallableResolver resolves a compile-time string naming a
user function to its Native call.
- ZendSortLlvm: inline-comparator mode for comparators that reference the
caller's frame (closures bind captured variables to caller stack slots, so
they cannot run in a separate function); comparator emission is scoped
with scopeLoweringToFunction (lazily materialized helpers restored the
insert point into the wrong function).
Known, pre-existing (also on master): closures with use(&$x) invoked through
NestedClosureInvoke print spurious "Undefined variable" warnings.
Gates: make check OK; parallel AOT differential sweep 379 ok / 8 fail, failing
set identical to master; new case usort_zend_parity matches Zend (3 runs);
verified with PHP_COMPILER_LLVM_ASSERT=1 (module verifier).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
See commit message. Gates: make check OK; AOT differential sweep failing set identical to master (379 ok / 8 fail); module verifier clean on new tests. Not run: compliance suites.
🤖 Generated with Claude Code