Skip to content

php-in-php: preg_match() JIT — delete preg_match.c (~112 lines), lower from ext/standard/VmPreg.php #5289

Description

@PurHur

Category

php-in-php | stdlib | bootstrap

Problem

JIT (and AOT) currently reuse a hand-written native regex runtime:

  • lib/AOT/runtime/preg_match.c

That keeps PCRE semantics in C and blocks the PHP-in-PHP goal (#1492). This repo already has a PHP implementation surface in ext/standard/:

  • ext/standard/VmPreg.php
  • ext/standard/VmPregNative.php (FFI to libpcre2-8)

We should delete the C runtime helper (or shrink it to a minimal ABI shim) and lower preg_match()/friends via the PHP VM semantics so VM/JIT/AOT share one source of truth.

php-src reference

  • ext/pcre/php_pcre.c — preg_match, preg_match_all, preg_replace, preg_replace_callback, preg_last_error, preg_last_error_msg

Repro

test/repro-maintainer/preg_match_basic.php:

<?php
var_dump(preg_match('/a./', 'abc', $m));
var_export($m);
echo "\n";

Run:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/preg_match_basic.php
php bin/vm.php test/repro-maintainer/preg_match_basic.php
php bin/jit.php test/repro-maintainer/preg_match_basic.php
'

Expected (Zend):

int(1)
array (
  0 => 'ab',
)

Scope (this repo)

  • Delete or shrink: lib/AOT/runtime/preg_match.c
  • VM SSOT:
    • ext/standard/VmPreg.php
    • ext/standard/VmPregNative.php
  • JIT builtin lowering: lib/JIT/Builtin/StringPregMatch.php should link/lower to the PHP path (no new C logic).
  • Add compliance tests:
    • test/compliance/cases/stdlib/preg_match_basic.phpt
    • test/compliance/cases/stdlib/preg_last_error_msg.phpt

Done when

  • JIT/AOT no longer depends on preg_match.c for semantics (file removed or reduced to a minimal ABI shim)
  • Repro output matches Zend on VM and JIT/AOT
  • ./script/ci-fast.sh --filter preg_match is green
  • Implementing PR notes C runtime reduction (lines removed / symbols deleted)

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 / 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