Skip to content

php-in-php: preg_replace_callback()/preg_split() JIT — delete LLVM stubs, wire real lowering (ext/pcre/php_pcre.c) #6639

Description

@PurHur

Category

php-in-php · stdlib · JIT/AOT regression

Problem

VM preg_replace_callback() / preg_split() work via ext/standard/VmPreg.php, but MCJIT/AOT still emit stub bodies for __compiler_preg_replace_callback and __compiler_preg_split in lib/JIT/Builtin/StringPregMatchJit.php (returns NULL / BAD_REGEX). Closed #1177 / #1178 covered initial wiring; stubs remain.

<?php
function cb(array $m): string { return strtoupper($m[0]); }
var_export(preg_replace_callback('/a/', 'cb', 'aba'));
// Zend: aBa

php-src reference

Repro (JIT)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/jit.php -r "
function cb(array \$m): string { return strtoupper(\$m[0]); }
echo preg_replace_callback(\"/a/\", \"cb\", \"aba\"), \"\n\";
"'

Observed: NULL / empty or VM fallback depending on probe flags.
Expected: aBa under MCJIT when JIT path selected.

preg_split with PREG_SPLIT_NO_EMPTY similarly fails in JIT when __compiler_preg_split stub is linked.

Scope (this repo)

Path Work
lib/JIT/Builtin/StringPregMatchJit.php Replace emitReplaceCallbackStub / emitSplitStub with real PCRE2 lowering (mirror emitReplace / emitMatch)
ext/standard/JitPregReplaceCallback.php, JitPregSplit.php Align callback pointer ABI with VM VmPregReplaceCallback
ext/standard/preg_*.php Remove "not supported in JIT/AOT" guards when lowering is real
Tests test/compliance/cases/stdlib/preg_replace_callback_jit.phpt, preg_split_jit.phpt

PHP-in-PHP: keep PCRE logic in PHP-generated LLVM + thin libpcre2 ABI; do not grow runtime/*.c.

Done when

Strictness

php-src-strict for user scripts; enum-case operands per #5999.

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 6, 2026
  2. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#6639: replace preg_replace_callback/preg_split LLVM stubs in StringPregMatchJit with real lowering from JitPregReplaceCallback/JitPregSplit).

  3. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    Unclaiming #6639 this run: picked #5303 closure (phpc_weakref.c migration already merged #5684). #6639 handoff: fix __compiler_preg_replace_callback ABI (declareFunction param order vs JitPregReplaceCallback), replace emitReplaceCallbackStub/emitSplitStub with real LLVM from emitReplaceInternal pattern; AOT preg_replace_callback.phpt currently fails compile with "runtime callback type is not a function pointer".

  4. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#6639: replace preg_replace_callback/preg_split LLVM stubs, fix __compiler_preg_replace_callback ABI param order).

  5. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #7662.

    PHP path: StringPregMatchJit::emitReplaceCallback + emitSplit replace BAD_REGEX/NULL stubs; __compiler_preg_replace_callback ABI fixed to (pattern, subject, callback fn*); indirect callback via LLVMBuildCall2.

    Verification (VM+JIT green):

    • vendor/bin/phpunit test/unit/JIT/StringPregMatchRuntimeStandaloneTest.php — OK
    • --filter preg_replace_callback_jit / preg_split_jit / stdlib/preg_replace_callback — OK

    Note: AOT preg_replace_callback/preg_split fixtures still hit pre-existing standalone module verify during bin/compile.php (reproduces on master); handoff for a follow-up AOT link gate.

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 / JITarea:vmVirtual machineenhancementNew 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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions