diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ab529d6c..ef3490e8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,6 +19,8 @@ env: jobs: build-phpx: name: Build PHPX (PHP ${{ matrix.php }}) + # Skip the whole test pipeline when the push commit message contains `--skip-tests`. + if: ${{ !contains(github.event.head_commit.message || '', '--skip-tests') }} runs-on: ubuntu-latest timeout-minutes: 30 strategy: @@ -94,6 +96,7 @@ jobs: phpunit: name: PHPUnit (PHP ${{ matrix.php }}) + if: ${{ !contains(github.event.head_commit.message || '', '--skip-tests') }} runs-on: ubuntu-latest timeout-minutes: 30 needs: build-phpx @@ -158,6 +161,7 @@ jobs: phpt: name: PHPT (PHP ${{ matrix.php }}) + if: ${{ !contains(github.event.head_commit.message || '', '--skip-tests') }} runs-on: ubuntu-latest timeout-minutes: 180 needs: build-phpx diff --git a/README-CN.md b/README-CN.md index b328ac82..bd69376f 100644 --- a/README-CN.md +++ b/README-CN.md @@ -22,8 +22,14 @@ TypePHP 是一个 AOT(Ahead-Of-Time,提前编译)编译器,它把 PHP 它保留熟悉的 PHP 语法,同时引入编译期类型信息,让编译器为你的性能热点生成快速、 静态类型的 C++ 代码,而其余代码仍运行在久经考验的 Zend 引擎上。 +TypePHP **完全由 PHP 语言编写**,并且**完全自举**:`tpc` 编译器二进制就是 +用 TypePHP 编译编译器自身的 PHP 源码得到的。整个自举链路是纯 PHP——编译器 +本身没有任何 C 或 C++ 胶水代码。 + ## 特性 +- **完全自举、纯 PHP 实现** —— TypePHP 编译器完全由 PHP 语言编写,并能自举: + 用 `tpc` 编译编译器自身的源码,即可生成原生二进制。 - **真正的 AOT 编译** —— PHP 先降级为 C++17,再编译为原生机器码。无解释器、 无 opcode 缓存、无 JIT 预热。 - **三种构建模式** —— 同一份代码可编译为独立 `bin` 可执行文件、可加载的 PHP @@ -74,20 +80,21 @@ TypePHP 是一个 AOT(Ahead-Of-Time,提前编译)编译器,它把 PHP - **PHP 8.4 – 8.5**,需包含 `embed` 模块(`libphp.so`) - **GCC 9+**(或 Clang),支持 **C++17** - **CMake 3.24+** -- 高精度数学库:**GMP**、**MPFR**、**libmpdec** +- 高精度数学库:**GMP**、**MPFR**(libmpdec 已随 PHPX 内置) ```shell # Ubuntu/Debian -sudo apt install libgmp-dev libmpfr-dev libmpdec-dev +sudo apt install libgmp-dev libmpfr-dev # RHEL/CentOS/Fedora -sudo dnf install gmp-devel mpfr-devel libmpdec-devel +sudo dnf install gmp-devel mpfr-devel # Arch Linux -sudo pacman -S gmp mpfr mpdecimal +sudo pacman -S gmp mpfr ``` -> GMP 用于 `bigInt`,MPFR 用于 `bigFloat`,libmpdec 用于 `decimal`。 +> GMP 用于 `bigInt`,MPFR 用于 `bigFloat`。`decimal` 底层是 libmpdec, +> 已随 PHPX 内置,无需单独安装。 预览版目前以 **Linux** 为主要开发平台(推荐 Ubuntu 22.04)。Windows 和 macOS 打包通过同一入口点支持。 @@ -322,6 +329,21 @@ function main(): void ## 基准测试 +### PHP 语言基准(来自 php-src) + +TypePHP 使用 `-O3` 运行 PHP 源码树自带的官方 `bench.php` 与 +`micro_bench.php` 语言性能测试: + +| 基准 | 解释执行 PHP | TypePHP AOT(`-O3`) | 加速比 | +|---|---|---|---| +| `bench.php`(总计) | 5.034 秒 | **0.603 秒** | 约 8× | +| `micro_bench.php`(总计) | 13.045 秒 | **2.021 秒** | 约 6.5× | + +两项基准覆盖 PHP 语言核心性能——函数调用、对象属性访问、数组/哈希访问、 +字符串处理、控制流等。完整逐项报告见 [`bench.txt`](bench.txt)。 + +### std::array 对比 PHP 数组 + 一个 10000×100000 的元素累加循环,对比 PHP 数组、TypePHP `std::array` 与原生 C++: diff --git a/README.md b/README.md index c5727644..9746c3e2 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,16 @@ It keeps familiar PHP syntax and adds compile-time type information, so the compiler can emit fast, statically-typed C++ for your hot paths — while the rest of your code continues to run on the battle-tested Zend engine. +TypePHP is **written entirely in PHP** and is **fully self-hosting**: the `tpc` +compiler binary is built by compiling the compiler's own PHP source code with +TypePHP. The bootstrap chain is pure PHP — no C or C++ glue in the compiler +itself. + ## Features +- **Self-hosting, written in PHP** — the TypePHP compiler is implemented + entirely in PHP and bootstraps itself: `tpc` compiles the compiler's own + source into a native binary. - **True AOT compilation** — PHP is lowered to C++17, then to native machine code. No interpreter, no opcode cache, no JIT warm-up. - **Three build modes** — build a standalone `bin` executable, a loadable PHP @@ -87,20 +95,21 @@ rest of your code continues to run on the battle-tested Zend engine. - **PHP 8.4 – 8.5** with the `embed` module (`libphp.so`) - **GCC 9+** (or Clang) with **C++17** - **CMake 3.24+** -- High-precision math libraries: **GMP**, **MPFR**, **libmpdec** +- High-precision math libraries: **GMP**, **MPFR** (libmpdec is bundled with PHPX) ```shell # Ubuntu/Debian -sudo apt install libgmp-dev libmpfr-dev libmpdec-dev +sudo apt install libgmp-dev libmpfr-dev # RHEL/CentOS/Fedora -sudo dnf install gmp-devel mpfr-devel libmpdec-devel +sudo dnf install gmp-devel mpfr-devel # Arch Linux -sudo pacman -S gmp mpfr mpdecimal +sudo pacman -S gmp mpfr ``` -> GMP powers `bigInt`, MPFR powers `bigFloat`, and libmpdec powers `decimal`. +> GMP powers `bigInt` and MPFR powers `bigFloat`. The `decimal` type is backed +> by libmpdec, which is bundled with PHPX — no separate install required. The preview currently targets **Linux** as the primary development platform (Ubuntu 22.04 recommended). Windows and macOS packaging is supported through @@ -340,6 +349,22 @@ See [Mixed C++/PHP](docs/MIXED_CPP_PHP.md). ## Benchmark +### PHP language benchmarks (from php-src) + +TypePHP runs the official `bench.php` and `micro_bench.php` language +benchmarks that ship with the PHP source tree, compiled with `-O3`: + +| Benchmark | Interpreted PHP | TypePHP AOT (`-O3`) | Speedup | +|---|---|---|---| +| `bench.php` (total) | 5.034 s | **0.603 s** | ~8× | +| `micro_bench.php` (total) | 13.045 s | **2.021 s** | ~6.5× | + +Both benchmarks measure core PHP language performance — function calls, object +property access, array/hash access, string handling, control flow, and more. +See the full per-item report in [`bench.txt`](bench.txt). + +### std::array vs PHP array + A 10000×100000 element update loop, comparing PHP arrays against TypePHP's `std::array` and native C++: