Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127670 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 9D7D71A00BC for ; Mon, 16 Jun 2025 07:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1750057428; bh=NPZx51zaJdEEm8iAGNPXoZ0GGyF2vL3kKqk0K3UyTHA=; h=From:Date:Subject:To:From; b=FBVy278Um7Ardik4ztbxi9lAtSUB/8FY/XXssLPF4Ck3ON6R6rBPcOLBkzeRVHaUk 6r2tGfqB0bqbzhgOHZxExKG757jMvtwOvoFUDzquj1+34zJSEGD08MYBHRTTsHbVfk QfWID2bAvqoKM5Fu5KsaFLcVzcPQdf4MlLugD+trCFkf6d89uww9rIwSqmLGvrim0R zheD6Bw6uRgpMwuCJDPT/O2YtO1gaLrYW0dwq0+WU0ZK3ob5Rac8KfOEA6yZqwlR2L aJvMnmMVKN3YPpOBUPipF44flvRZJix2yaQkB91Tkb4ecdfldx8+FD7z5n3nQQzhCc 0+f0RLPMo251Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6B7AB180047 for ; Mon, 16 Jun 2025 07:03:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 16 Jun 2025 07:03:44 +0000 (UTC) Received: by mail-ua1-f51.google.com with SMTP id a1e0cc1a2514c-87ed676e631so2608924241.3 for ; Mon, 16 Jun 2025 00:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750057542; x=1750662342; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=NPZx51zaJdEEm8iAGNPXoZ0GGyF2vL3kKqk0K3UyTHA=; b=NHDbA2o/A9PsOV8Fr3tuxROHTHVDlewQxGyto2CbWHa1g79pVQiWQxtGLouBwxVrpN Bz+ufcoEj8n/xHVyBYCMxVugWj9Aj7H/P6gtEZhK7YmMruWfskftnjTk8Wf9R6yBc9dY GokK39pWQ9SguekclFJgC06oAceHizSs5vlKVVA0j+r2BRwbIB4kjTNmcCmRiRIP+L15 uYYCyGGEN82y4ANWo7AqoRvoiY6sixsLfP3aeg3clgpa0hqMPahxnBaAYi/BdJqPyjQm QyWQDqH935O/Ol5Yp9gkE6UWSS/msZM0uNOgy5HL1klOlPPWcdpobHq0DkPTjF+3GWOv xAfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750057542; x=1750662342; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NPZx51zaJdEEm8iAGNPXoZ0GGyF2vL3kKqk0K3UyTHA=; b=Q4aOGYR7TE8JOblCjAzfecqHgURYshcFBngmv1/6rKkua4IU3/cxPRD976yUPqYmqO STSWSpSE63hnhGo7x7fb4Wn4hcnYaSavHJrqlWm148WgKd0trwXPXKTHl1i26/F09IWX ZOC4qGnyfBY1TaAcBjM6VaEphwI6ObfkXvdvfL9T2InVjlwf6P5mw1QeYyjSqR+4k3Ad zSwBw3Hz/gQgAzGi8iEYc54jUDUhMv9yvBD1Oktbsb6vEiVlmTdAtt+x03EyBWiiMxja qvO6VTLAZ/2AKA4/nMbGYES9MbK3/OSpzLqdAnhZlSd90/B+sfC/W0yrgX4TpShRb+fe ckmw== X-Gm-Message-State: AOJu0Yy0f2ovXNg9aVQo+bhcBZNaqdnI1tWSDB7ad/omjfZLS6dA3eAo +7Fp1Pia12l5j8zR/7Vz+PDzC8XMjbG1DF541eUEjT5YX50fpU++sRYkSSfe1nAH/K6xsOQx46r ZW0jkQ6tZEoOyCW6LWblBiBAmIfnC77D0O1fBU+JMXA== X-Gm-Gg: ASbGncthZ/TpgZuTRtkq8nl9JzGjIeAFcFyBIPNcyX5LF8TXU4By3p+LMNVmJGkJt3S 8mBoFP+j3K11Sht8WH7GRxXRrAQxBPxqXQoXgAuZFpoW4/5psf/kdkHf/WTkoe522mGDV35To5o p6HEEdIzJ6wRcv2RWeWulllPIcYthRUrupdpb0ue8uH1Fu2JDLN9g5dGg= X-Google-Smtp-Source: AGHT+IF8Kzv/z9NhxIQE+ImDSpv9WjKlLFFT8Hc6AlZFlgm0UwQo2oqFv9UbYyX501a+9xDdYSeEHVldBxiSW3g/JyQ= X-Received: by 2002:a05:6102:2927:b0:4e7:cbf9:43a1 with SMTP id ada2fe7eead31-4e7f6218da4mr5168456137.23.1750057542344; Mon, 16 Jun 2025 00:05:42 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 16 Jun 2025 15:05:30 +0800 X-Gm-Features: AX0GCFuICwDbWT73tUtMihu3-E2iHvKA3dzHjXyV8kcXGbiPIgwMt6PVPelMcvw Message-ID: Subject: [PHP-DEV] [RFC] RFC Discussion - CLI-Only Development Mode and AOT Compilation Architecture To: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000025e51d0637ab0677" From: wheakerd@gmail.com (wheakerd) --00000000000025e51d0637ab0677 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Dear PHP Internals, I am submitting this proposal for discussion regarding a potential future direction for PHP: moving toward a CLI-only development model and introducing an optional Ahead-of-Time (AOT) compilation infrastructure. While this may not fully align with PHP=E2=80=99s traditional interpreter-b= ased design, I believe it opens up valuable opportunities to modernize PHP's runtime and improve performance, portability, and long-term maintainability= . =3D=3D=3D=3D=3D Current Development Landscape =3D=3D=3D=3D=3D Contemporary PHP projects are already moving toward architecture patterns that resemble compiled systems: - Frameworks define service containers, dependency graphs, and code generation layers. - Static analysis tools (Psalm, PHPStan) are integral to modern development= . - Code is often bootstrapped through CLI pipelines: for build, testing, deployment, and even request simulation (`php artisan`, `bin/console`, etc.). - Composer autoloading, annotation processors, and classmaps are precomputed. - Web servers (e.g., Swoole, RoadRunner) are replacing FPM in performance-critical applications, with CLI processes becoming long-lived daemons. All of this reflects a growing shift: **PHP is increasingly behaving like a static backend language**, except it still runs on a dynamic interpreter. This proposal attempts to provide native language support and compiler infrastructure that aligns with these modern PHP usage patterns. =3D=3D=3D=3D=3D Motivation =3D=3D=3D=3D=3D PHP=E2=80=99s traditional runtime model (FPM or mod_php) is optimized for short-lived, script-based execution. However, this limits PHP=E2=80=99s pot= ential in: - Serverless or event-driven environments (high cold start cost). - Embedded targets and containers with limited runtime support. - Modular system design where PHP extensions must be written in C. - Distributable binaries for CLI tools or desktop-style apps. PHP developers are often forced to work around these limitations using complex workarounds (e.g., caching containers, annotation scans, custom autoloaders, preload hacks). AOT compilation and CLI-first design can solve these challenges directly, natively. =3D=3D=3D=3D=3D Proposal =3D=3D=3D=3D=3D ### 1. Compiler Infrastructure (AOT Mode) A new compiler pipeline would be introduced: - **Frontend**: Parse PHP source into AST (reusing current infrastructure). - **IR Layer**: Transform AST into intermediate representation (IR). - **Backend**: Compile IR into native binary via C transpilation or LLVM backend. ### 2. Required Language Model Changes To make PHP compilable in AOT mode, certain dynamic features must be restricted or restructured. The following are required: #### a. **Static Code & Configuration** - Dynamic constructs (e.g., `eval`, dynamic includes/classes/functions) are disallowed. - Project must provide static configuration file (`php.compiler.json`) for classmap, entrypoint, environment constants, etc. - No runtime-based code discovery or composition. #### b. **Unified Standard Library** - Procedural global functions (e.g., `strlen`, `array_merge`) are consolidated into base classes (e.g., `Str::len()`, `Arr::merge()`). - Modules gain clearer boundaries and dependency injection support. #### c. **Environment Interfaces** - Superglobals (`$_ENV`, `$_SERVER`, etc.) are abstracted via interfaces or injectable system services. #### d. **Type System Enhancements** - Strong use of `declare(strict_types=3D1)`, interfaces, final classes, and property types. - Optional compilation-time type enforcement and inference. #### e. **Compiler Extension Hooks** - Developers or frameworks can hook into compilation stages (AST transformation, IR passes) to generate optimized artifacts. ### 3. CLI-Only Development Focus - CLI becomes the canonical platform for PHP execution and development. - PHP-FPM and SAPI models remain available for backward compatibility but are **not required** for future application delivery. - Built-in CLI runners or Web adapters (e.g., `php serve`, Swoole adapters) provide development/testing environments. =3D=3D=3D=3D=3D Expected Benefits =3D=3D=3D=3D=3D - Native, standalone executables=E2=80=94no PHP interpreter dependency. - Fast cold start (useful in serverless and event-driven environments). - PHP extensions can be authored in PHP and compiled, removing the C barrier. - Clean separation between compilation-time and runtime. - Enables new use cases: embedded systems, WASM targets, mobile SDKs, long-lived CLI daemons. =3D=3D=3D=3D=3D Compatibility Note =3D=3D=3D=3D=3D This proposal is entirely opt-in and defines a **strict static subset of PHP**. Dynamic runtime via Zend VM and JIT continues to be supported and unchanged. This is an addition, not a replacement. =3D=3D=3D=3D=3D Request for Feedback =3D=3D=3D=3D=3D I=E2=80=99d appreciate feedback from internals and community members on: - Whether such a compiler pipeline is desirable and feasible. - Acceptability of the required language subset restrictions. - Pathways to prototype this outside core, e.g., via PHP extensions or userland tooling. =3D=3D=3D=3D=3D Note =3D=3D=3D=3D=3D I would like to clarify that I am currently not in a position to implement this proposal independently, as it would involve deep modifications to the PHP runtime, compiler pipeline design, or extension interfaces. This RFC is submitted with the intention of initiating structured discussion and community exploration around this long-term direction. I am willing to contribute research, coordination, and specification work if there is interest from core contributors. I greatly appreciate any feedback, suggestions, or interest in collaborating on prototyping or feasibility assessment. Sincerely, [wheakerd] --00000000000025e51d0637ab0677 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dear PHP Internals,

I am submittin= g this proposal for discussion regarding a potential future direction for P= HP: moving toward a CLI-only development model and introducing an optional = Ahead-of-Time (AOT) compilation infrastructure.

While this may not f= ully align with PHP=E2=80=99s traditional interpreter-based design, I belie= ve it opens up valuable opportunities to modernize PHP's runtime and im= prove performance, portability, and long-term maintainability.

=3D= =3D=3D=3D=3D Current Development Landscape =3D=3D=3D=3D=3D
Contemporary = PHP projects are already moving toward architecture patterns that resemble = compiled systems:

- Frameworks define service containers, dependency= graphs, and code generation layers.
- Static analysis tools (Psalm, PHP= Stan) are integral to modern development.
- Code is often bootstrapped t= hrough CLI pipelines: for build, testing, deployment, and even request simu= lation (`php artisan`, `bin/console`, etc.).
- Composer autoloading, ann= otation processors, and classmaps are precomputed.
- Web servers (e.g., = Swoole, RoadRunner) are replacing FPM in performance-critical applications,= with CLI processes becoming long-lived daemons.

All of this reflect= s a growing shift: **PHP is increasingly behaving like a static backend lan= guage**, except it still runs on a dynamic interpreter.

This proposa= l attempts to provide native language support and compiler infrastructure t= hat aligns with these modern PHP usage patterns.

=3D=3D=3D=3D=3D Mot= ivation =3D=3D=3D=3D=3D
PHP=E2=80=99s traditional runtime model (FPM or = mod_php) is optimized for short-lived, script-based execution. However, thi= s limits PHP=E2=80=99s potential in:

- Serverless or event-driven en= vironments (high cold start cost).
- Embedded targets and containers wit= h limited runtime support.
- Modular system design where PHP extensions = must be written in C.
- Distributable binaries for CLI tools or desktop-= style apps.

PHP developers are often forced to work around these lim= itations using complex workarounds (e.g., caching containers, annotation sc= ans, custom autoloaders, preload hacks). AOT compilation and CLI-first desi= gn can solve these challenges directly, natively.

=3D=3D=3D=3D=3D Pr= oposal =3D=3D=3D=3D=3D
### 1. Compiler Infrastructure (AOT Mode)
A ne= w compiler pipeline would be introduced:

- **Frontend**: Parse PHP s= ource into AST (reusing current infrastructure).
- **IR Layer**: Transfo= rm AST into intermediate representation (IR).
- **Backend**: Compile IR = into native binary via C transpilation or LLVM backend.

### 2. Requi= red Language Model Changes
To make PHP compilable in AOT mode, certain d= ynamic features must be restricted or restructured. The following are requi= red:

#### a. **Static Code & Configuration**
- Dynamic constr= ucts (e.g., `eval`, dynamic includes/classes/functions) are disallowed.
= - Project must provide static configuration file (`php.compiler.json`) for = classmap, entrypoint, environment constants, etc.
- No runtime-based cod= e discovery or composition.

#### b. **Unified Standard Library**
= - Procedural global functions (e.g., `strlen`, `array_merge`) are consolida= ted into base classes (e.g., `Str::len()`, `Arr::merge()`).
- Modules ga= in clearer boundaries and dependency injection support.

#### c. **En= vironment Interfaces**
- Superglobals (`$_ENV`, `$_SERVER`, etc.) are ab= stracted via interfaces or injectable system services.

#### d. **Typ= e System Enhancements**
- Strong use of `declare(strict_types=3D1)`, int= erfaces, final classes, and property types.
- Optional compilation-time = type enforcement and inference.

#### e. **Compiler Extension Hooks**=
- Developers or frameworks can hook into compilation stages (AST transf= ormation, IR passes) to generate optimized artifacts.

### 3. CLI-Onl= y Development Focus
- CLI becomes the canonical platform for PHP executi= on and development.
- PHP-FPM and SAPI models remain available for backw= ard compatibility but are **not required** for future application delivery.=
- Built-in CLI runners or Web adapters (e.g., `php serve`, Swoole adapt= ers) provide development/testing environments.

=3D=3D=3D=3D=3D Expec= ted Benefits =3D=3D=3D=3D=3D
- Native, standalone executables=E2=80=94no= PHP interpreter dependency.
- Fast cold start (useful in serverless and= event-driven environments).
- PHP extensions can be authored in PHP and= compiled, removing the C barrier.
- Clean separation between compilatio= n-time and runtime.
- Enables new use cases: embedded systems, WASM targ= ets, mobile SDKs, long-lived CLI daemons.

=3D=3D=3D=3D=3D Compatibil= ity Note =3D=3D=3D=3D=3D
This proposal is entirely opt-in and defines a = **strict static subset of PHP**. Dynamic runtime via Zend VM and JIT contin= ues to be supported and unchanged. This is an addition, not a replacement.<= br>
=3D=3D=3D=3D=3D Request for Feedback =3D=3D=3D=3D=3D
I=E2=80=99d = appreciate feedback from internals and community members on:

- Wheth= er such a compiler pipeline is desirable and feasible.
- Acceptability o= f the required language subset restrictions.
- Pathways to prototype thi= s outside core, e.g., via PHP extensions or userland tooling.
=3D=3D=3D=3D=3D Note =3D=3D=3D=3D=3D
I would like to clarify= that I am currently not in a position to implement this proposal independe= ntly, as it would involve deep modifications to the PHP runtime, compiler p= ipeline design, or extension interfaces.

This RFC is submitted with = the intention of initiating structured discussion and community exploration= around this long-term direction. I am willing to contribute research, coor= dination, and specification work if there is interest from core contributor= s.

I greatly appreciate any feedback, suggestions, or interest in co= llaborating on prototyping or feasibility assessment.

Sincerely,= =C2=A0
[wheakerd]
--00000000000025e51d0637ab0677--