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: 1 addition & 1 deletion docs/bootstrap-selfhost.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
| Self-host probe in full CI | `./script/ci-local.sh` (LLVM tail) | ✅ default-on when LLVM 9 present; `BOOTSTRAP_SELFHOST_PROBE_GATE=0` to skip ([#829](https://github.com/PurHur/php-compiler/issues/829)) |
| Wave gate in full CI | `./script/ci-local.sh` (LLVM tail) | ✅ default-on when LLVM 9 present; `BOOTSTRAP_WAVE_CHECK=0` to skip; `./script/bootstrap-wave-check.sh --fail-fast` |
| Self-host native link | `./script/bootstrap-selfhost-link.sh` | ✅ `build/selfhost` prints `compiler_minimal bundle OK` ([#557](https://github.com/PurHur/php-compiler/issues/557), [#913](https://github.com/PurHur/php-compiler/issues/913)) |
| M2 lib spine smoke lint | `php bin/compile.php -l test/selfhost/compiler_lib_spine_smoke/main.php` | ✅ **567** units (`compiler_minimal` **109** + **459** M2 spine; [#1492](https://github.com/PurHur/php-compiler/issues/1492), [#1419](https://github.com/PurHur/php-compiler/issues/1419), [#1497](https://github.com/PurHur/php-compiler/issues/1497)) |
| M2 lib spine smoke lint | `php bin/compile.php -l test/selfhost/compiler_lib_spine_smoke/main.php` | ✅ **568** units (`compiler_minimal` **109** + **460** M2 spine; [#1492](https://github.com/PurHur/php-compiler/issues/1492), [#1419](https://github.com/PurHur/php-compiler/issues/1419), [#1497](https://github.com/PurHur/php-compiler/issues/1497)) |
| M2 lib spine smoke native run | `./script/bootstrap-selfhost-lib-spine-smoke-link.sh` or `BOOTSTRAP_LIB_SPINE_SMOKE=1 make bootstrap-selfhost-lib-spine-smoke` | ✅ `build/selfhost-lib-spine-smoke` prints `compiler_lib_spine_smoke bundle OK` |
| M3 HelloWorld self-host probe lint | `php bin/compile.php -l test/selfhost/compiler_helloworld_smoke/main.php` | ✅ `compiler_compile_smoke` spine + `helloworld_compile_smoke` driver (linkable) |
| M3 HelloWorld compile driver lint | `php bin/compile.php -l test/selfhost/compiler_helloworld_smoke/compile_driver.php` | ✅ `Runtime::parseAndCompile` + mode-file dispatch (native link opt-in) |
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/development-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permalink: /development-status.html
| **Overall progress** | ~**50%** toward web-capable + self-hosting compiler (indicative) |
| **Wave 3 (May 2026)** | Language **10/13** · Stdlib **12/13** ([#1380](https://github.com/PurHur/php-compiler/issues/1380)) |
| **North Star 1** | Reference web app — VM ✅ · AOT link ✅ · AOT execute **partial** ([#1044](https://github.com/PurHur/php-compiler/issues/1044)) |
| **North Star 2** | Self-compile — M0–M1 ✅ · M2 spine **567/586** · M5 ⬜ ([#1492](https://github.com/PurHur/php-compiler/issues/1492)) |
| **North Star 2** | Self-compile — M0–M1 ✅ · M2 spine **568/586** · M5 ⬜ ([#1492](https://github.com/PurHur/php-compiler/issues/1492)) |
| **Not Zend parity** | Subset compiler (not full Zend PHP) |

[← Visual overview](index.html) · [Repository](https://github.com/PurHur/php-compiler)
Expand Down Expand Up @@ -51,7 +51,7 @@ Indicative composite toward a **web-capable, self-hosting** compiler (not line-c
| **Stdlib** | ~58% | Wave-3 batch ([#1367](https://github.com/PurHur/php-compiler/issues/1367)–[#1379](https://github.com/PurHur/php-compiler/issues/1379)): 12/13 closed; `debug_backtrace` ([#1378](https://github.com/PurHur/php-compiler/issues/1378)) in [#1404](https://github.com/PurHur/php-compiler/pull/1404) |
| **Web AOT** (build, deploy) | ~65% | Project link ✅; home-route execute ✅; PATH_INFO / layout chain 🚧 |
| **Reference app** (MiniWebApp) | ~55% | VM ✅; AOT link ✅; AOT execute **partial** |
| **Self-host** (North Star 2, M0–M5) | ~97% | M0–M1 ✅; M2 spine **567/586**; M3 partial (native run ✅, Zend emit); M4–M5 ⬜ — [self-host-target.md](https://github.com/PurHur/php-compiler/blob/master/docs/self-host-target.md) |
| **Self-host** (North Star 2, M0–M5) | ~97% | M0–M1 ✅; M2 spine **568/586**; M3 partial (native run ✅, Zend emit); M4–M5 ⬜ — [self-host-target.md](https://github.com/PurHur/php-compiler/blob/master/docs/self-host-target.md) |

**Overall (indicative): ~52%** toward the stated north stars below.

Expand Down Expand Up @@ -200,7 +200,7 @@ Zend PHP still runs `bin/compile.php` during bootstrap. The output is a **curate
|-----------|---------|--------|
| **M0 — Bundled subset runs** | ~109 literal `require_once` units in `test/selfhost/compiler_minimal/main.php` → `build/selfhost` prints `compiler_minimal bundle OK` | ✅ [#557](https://github.com/PurHur/php-compiler/issues/557), [#913](https://github.com/PurHur/php-compiler/issues/913) |
| **M1 — Compiler-shaped bundle** | Bundled `Compiler.php` AOT lint; compile-smoke native link + AOT echo (`compiler smoke`); driver smoke toward `bin/compile.php` | ✅ [#1025](https://github.com/PurHur/php-compiler/issues/1025), [#1095](https://github.com/PurHur/php-compiler/issues/1095) |
| **M2 — Lib spine growth** | `compiler_lib_spine_smoke` bundle toward full `bin/vm.php` inventory (**586** files) | 🚧 **567** / 586 units (~97%; [#1492](https://github.com/PurHur/php-compiler/issues/1492), [#1419](https://github.com/PurHur/php-compiler/issues/1419), [#1497](https://github.com/PurHur/php-compiler/issues/1497)) |
| **M2 — Lib spine growth** | `compiler_lib_spine_smoke` bundle toward full `bin/vm.php` inventory (**586** files) | 🚧 **568** / 586 units (~97%; [#1492](https://github.com/PurHur/php-compiler/issues/1492), [#1419](https://github.com/PurHur/php-compiler/issues/1419), [#1497](https://github.com/PurHur/php-compiler/issues/1497)) |
| **M3 — Native compiles PHP** | Self-hosted bundle links; HelloWorld AOT **runs** natively; **emit still uses Zend** `bin/compile.php` fallback | 🚧 partial ([#1492](https://github.com/PurHur/php-compiler/issues/1492)) |
| **M4 — Bootstrap loop** | Native toolchain rebuilds the **next** compiler sources (same tree, new revision) | ⬜ |
| **M5 — Full self-host** | Real `bin/vm.php` / `bin/compile.php` path on full inventory; **no Zend bootstrap** | ⬜ **north star** ([#1492](https://github.com/PurHur/php-compiler/issues/1492)) |
Expand All @@ -210,7 +210,7 @@ Zend PHP still runs `bin/compile.php` during bootstrap. The output is a **curate
| Set | ~Files | Notes |
|-----|--------|-------|
| `compiler_minimal` bundle (M0) | **109** | Literal `require_once` closure |
| `compiler_lib_spine_smoke` (M2) | **567** | vm.php-path lib/ + ext/standard growth bundle |
| `compiler_lib_spine_smoke` (M2) | **568** | vm.php-path lib/ + ext/standard growth bundle |
| Top-level `lib/*.php` | **14** | Per-file AOT lint ✅ |
| Full vm.php inventory | **586** | Phase A inventory (`php script/bootstrap-inventory.php`) |

Expand Down Expand Up @@ -245,7 +245,7 @@ Details: [self-host-target.md](https://github.com/PurHur/php-compiler/blob/maste
| Native link + run | `./script/bootstrap-selfhost-link.sh` | ✅ M0 |
| Compile smoke link | `make bootstrap-selfhost-compile-smoke` | ✅ M1 |
| Compile smoke AOT echo | `make bootstrap-selfhost-compile-smoke-run` | ✅ M1 |
| M2 spine native link | `BOOTSTRAP_LIB_SPINE_SMOKE=1 make bootstrap-selfhost-lib-spine-smoke` | ✅ `compiler_lib_spine_smoke bundle OK` (**567** units) |
| M2 spine native link | `BOOTSTRAP_LIB_SPINE_SMOKE=1 make bootstrap-selfhost-lib-spine-smoke` | ✅ `compiler_lib_spine_smoke bundle OK` (**568** units) |
| M3 HelloWorld probe | `make bootstrap-selfhost-helloworld` | 🚧 partial — native **run** ✅; emit Zend fallback |
| Wave gate | `./script/bootstrap-wave-check.sh` | ✅ locally / Docker; GHA workflow disabled |
| Next includes probe | `php script/bootstrap-selfhost-next-includes.php` | 🚧 bundle growth |
Expand Down
10 changes: 5 additions & 5 deletions docs/self-host-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ That is **M5**. Everything below is the honest path from today’s bootstrap to
| Layer | Today | Target |
|-------|-------|--------|
| **Bootstrap driver** | Zend runs `php bin/compile.php` | Compiled `bin/compile.php` |
| **Bundle size** | **567** curated `require_once` in spine smoke (108 minimal overlap + **459** M2-only) | **586** inventory files |
| **Inventory coverage** | **~97%** of vm.php path in spine smoke (**567/586**) | **100%** |
| **Bundle size** | **568** curated `require_once` in spine smoke (108 minimal overlap + **460** M2-only) | **586** inventory files |
| **Inventory coverage** | **~97%** of vm.php path in spine smoke (**568/586**) | **100%** |
| **HelloWorld** | Native **run** ✅; **emit** still Zend fallback | Native compile + emit |
| **Bootstrap loop (M4)** | Gen-1 link + gen-2 Zend partial | Native gen-2 emit + full tree rebuild |
| **Vendor** | `composer install` + patches on host | Prelinked artifacts only |
Expand All @@ -61,7 +61,7 @@ That is **M5**. Everything below is the honest path from today’s bootstrap to
|-----------|----------------|--------|-----|
| **M0** | AOT can link a **small** honest `lib/` subset | ✅ | 100% |
| **M1** | Bundle is **compiler-shaped** (lint + compile-smoke) | ✅ | 100% |
| **M2** | Spine grows toward full `bin/vm.php` inventory | 🚧 **567/586** units | **~97%** |
| **M2** | Spine grows toward full `bin/vm.php` inventory | 🚧 **568/586** units | **~97%** |
| **M3** | Self-host binary **compiles external PHP** (HelloWorld) without Zend emit | 🚧 partial | **~45%** |
| **M4** | Self-host binary **rebuilds** the next compiler tree | ⬜ | 0% |
| **M5** | Full self-host; Zend retired from loop | ⬜ north star | 0% |
Expand All @@ -72,7 +72,7 @@ That is **M5**. Everything below is the honest path from today’s bootstrap to

| Indicator | Formula | May 2026 |
|-----------|---------|----------|
| **M2 spine progress** | `require_once` units in `compiler_lib_spine_smoke` ÷ Phase A inventory file count | **567 / 586 ≈ 97%** |
| **M2 spine progress** | `require_once` units in `compiler_lib_spine_smoke` ÷ Phase A inventory file count | **568 / 586 ≈ 97%** |
| **Public “Self-host” row** | Same M2 ratio until M3–M5 gates add weight ([`development-status.md`](pages/development-status.md)) | **~61%** |
| **Composite (internal)** | Milestone weights in table above (M0–M1 = 100%, M2 = spine %, M3–M5 = gate %) | **~54%** |

Expand Down Expand Up @@ -124,7 +124,7 @@ Parallel batches ([#1419](https://github.com/PurHur/php-compiler/issues/1419), [
| Entry | Units | Role |
|-------|------:|------|
| `test/selfhost/compiler_minimal/main.php` | **109** | M0 core |
| `test/selfhost/compiler_lib_spine_smoke/main.php` | **567** | M2 growth (ext/standard + Vm* spine batch) |
| `test/selfhost/compiler_lib_spine_smoke/main.php` | **568** | M2 growth (ext/standard + Vm* spine batch) |
| `test/selfhost/compiler_helloworld_smoke/` | — | M3 probe + compile driver |
| `test/selfhost/bootstrap_loop_smoke/` | — | M4 scaffold (gen-1→gen-2 loop probe; [#1498](https://github.com/PurHur/php-compiler/issues/1498)) |

Expand Down
38 changes: 28 additions & 10 deletions ext/standard/sort_.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,38 @@ public function execute(Frame $frame): void
$copy->copyFrom($value);
$values[] = $copy;
}
\usort($values, static function (Variable $a, Variable $b): int {
$a = $a->resolveIndirect();
$b = $b->resolveIndirect();
if (Variable::TYPE_STRING === $a->type && Variable::TYPE_STRING === $b->type) {
return VmString::strcmp($a->toString(), $b->toString());
}
if (Variable::TYPE_INTEGER === $a->type && Variable::TYPE_INTEGER === $b->type) {
return $a->toInt() <=> $b->toInt();
$first = $values[0]->resolveIndirect();
if (Variable::TYPE_STRING === $first->type) {
VmInternalCompare::sortVariableValues(
$values,
VmInternalCompare::resolveStringCallback('strcmp')
);
} elseif (Variable::TYPE_INTEGER === $first->type) {
$n = \count($values);
for ($i = 1; $i < $n; ++$i) {
$j = $i;
while ($j > 0) {
$a = $values[$j - 1]->resolveIndirect();
$b = $values[$j]->resolveIndirect();
if (Variable::TYPE_INTEGER !== $a->type || Variable::TYPE_INTEGER !== $b->type) {
throw new \LogicException(
'sort() only supports homogeneous string or integer arrays in this compiler build'
);
}
if ($a->toInt() <= $b->toInt()) {
break;
}
$tmp = $values[$j - 1];
$values[$j - 1] = $values[$j];
$values[$j] = $tmp;
--$j;
}
}

} else {
throw new \LogicException(
'sort() only supports homogeneous string or integer arrays in this compiler build'
);
});
}
$ht->replacePackedValues($values);
if (null !== $frame->returnVar) {
$frame->returnVar->bool(true);
Expand Down
1 change: 1 addition & 0 deletions test/selfhost/compiler_lib_spine_smoke/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@
require_once __DIR__.'/../../../ext/standard/setrawcookie.php';
require_once __DIR__.'/../../../ext/standard/sin.php';
require_once __DIR__.'/../../../ext/standard/sleep.php';
require_once __DIR__.'/../../../ext/standard/sort_.php';
require_once __DIR__.'/../../../ext/standard/sprintf_.php';
require_once __DIR__.'/../../../ext/standard/sqrt.php';
require_once __DIR__.'/../../../ext/standard/stat_.php';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BootstrapSelfhostBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function testCompilerLibSpineSmokeBundleUnitCountAndKeyUnits(): void
$this->assertFileExists($entry);
$contents = (string) file_get_contents($entry);
$count = substr_count($contents, 'require_once __DIR__');
$this->assertSame(567, $count, '108 compiler_minimal overlap + 459 M2 spine units; array_pop/shift/search/combine/multisort/sort/usort/uasort + shell_exec + VmString/VmSplAutoload/VmPregReplaceCallback/spl_autoload skipped (AOT lint)');
$this->assertSame(568, $count, '108 compiler_minimal overlap + 460 M2 spine units; array_pop/shift/search/combine/multisort/usort/uasort + shell_exec + VmString/VmSplAutoload/VmPregReplaceCallback/spl_autoload skipped (AOT lint)');
foreach (self::LIB_SPINE_SMOKE_NEW_UNITS as $unit) {
$this->assertStringContainsString(
"require_once __DIR__.'/../../../{$unit}';",
Expand Down