Category
php-in-php
Problem
json_encode() VM path already uses ext/standard/VmJson.php + VmJsonFormat.php, but JIT/AOT still lowers through ~540 lines of hand-written LLVM in lib/JIT/Builtin/StringJsonEncode.php (__compiler_json_encode_value, __compiler_json_encode_array). This duplicates UTF-8/NaN/Inf handling, enum/object encoding, and json_last_error() state that already exist in PHP — and drifts from VM behavior (see #9205 invalid UTF-8).
php-src reference
ext/json/php_json.c — php_json_encode() / encoder error paths
ext/json/php_json_encoder.c — value walk + UTF-8 validation
Repro (VM vs JIT divergence today)
<?php
$s = "\xC3\x28"; // invalid UTF-8
var_dump(json_encode($s));
var_dump(json_last_error(), json_last_error_msg());
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro.php'
Zend: false, JSON_ERROR_UTF8, message about malformed UTF-8.
VM today: replacement char + json_last_error() === 0 (#9205).
JIT: uses LLVM encoder — same or worse drift from VmJson.
Scope (this repo)
| Area |
Path |
Action |
| Stdlib SSOT |
ext/standard/VmJson.php, VmJsonFormat.php |
Keep encoder semantics here |
| JIT bridge |
new ext/standard/JitJsonEncode.php or extend existing |
Call VM helpers from JIT like other migrated builtins |
| Delete/shrink |
lib/JIT/Builtin/StringJsonEncode.php |
Remove LLVM value walk; thin ABI trampoline only if unavoidable |
| Registry |
lib/JIT/Builtin/Type.php |
Stop registering __compiler_json_encode_* bodies |
| Tests |
test/compliance/cases/ext/json_*.phpt |
VM + JIT/AOT must agree |
PHP-in-PHP rule: do not grow runtime/*.c for JSON encoding; port any missing edge cases into ext/standard/.
Done when (php-src-strict)
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter JsonEncode'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php test/repro/json_encode_utf8_invalid.php'
Links
Category
php-in-phpProblem
json_encode()VM path already usesext/standard/VmJson.php+VmJsonFormat.php, but JIT/AOT still lowers through ~540 lines of hand-written LLVM inlib/JIT/Builtin/StringJsonEncode.php(__compiler_json_encode_value,__compiler_json_encode_array). This duplicates UTF-8/NaN/Inf handling, enum/object encoding, andjson_last_error()state that already exist in PHP — and drifts from VM behavior (see #9205 invalid UTF-8).php-src reference
ext/json/php_json.c—php_json_encode()/ encoder error pathsext/json/php_json_encoder.c— value walk + UTF-8 validationRepro (VM vs JIT divergence today)
Zend:
false,JSON_ERROR_UTF8, message about malformed UTF-8.VM today: replacement char +
json_last_error() === 0(#9205).JIT: uses LLVM encoder — same or worse drift from
VmJson.Scope (this repo)
ext/standard/VmJson.php,VmJsonFormat.phpext/standard/JitJsonEncode.phpor extend existinglib/JIT/Builtin/StringJsonEncode.phplib/JIT/Builtin/Type.php__compiler_json_encode_*bodiestest/compliance/cases/ext/json_*.phptPHP-in-PHP rule: do not grow
runtime/*.cfor JSON encoding; port any missing edge cases intoext/standard/.Done when (php-src-strict)
json_encode()calls the same PHP encoder path as VM (sharedVmJson/ helper), not LLVM hashtable walklib/JIT/Builtin/StringJsonEncode.phpdeleted or reduced to a thin bridge (<50 lines) — cite lines removed in PRdocs/capabilities.mdmatrix unchanged or notes JIT PHPT greenVerification
Links