Skip to content

php-in-php: JIT StringPregMatchJit — route preg_* through VmPreg PHP not ~3k-line LLVM/pcre2 (#1492) #9542

Description

@PurHur

Category

php-in-php · php-src-strict

Problem

preg_match(), preg_match_all(), preg_replace(), and friends have VM implementations in ext/standard/, but JIT/AOT emit ~3,000 lines of LLVM in lib/JIT/Builtin/StringPregMatchJit.php calling libpcre2-8 directly (mirrors deleted lib/AOT/runtime/preg_match.c). This duplicates offset capture, error codes, and PREG_* flag semantics — a frequent source of VM/JIT drift (#5289, #6639).

php-src reference

Repro

wc -l lib/JIT/Builtin/StringPregMatchJit.php
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/compliance/cases/stdlib/preg_match_basic.phpt
php bin/jit.php test/compliance/cases/stdlib/preg_match_basic.phpt
php bin/jit.php -r "var_export(preg_match(\"/(\d+)/\", \"abc123\", \$m)); echo PHP_EOL, \$m[1];"
'
Symptom VM JIT today
Capture offsets / PREG_OFFSET_CAPTURE PHP Separate LLVM pcre2 path
preg_last_error() after JIT call shared helper? phpc_preg_last_error global

Scope

Layer Files
PHP helper New ext/standard/PregJitHelper.php wrapping VM preg engine
JIT lib/JIT/Builtin/StringPregMatchJit.php → thin compile + call
FFI Keep single pcre2 binding in PHP/VM layer; delete duplicate LLVM extern decls
Tests Existing preg compliance PHPTs + enum-case subject guards (#3568 family)

Done when

  • Representative preg PHPT suite green on JIT and AOT via PHP helper
  • StringPregMatchJit.php ≤ thin wrapper; PR cites LLVM lines removed
  • preg_last_error() consistent VM/JIT after failed match
  • ./script/ci-fast.sh --filter preg_match 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