Skip to content

php-in-php: json_decode() — delete phpc_json_decode.c (~649 lines), VM+JIT+AOT from ext/standard/VmJson*.php #6202

Closed

Description

@PurHur

Category

php-in-php | bootstrap

Problem

json_decode() still depends on a hand-written C parser in lib/AOT/runtime/phpc_json_decode.c (~649 lines) for JIT/AOT link, while the VM path already has PHP scanners/validators (ext/standard/VmJsonScanner.php, VmJsonValidate.php). This blocks self-host (#1492): the native binary must not ship a duplicate JSON parser in C when PHP lowering is sufficient.

PHP-in-PHP first: port decode semantics into ext/standard/ + JIT lowering; delete or shrink the C file to a thin ABI trampoline (if any remains).

php-src reference

Repro (C runtime still linked today)

./script/docker-exec.sh -- bash -lc 'wc -l lib/AOT/runtime/phpc_json_decode.c; rg -l phpc_json_decode lib/AOT/Linker.php'

lib/AOT/Linker.php lists phpc_json_decode.c; ext/standard/VmJsonScanner.php header notes it mirrors the C scanner.

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "
\$j = json_decode(\"{\\\"a\\\":1,\\\"b\\\":[true,null]}\", true);
var_export(\$j);
"'

VM decode works; goal is same behavior without C parser on JIT/AOT/self-host paths.

Scope (this repo)

Layer Path
PHP decode extend ext/standard/json_decode.php / new VmJsonDecode.php sharing scanner with VmJsonScanner
JIT/AOT lib/JIT/JitJsonDecode.php — lower to PHP path or thin native stub only
Linker remove phpc_json_decode.c from lib/AOT/Linker.php when parity green
C shrink delete ~649 lines from lib/AOT/runtime/phpc_json_decode.c (note lines removed in PR)
Tests test/compliance/cases/stdlib/json_decode*.phpt + AOT fixtures; reuse json_validate cases where overlap

Done when

  • json_decode() VM/JIT/AOT behavior matches Zend on compliance .phpt set (assoc + object modes, depth, invalid JSON)
  • lib/AOT/runtime/phpc_json_decode.c removed from link (or reduced to documented thin ABI only)
  • PR body lists lines removed from runtime/
  • make bootstrap-selfhost-link / targeted ./script/ci-fast.sh --filter JsonDecode green

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

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#6202: StringJsonDecodeJit LLVM bodies, delete phpc_json_decode.c ~649 lines).

  3. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #7078.

    C shrink: deleted lib/AOT/runtime/phpc_json_decode.c (649 lines); removed from lib/AOT/Linker.php.

    PHP path: lib/JIT/Builtin/StringJsonDecodeJit.php (LLVM __compiler_json_decode, __compiler_json_validate, __compiler_json_last_error*), wired via StringJsonDecode.php + Type/String_.php + JitJsonDecode::ensureLinked().

    Verification (Docker):

    • vendor/bin/phpunit test/unit/JIT/StringJsonDecodeRuntimeStandaloneTest.php → OK (1/1)
    • vendor/bin/phpunit test/compliance/JITTest.php --filter json_decode_jit → OK (1/1)
    • vendor/bin/phpunit test/unit/JsonValidateBuiltinTest.php → OK (5/5)

    Note: bin/compile.php segfaults for all scripts on this harness (incl. master echo ok); AOT gate blocked pre-existing — JIT/json_validate VM paths green.

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