Skip to content

AOT: Dynamic require/include discovery for project build (phase 2 of #154) #1762

Description

@PurHur

Category

bootstrap | language (AOT project graph)

Problem

#752 ✅ / #59 shipped static project build: phpc.json includes[] + ProjectGraph BFS over literal require paths. 003-MiniWebApp and self-host bundles rely on explicit manifest lists.

Remaining gap: apps that use dynamic includes (require $path, PSR-4 autoload, conditional requires) cannot phpc build --project without manually listing every file. Self-host M4/M5 needs either full graph discovery or documented static bundling policy.

#154 phase 1 (explicit multi-TU link) is largely shipped; this tracks phase 2.

#1803 / #1856 cover phpc.json autoload schema + migrating 003 — this issue is the compiler graph walk that consumes that manifest.

php-src reference

  • N/A (tooling) — behavior mirrors Zend autoload + compile-time include resolution patterns used by OPcache preloading
  • Compare: php-src ext/opcache preload file list build; PSR-4 equivalent in Composer ClassLoader.php

Repro (failure today)

test/fixtures/aot/projects/psr4_mini/ (to be added) with:

{ "entry": "public/index.php", "autoload": { "psr-4": { "App\\": "src/" } } }
// public/index.php
require __DIR__ . '/../vendor/autoload.php'; // not needed — direct class ref
echo (new App\Greeter())->hi();
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/compile.php --project test/fixtures/aot/projects/psr4_mini -o /tmp/psr4_mini 2>&1'

Expected (after fix): link succeeds; /tmp/psr4_mini prints greeting.
Actual today: unresolved class / missing TU unless src/Greeter.php hand-listed in includes[].

Dynamic require lint:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./phpc lint --project examples/003-MiniWebApp 2>&1 | head -20'
# dynamic require $path should report actionable error (not silent omit)

Goal

phpc build --project optionally discovers PHP files reachable from entry via:

  1. Static string require/require_once/include (extend Language: include/require in JIT and AOT (multi-file applications) #54 AOT lowering)
  2. phpc.json "autoload": { "psr-4": { "App\\": "src/" } } — compile referenced classes (DevEx: PSR-4 autoload paths in phpc.json project manifest #155)
  3. Fail with actionable lint report for truly dynamic paths (require $var)

Scope (this repo)

Piece File Notes
Graph walk lib/AOT/ProjectGraph.php Extend BFS: literal include edges + autoload class files
Manifest lib/Web/ProjectManifest.php Parse autoload.psr-4; validate paths exist
Class discovery new lib/AOT/AutoloadResolver.php Map App\Routersrc/Router.php (PSR-4)
Compiler lib/Compiler.php Record TYPE_INCLUDE literal targets in compile unit metadata
Lint bin/lint.php, UnsupportedRegistry phpc lint --project reports unresolved dynamic includes
Link lib/AOT/Linker.php Multi-.o already works (#752)
JIT parity #475, #1770 JIT project graph should share resolver when possible
Tests test/unit/ProjectGraphTest.php, test/fixtures/aot/projects/psr4_mini/ Static vs dynamic require fixtures

Suggested fixture layout

test/fixtures/aot/projects/psr4_mini/
  phpc.json          # entry + autoload psr-4
  public/index.php   # uses App\Greeter
  src/Greeter.php

Unblock order

#1803 manifest schema → AutoloadResolver → ProjectGraph BFS → psr4_mini fixture → #1856 migrate 003

Lint error shape (actionable)

error: dynamic require at Router.php:42 — add file to phpc.json includes[] or use literal require

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/ci-local.sh --filter ProjectGraph'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./phpc lint --project examples/003-MiniWebApp'

Dependencies

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-3:aotPhase 3 – AOT deployment

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions