Skip to content

php-in-php: JIT StringVersionCompareJit — route version_compare() through VmInfo PHP not ~800-line LLVM (#1492) #9813

Description

@PurHur

Category

php-in-php · php-src-strict

Problem

version_compare() is implemented in PHP (ext/standard/version_compare.php, VmInfo::version_compare()), but JIT/AOT still emit lib/JIT/Builtin/StringVersionCompareJit.php (~800 lines) of LLVM duplicating php-src php_version_compare tokenization (dev/alpha/beta/RC/pl/patch rules).

Maintainers already deleted phpc_version_compare.c; the LLVM class is the remaining duplicate surface.

php-src reference

Repro

Save as test/repro/maintainer_version_compare_jit.php:

<?php
$cases = [
    ['1.0.0', '1.0.1', '<', true],
    ['1.0.0', '1.0.0', '=', true],
    ['1.0.0-dev', '1.0.0', '<', true],
    ['8.2.0', '8.10.0', '<', true],
];
foreach ($cases as [$a, $b, $op, $want]) {
    $got = version_compare($a, $b, $op);
    echo "$a $op $b => ", var_export($got, true), $got === $want ? " OK\n" : " FAIL\n";
}
echo version_compare('1.2', '1.10'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_version_compare_jit.php
php bin/jit.php test/repro/maintainer_version_compare_jit.php
'

Scope

Path Work
ext/standard/VersionCompareJitHelper.php (or reuse JitInfo.php) Callable bridge from JIT
lib/JIT/Builtin/StringVersionCompareJit.php Replace LLVM parser with helper call
lib/JIT/Builtin/JitInfo.php Ensure VM/JIT/AOT share VmInfo::version_compare()
Tests extend repro + compliance version_compare_jit.phpt

Done when

  • JIT/AOT repro matches VM/Zend for table above + operator-less int return
  • StringVersionCompareJit.php reduced to thin bridge (−700+ LLVM lines)
  • Invalid operator still throws ValueError via PHP SSOT
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter version_compare' green

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions