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
7 changes: 3 additions & 4 deletions docs/bootstrap-inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Regenerate: `php script/bootstrap-inventory.php`
| Phase A inventory files (M2 ratio SSOT) | 6432 |
| Phase A ratio-deferred paths | 0 |
| Source constructs flagged (blockers) | 0 |
| Source constructs flagged (warnings) | 20541 |
| Source constructs flagged (warnings) | 20540 |

## Compiler CFG gaps (`lib/Compiler.php`)

Expand Down Expand Up @@ -4735,7 +4735,7 @@ Rank live CFG gaps across inventory files: `php script/bootstrap-inventory-triag
| `lib/JIT/Builtin/BcmathJit.php` | 0 | 3 |
| `lib/JIT/Builtin/Bz2Runtime.php` | 0 | 1 |
| `lib/JIT/Builtin/Bz2StreamIo.php` | 0 | 1 |
| `lib/JIT/Builtin/Bz2StreamRuntime.php` | 0 | 3 |
| `lib/JIT/Builtin/Bz2StreamRuntime.php` | 0 | 2 |
| `lib/JIT/Builtin/CallArgv.php` | 0 | 1 |
| `lib/JIT/Builtin/CallUnpackRuntime.php` | 0 | 1 |
| `lib/JIT/Builtin/CastArrayRuntime.php` | 0 | 1 |
Expand Down Expand Up @@ -41487,9 +41487,8 @@ Rank live CFG gaps across inventory files: `php script/bootstrap-inventory-triag
### `lib/JIT/Builtin/Bz2StreamRuntime.php`

**Warnings** (review for bootstrap subset):
- new JIT (line 346)
- 13 class method(s)
- 9 closure(s)
- 8 closure(s)

### `lib/JIT/Builtin/CallArgv.php`

Expand Down
39 changes: 10 additions & 29 deletions lib/JIT/Builtin/Bz2StreamRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace PHPCompiler\JIT\Builtin;

use PHPCompiler\JIT;
use PHPCompiler\JIT\Context;
use PHPCompiler\JIT\JitNestedHelperCoerce;
use PHPCompiler\JIT\JitVmHelperLink;
use PHPCompiler\JIT\NestedJitCompileScope;
use PHPLLVM\Builder;
use PHPLLVM\Value\Function_ as LlvmFunction;

/**
* JIT/AOT link for bz2 stream ABI via Bz2StreamJitHelper PHP (#17301).
* JIT/AOT link for bz2 stream ABI via Bz2StreamJitHelper PHP (#17301, #22416).
*
* Helper compile: {@see JitVmHelperLink::ensureCompiled} (peer SysGetloadavgRuntime #22399).
* SSOT: {@see \PHPCompiler\ext\bz2\VmBz2Stream}
* php-src: ext/bz2/bz2.c
*/
Expand Down Expand Up @@ -314,38 +315,18 @@ private static function emitNullableStringBridge(
private static function helperFunction(Context $context, string $logical): LlvmFunction
{
self::ensureJitHelperCompiled($context);
$lc = \strtolower($logical);
$fn = $context->functions[$lc] ?? null;
if (null === $fn) {
throw new \LogicException($logical.' missing after Bz2StreamJitHelper compile (#17301)');
}

return $fn;
return JitVmHelperLink::lookupCompiled($context, $logical, '#22416');
}

private static function ensureJitHelperCompiled(Context $context): void
{
$missing = false;
foreach (self::COMPILED_HELPERS as $logical) {
if (!isset($context->functions[\strtolower($logical)])) {
$missing = true;
break;
}
}
if (!$missing) {
return;
}

$runtime = $context->runtime;
$path = \dirname(__DIR__, 3).self::HELPER_PATH;
NestedJitCompileScope::run($context, static function () use ($context, $runtime, $path): void {
$block = $runtime->parseAndCompile((string) \file_get_contents($path), 'Bz2StreamJitHelper.php');
if (null === $block) {
throw new \LogicException('Bz2StreamJitHelper.php parseAndCompile failed (#17301)');
}
$jit = new JIT($context);
$jit->compile($block);
});
JitVmHelperLink::ensureCompiled(
$context,
self::HELPER_PATH,
self::COMPILED_HELPERS,
'#22416'
);
}

private static function registerLinkedRuntime(Context $context): void
Expand Down
34 changes: 34 additions & 0 deletions test/unit/Bz2StreamRuntimeShrinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace PHPCompiler\Test\Unit;

use PHPUnit\Framework\TestCase;

/**
* Bz2StreamRuntime NestedJIT via JitVmHelperLink::ensureCompiled (#22416 / peer #22399).
* Must route through Bz2StreamJitHelper PHP (#17301).
*/
final class Bz2StreamRuntimeShrinkTest extends TestCase
{
public function testBz2StreamRuntimeUsesJitVmHelperLink(): void
{
$source = (string) file_get_contents(__DIR__.'/../../lib/JIT/Builtin/Bz2StreamRuntime.php');
$this->assertStringContainsString('Bz2StreamJitHelper', $source);
$this->assertStringContainsString('JitVmHelperLink::ensureCompiled', $source);
$this->assertStringContainsString('JitVmHelperLink::lookupCompiled', $source);
$this->assertStringContainsString('NestedJitCompileScope::isActive', $source);
$this->assertStringNotContainsString('NestedJitCompileScope::run', $source);
$this->assertStringNotContainsString('parseAndCompile', $source);
$this->assertStringNotContainsString('new JIT(', $source);
$this->assertStringNotContainsString('use PHPCompiler\\JIT;', $source);
}

public function testBz2StreamJitHelperDelegatesToVmBz2Stream(): void
{
$source = (string) file_get_contents(__DIR__.'/../../ext/bz2/Bz2StreamJitHelper.php');
$this->assertStringContainsString('VmBz2Stream', $source);
$this->assertFileExists(__DIR__.'/../../ext/bz2/Bz2StreamJitHelper.php');
}
}
Loading