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
5 changes: 4 additions & 1 deletion bin/compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,10 @@ function phpc_run_command(string $command, ?array $env = null): ?array
// `free(): invalid pointer` (exit 134) or spins after a successful link
// (#21925, #31726). Prefer Runtime::standalone() fast-exit (before $context
// dtor); this is belt-and-suspenders if that return is reached.
if ($aotEmitOk && '' !== $normalized && str_contains($normalized, 'test/selfhost/')) {
if ($aotEmitOk && '' !== $normalized && (
str_contains($normalized, 'test/selfhost/')
|| \PHPCompiler\AOT\ExternalMethodBind::spineChunkMode()
)) {
\PHPCompiler\AOT\AotEmitFastExit::exitAfterSuccessfulSelfhostEmit($filename, (string) $options['-o']);
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/AOT/AotEmitFastExit.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ public static function exitAfterSuccessfulSelfhostEmit(
$selfhostEnv = getenv('PHP_COMPILER_SELFHOST_AOT');
$isSelfhostPath = '' !== $normalized && str_contains($normalized, 'test/selfhost/');
$isSelfhostEnv = '1' === $selfhostEnv || 'true' === strtolower((string) $selfhostEnv);
$spineChunkEnv = getenv(ExternalMethodBind::ENV_SPINE_CHUNK);
$isSpineChunk = '1' === $spineChunkEnv || 'true' === strtolower((string) $spineChunkEnv);
// Match #31741: selfhost path or explicit SELFHOST_AOT (compile_driver argv).
if (!$isSelfhostPath && !$isSelfhostEnv) {
// Spine split-TU hub/consumer chunks compile under SPINE_CHUNK=1 but are not
// test/selfhost paths; bin/compile.php treats them as user-script AOT and clears
// SELFHOST_AOT — same post-emit LLVM teardown hang (#31726, #36155 Phase B).
if (!$isSelfhostPath && !$isSelfhostEnv && !$isSpineChunk) {
return;
}
if (null !== $outfile && '' !== $outfile) {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/SelfhostAotFastExitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PHPCompiler\test\unit;

use PHPCompiler\AOT\ExternalMethodBind;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -88,4 +89,20 @@ public function testZendCompileInvokeHasPostEmitHangWatchdog(): void
$this->assertStringContainsString('runtime_standalone_compiletofile_done', $script);
$this->assertStringContainsString('#31726', $script);
}

/** Spine split-TU hub chunks hit the same post-emit hang without fast-exit (#36155). */
public function testAotEmitFastExitIncludesSpineChunkMode(): void
{
$root = dirname(__DIR__, 2);
$helper = (string) file_get_contents($root.'/lib/AOT/AotEmitFastExit.php');
$this->assertStringContainsString('ExternalMethodBind::ENV_SPINE_CHUNK', $helper);
$this->assertStringContainsString('isSpineChunk', $helper);
}

public function testCompilePhpFastExitsAfterSpineChunkEmit(): void
{
$root = dirname(__DIR__, 2);
$compile = (string) file_get_contents($root.'/bin/compile.php');
$this->assertStringContainsString('ExternalMethodBind::spineChunkMode()', $compile);
}
}
Loading