Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/JIT/Builtin/ScalarDimFetchRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* JIT/AOT link for scalar dim fetch warnings via ScalarDimFetchJitHelper PHP (#10271, #10343).
*
* SSOT: {@see \PHPCompiler\VM\ScalarDimFetchJitHelper}, {@see \PHPCompiler\VM\ErrorReporter}
* emitWarning / emitWarningForNativeBool ensureLinked before ABI use; ensureFullStandaloneBodies
* must not NestedJIT this during init (#35065) — peer #35035 / #32122 `.1` mint class.
*/
final class ScalarDimFetchRuntime
{
Expand Down
2 changes: 2 additions & 0 deletions lib/JIT/Builtin/StringJsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* Embed + thin standalone AOT: single {@see __compiler_json_decode} bridge with tag dispatch
* (Unserialize #20785 / Explode #14750 shape — no thin null stubs).
* Validate/last_error live in {@see JsonValidateJitHelper} (separate NestedJIT TU).
* Call sites ensureLinked before lookup; ensureFullStandaloneBodies must not NestedJIT this
* during init (#35065) — peer #35035 / #32122 `.1` mint class.
* php-src: ext/json/php_json.c — php_json_decode_ex / php_json_validate
*/
final class StringJsonDecode
Expand Down
2 changes: 2 additions & 0 deletions lib/JIT/Builtin/StringJsonEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*
* Embed + thin standalone AOT: {@see JsonEncodeNestedJitHelper} via {@see JitVmHelperLink}
* (Context-free NestedJIT path — avoids `$ctx->runtime->vm` SIGSEGV on thin AOT).
* Call sites ensureLinked / ensureJitHelperCompiled before lookup; ensureFullStandaloneBodies
* must not NestedJIT this during init (#35065) — peer #35035 / #32122 `.1` mint class.
* php-src: ext/json/php_json.c — php_json_encode
*/
final class StringJsonEncode
Expand Down
2 changes: 2 additions & 0 deletions lib/JIT/Builtin/StringOffsetRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* (ChunkSplit #21399 / ObOutput #21476 shape — no user-script standalone inline LLVM fork).
* Nested helper compile leaf: inline LLVM matching {@see StringOffsetJitHelper::normalizeByteIndex}
* without re-entering NestedJIT (#17279 / MathFpow Kernel shape).
* dimFetch / readDimAsString / … ensureLinked before ABI use; ensureFullStandaloneBodies must
* not NestedJIT this during init (#35065) — peer #35035 / #32122 `.1` mint class.
* SSOT: {@see \PHPCompiler\VM\StringOffsetJitHelper}, {@see \PHPCompiler\VM\Variable}
* php-src: Zend/zend_operators.c — string offset fetch/write
*/
Expand Down
12 changes: 8 additions & 4 deletions lib/JIT/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -2466,12 +2466,16 @@ private function ensureFullStandaloneBodies(): void
if (\PHPCompiler\AOT\HelperRuntimeCache::enabled()) {
Builtin\StringStrReplace::ensureStandaloneBodies($this);
}
Builtin\StringJsonEncode::ensureStandaloneBodies($this);
Builtin\StringJsonDecode::ensureStandaloneBodies($this);
// StringJsonEncode / StringJsonDecode always-on removed (#35065): JitJsonEncode /
// JitJsonDecode / JsonEncodeArrayLlvm / JitJsonValidate / … already ensureLinked /
// ensureJitHelperCompiled before lookup (peer #35035). Full standalone must not
// NestedJIT json_* during init — leftover Context NestedJIT vs Runtime ABI drift
// mints json_encode_*.1 / json_decode*.1 (#31894 / #32122).
Builtin\StringTriggerError::ensureStandaloneBodies($this);
Builtin\StringRandomBytes::implement($this);
Builtin\ScalarDimFetchRuntime::ensureStandaloneBodies($this);
Builtin\StringOffsetRuntime::ensureStandaloneBodies($this);
// ScalarDimFetchRuntime / StringOffsetRuntime always-on removed (#35065):
// emitWarning / dimFetch / readDimAsString / … already ensureLinked before ABI use
// (peer #35035). Do not NestedJIT offset / scalar-dim helpers during full init.
// UndefinedVariableRuntime: ensureLinked only — emitWarningForName uses __compiler_trigger_error
// (StringTriggerError already linked above; avoid duplicate standalone bodies — #10524).
// NestedJIT StreamFilterJitHelper during full standalone init (#21041 / peer #20998).
Expand Down
87 changes: 87 additions & 0 deletions test/unit/ContextFullStandaloneLazyJsonOffsetShrinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace PHPCompiler\Test\Unit;

use PHPUnit\Framework\TestCase;

/**
* Drop Context::ensureFullStandaloneBodies always-on NestedJIT of StringJsonEncode /
* StringJsonDecode / ScalarDimFetchRuntime / StringOffsetRuntime (#35065 / peer #35035).
*
* Full standalone must not NestedJIT json_* / string-offset / scalar-dim during init
* (#32122 .1 mint class). Call sites already ensureLinked before lookup / emit.
*/
final class ContextFullStandaloneLazyJsonOffsetShrinkTest extends TestCase
{
public function testEnsureFullDropsEagerJsonAndOffsetNestedJit(): void
{
$context = (string) file_get_contents(__DIR__.'/../../lib/JIT/Context.php');
$this->assertStringContainsString('#35065', $context);
$fullPos = strpos($context, 'private function ensureFullStandaloneBodies');
$this->assertNotFalse($fullPos);
$fullEnd = strpos($context, 'public function compileToFile', $fullPos);
$this->assertNotFalse($fullEnd);
$fullBody = substr($context, $fullPos, $fullEnd - $fullPos);

foreach ([
'StringJsonEncode::ensureStandaloneBodies($this)',
'StringJsonDecode::ensureStandaloneBodies($this)',
'ScalarDimFetchRuntime::ensureStandaloneBodies($this)',
'StringOffsetRuntime::ensureStandaloneBodies($this)',
] as $forbidden) {
$this->assertStringNotContainsString(
$forbidden,
$fullBody,
'ensureFullStandaloneBodies must not eagerly '.$forbidden.' (#35065)'
);
}

// Still links format / refresh / strspn / file helpers used by inventory / standalone main.
$this->assertStringContainsString('StringFormat::ensureStandaloneBodies($this)', $fullBody);
$this->assertStringContainsString('SuperglobalRefreshRuntime::ensureStandaloneBodies($this)', $fullBody);
$this->assertStringContainsString('StringStrspn::ensureStandaloneBodies($this)', $fullBody);
}

public function testCallSitesStillEnsureBeforeLookup(): void
{
$encode = (string) file_get_contents(__DIR__.'/../../ext/standard/JitJsonEncode.php');
$this->assertStringContainsString('StringJsonEncode::ensureLinked($context)', $encode);

$decode = (string) file_get_contents(__DIR__.'/../../ext/standard/JitJsonDecode.php');
$this->assertStringContainsString('StringJsonDecode::ensureLinked($context)', $decode);

$scalar = (string) file_get_contents(__DIR__.'/../../lib/JIT/Builtin/ScalarDimFetchRuntime.php');
$this->assertStringContainsString('self::ensureLinked($context)', $scalar);
$this->assertStringContainsString('#35065', $scalar);

$offset = (string) file_get_contents(__DIR__.'/../../lib/JIT/Builtin/StringOffsetRuntime.php');
$this->assertStringContainsString('self::ensureLinked($context)', $offset);
$this->assertStringContainsString('#35065', $offset);
}

public function testJsonRuntimesDocumentLazyFull(): void
{
$encode = (string) file_get_contents(__DIR__.'/../../lib/JIT/Builtin/StringJsonEncode.php');
$this->assertStringContainsString('#35065', $encode);
$this->assertStringContainsString('ensureFullStandaloneBodies', $encode);

$decode = (string) file_get_contents(__DIR__.'/../../lib/JIT/Builtin/StringJsonDecode.php');
$this->assertStringContainsString('#35065', $decode);
$this->assertStringContainsString('ensureFullStandaloneBodies', $decode);
}

public function testNoNewRuntimeCForFullStandaloneLazy(): void
{
$runtimeDir = dirname(__DIR__, 2).'/lib/AOT/runtime';
$this->assertFileDoesNotExist(
$runtimeDir.'/json_encode.c',
'must not add json_encode.c for #35065 — PHP JIT bridges only'
);
$this->assertFileDoesNotExist(
$runtimeDir.'/string_offset.c',
'must not add string_offset.c for #35065'
);
}
}
Loading