Skip to content

Stdlib: preg_split() $limit / $flags — JIT/AOT lowering (phase 2 of #3639) #4078

Closed

Description

@PurHur

Category

stdlib / ext/pcre

Problem

preg_split() VM supports 2–4 arguments including $limit and PREG_SPLIT_* flags (#3639 closed for VM/constants). JIT/AOT still reject any call with $limit or $flags (preg_split.php throws; JitPregSplit is two-arg only).

php-src reference

Repro

test/repro-maintainer/preg_split_flags.php:

<?php
declare(strict_types=1);
$parts = preg_split('/(\d+)/', 'a1b2c', -1, PREG_SPLIT_DELIM_CAPTURE);
echo count($parts), ':', implode('|', $parts), "\n";
./script/docker-exec.sh -- bash -lc 'php test/repro-maintainer/preg_split_flags.php'
# 5:a|1|b|2|c

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro-maintainer/preg_split_flags.php'
# 5:a|1|b|2|c

./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro-maintainer/preg_split_flags.php'
# LogicException: limit and flags not supported in JIT/AOT (issue #3639)

Scope

Module Path
JIT/AOT ext/standard/preg_split.php, ext/standard/JitPregSplit.php, lib/AOT/runtime/ PCRE split
Tests extend test/compliance/cases/stdlib/preg_split_*.phpt to JIT/AOT

Done when

  • $limit and PREG_SPLIT_DELIM_CAPTURE / PREG_SPLIT_OFFSET_CAPTURE / PREG_SPLIT_NO_EMPTY match Zend on JIT and AOT
  • Existing two-arg JIT/AOT tests still pass

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 1, 2026
  2. PurHur commented on Jun 3, 2026

    @PurHur
    OwnerAuthor

    Implementation-ready spec (parity architect refresh)

    Repro file (add to repo)

    Create test/repro-maintainer/preg_split_flags.php:

    <?php
    declare(strict_types=1);
    $parts = preg_split('/(\d+)/', 'a1b2c', -1, PREG_SPLIT_DELIM_CAPTURE);
    echo count($parts), ':', implode('|', $parts), "\n";

    Commands

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php test/repro-maintainer/preg_split_flags.php
    php bin/vm.php test/repro-maintainer/preg_split_flags.php
    php bin/jit.php test/repro-maintainer/preg_split_flags.php
    '
    Runtime Expected output
    Zend / VM `5:a
    JIT (gap) LogicException — limit/flags not lowered

    php-src reference (flags)

    • PREG_SPLIT_DELIM_CAPTURE — ext/pcre/php_pcre.c php_pcre_split_impl
    • Flag constants: ext/standard/basic_functions.c

    Scope files

    • ext/standard/JitPregSplit.php — pass limit + flags to native/host split
    • ext/standard/preg_split.php — remove JIT throw for argc>2
    • lib/JIT/Builtin/ or __compiler_preg_split bridge

    Done when (expanded)

    • Repro green on bin/jit.php and AOT fixture
    • PREG_SPLIT_NO_EMPTY and PREG_SPLIT_OFFSET_CAPTURE have at least one PHPT each (subset OK if documented)
    • ./script/ci-fast.sh --filter preg_split green
    • Two-arg fast path unchanged (regression)

    Parent VM work: #3639 (closed).

  3. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  4. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    Progress (#7977)

    JIT + VM green for issue repro (`PREG_SPLIT_DELIM_CAPTURE`, `NO_EMPTY`, `OFFSET_CAPTURE`, limit).

    ```bash
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter preg_split'

    12/14 pass — VM + JIT compliance including new preg_split_flags_jit.phpt

    ```

    AOT: `bin/compile.php` still fails LLVM module verification for preg_split (also on master for 2-arg fixture). PR includes AOT fixture + slice CFG fixes toward that; merge held until `AotTest` preg_split cases compile.

    #7977

  5. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run (AOT LLVM verify fix for preg_split + preg runtime helpers)

  6. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    Merged via #7977.

    Verification (all green):

    • vendor/bin/phpunit --filter preg_split — 14/14 (VM + JIT + AOT)
    • AOT repro: preg_split('/(\d+)/', 'a1b2c', -1, PREG_SPLIT_DELIM_CAPTURE) → 5:a|1|b|2|c
    • Collateral: AotTest preg_match fixture now compiles (LLVM null-check/memcpy signature fix in StringPregMatchJit)
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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions