Skip to content

php-in-php: JIT StringJsonDecodeJit — route json_decode()/json_validate() through VmJson PHP not ~2.1k-line LLVM (#1492) #9359

Description

@PurHur

Category

php-in-php — shrink json_decode LLVM duplicate (#9267 covers json_encode only)

Problem

json_encode() migration is tracked in #9267, but json_decode() / json_validate() still use StringJsonDecodeJit.php (~2,128 lines of hand-written LLVM implementing __compiler_json_decode / validation paths, mirroring phpc_json_decode.c).

VM paths already use PHP scanners in ext/json/ — JIT/AOT should call the same PHP helpers, not maintain a second parser in LLVM.

php-src reference

Repro

# VM (PHP scanner) works for basic decode:
./script/docker-exec.sh -- php bin/vm.php -r '
var_export(json_decode("{\"a\":1}", true));
'
# array ('a' => 1,)

# LLVM duplicate footprint:
wc -l lib/JIT/Builtin/StringJsonDecodeJit.php

# JIT must match VM after migration:
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php -r "
var_export(json_decode(\"{\\\"a\\\":1}\", true));
"'

# json_validate flags path (coordinate #8748 enum TypeError separately):
./script/docker-exec.sh -- php bin/vm.php -r '
var_export(json_validate("{}"));
var_export(json_validate("{"));
'

Scope (this repo)

Path Work
ext/json/VmJson*.php SSOT decode/validate
lib/JIT/Builtin/StringJsonDecodeJit.php Replace with PHP bridge
lib/JIT/Builtin/StringJsonDecode.php Wire bridge
ext/standard/json_validate.php Share scanner with decode
Tests Extend existing json compliance PHPTs for JIT path

Done when

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