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
30 changes: 23 additions & 7 deletions lib/JIT.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ private function compileBlock(Block $block, ?string $funcName = null): PHPLLVM\V
|| $this->isLiteralIncludeDiscoveryRealLoweringMethod($emitLc)
|| $this->isDeployRootRealLoweringMethod($emitLc)
|| $this->isSourceBundlerRealLoweringMethod($emitLc)
|| $this->isConstStringFolderRealLoweringMethod($emitLc)
|| $this->isSuperglobalsRealLoweringMethod($emitLc)
|| $this->isM3EmitTuRuntimeCompileDriverSpineLoweringName($emitLc)
)
Expand Down Expand Up @@ -2035,21 +2036,36 @@ private function isSuperglobalsM3CompileDriverLoweringMethod(string $lower): boo
}

/**
* ConstStringFolder real LLVM lowering during self-host AOT (#816, #1056).
* ConstStringFolder real LLVM lowering during M3 compile-driver link (#816, #2827).
*
* Disabled until string/boxed compare ICmp verify is fixed; web-bootstrap stubs link the bundle.
* Entry points plus private helpers they call must be real-lowered together; stubbed callees
* return null and break __DIR__/__FILE__ include-path folding in bin/compile.php bundles.
*/
private function isConstStringFolderRealLoweringMethod(string $lower): bool
{
if (!$this->shouldUseM3CompileDriverRealLowering()) {
return false;
}
foreach ([
'fold',
'foldconcat',
'foldforinclude',
'tryparsedeployinclude',
'literalstringvalue',
'magicscriptconstvalue',
'sourcedir',
'findmagicscriptconstforoperand',
'findmagicscriptconstinblocktree',
'findconcatforoperand',
'findconcatinblocktree',
'folddeploypathconcat',
] as $suffix) {
if (str_ends_with($lower, '\\web\\conststringfolder::'.$suffix)) {
return true;
}
}

// Keep this narrow: only the compile-driver needs const-folding for include discovery/bundling.
return str_ends_with($lower, '\\web\\conststringfolder::fold')
|| str_ends_with($lower, '\\web\\conststringfolder::foldconcat')
|| str_ends_with($lower, '\\web\\conststringfolder::foldforinclude')
|| str_ends_with($lower, '\\web\\conststringfolder::tryparsedeployinclude');
return false;
}

private function collectStubFunctionArgTypes(Block $block): array
Expand Down
39 changes: 39 additions & 0 deletions test/unit/JitCompilerSelfHostStubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ final class JitCompilerSelfHostStubTest extends TestCase
'foldconcat',
'foldforinclude',
'tryparsedeployinclude',
'literalstringvalue',
'magicscriptconstvalue',
'sourcedir',
'findmagicscriptconstforoperand',
'findmagicscriptconstinblocktree',
'findconcatforoperand',
'findconcatinblocktree',
'folddeploypathconcat',
];

/** @var list<string> */
Expand Down Expand Up @@ -237,6 +245,37 @@ public static function m3WebConstStringFolderRealLoweringProvider(): iterable
}
}

/**
* @dataProvider m3WebConstStringFolderRealLoweringProvider
*/
public function testM3CompileDriverConstStringFolderHelpersAreNotWebBootstrapStubbed(string $method): void
{
$prevSelfHost = getenv('PHP_COMPILER_SELFHOST_AOT');
$prevM3 = getenv('PHP_COMPILER_M3_COMPILE_DRIVER');
putenv('PHP_COMPILER_SELFHOST_AOT=1');
putenv('PHP_COMPILER_M3_COMPILE_DRIVER=1');
try {
$this->assertFalse(
$this->invokeSkipCheck(
'isSkippedWebBootstrapHotPathName',
'phpcompiler\\web\\conststringfolder::'.$method
),
"Expected web-bootstrap real lowering for ConstStringFolder::{$method} when M3 compile driver is on"
);
} finally {
if (false === $prevSelfHost) {
putenv('PHP_COMPILER_SELFHOST_AOT');
} else {
putenv('PHP_COMPILER_SELFHOST_AOT='.$prevSelfHost);
}
if (false === $prevM3) {
putenv('PHP_COMPILER_M3_COMPILE_DRIVER');
} else {
putenv('PHP_COMPILER_M3_COMPILE_DRIVER='.$prevM3);
}
}
}

/**
* @dataProvider m3WebIncludePathResolverRealLoweringProvider
*/
Expand Down