Skip to content

usort(): exact zend_sort + php_array_user_compare; user-function-name callbacks for usort/array_map - #37726

Merged
PurHur merged 1 commit into
masterfrom
claude/usort-zend
Oct 24, 2026
Merged

PurHur merged 1 commit into
masterfrom
claude/usort-zend

Conversation

@PurHur

@PurHur PurHur commented Oct 24, 2026

Copy link
Copy Markdown
Owner

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

…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>
@PurHur
PurHur merged commit d770843 into master Oct 24, 2026
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.

1 participant