Repository navigation
php-in-php: json_decode() — delete phpc_json_decode.c (~649 lines), VM+JIT+AOT from ext/standard/VmJson*.php #6202
Copy link
Copy link
Closed
Labels
area:compilerCompiler / CFG / JITCompiler / CFG / JITarea:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web apps
Description
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
- php/php-src
ext/json/php_json_decoder.c— reference decode semantics - php/php-src
ext/json/php_json.c—json_decode()flags, depth, assoc/object modes - php/php-src
ext/standard/basic_functions.stub.php—JSON_*constants
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.phptset (assoc + object modes, depth, invalid JSON) -
lib/AOT/runtime/phpc_json_decode.cremoved 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 JsonDecodegreen
Related
- Stdlib: json_last_error() — VM + LLVM JIT/AOT #1173 JSON decode subset · Stdlib: json_decode() — enum case JSON must TypeError not LogicException (ext/json/php_json.c) #5907 enum operand TypeError · Stdlib: json_encode() — enum case operands must match Zend JSON output (ext/json/php_json.c) #6130 json_encode enum parity · Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492 self-host
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:compilerCompiler / CFG / JITCompiler / CFG / JITarea:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web apps
Activity
PurHur commentedon Jun 6, 2026
claim: PHP Runtime → PHP — starting this run (#6202: StringJsonDecodeJit LLVM bodies, delete phpc_json_decode.c ~649 lines).
php-in-php: delete phpc_json_decode.c, LLVM json_decode in StringJson…
PurHur commentedon Jun 6, 2026
Merged via PR #7078.
C shrink: deleted
lib/AOT/runtime/phpc_json_decode.c(649 lines); removed fromlib/AOT/Linker.php.PHP path:
lib/JIT/Builtin/StringJsonDecodeJit.php(LLVM__compiler_json_decode,__compiler_json_validate,__compiler_json_last_error*), wired viaStringJsonDecode.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.phpsegfaults for all scripts on this harness (incl. masterecho ok); AOT gate blocked pre-existing — JIT/json_validate VM paths green.