Repository navigation
fix: the first compile works, and *.php scanners find PHP# classes - #160
Merged
Merged
Conversation
…nding PHP# classes
Problem: on a fresh tree, vendor/autoload.php reads the standard
library's compiled Module.sharp as it loads, so every PHP process on the
engine dies before the first compile, vendor/bin/mago compile and an
extension host included. And PHP code that lists *.php files to find
classes never sees a .sharp class, because its compiled unit is binary
and lives in .sharp/.
Solution: the note records what master does, observed in neutral
fixtures, and the approved design. The container reads the library's
module before the first module or binding it reads, and readModule
becomes addModule. mago compile writes a <Name>.php beside each project
.sharp file that declares a type, which loads the .sharp file through
the engine.
docs/architecture/slices/
└── sharp-discovery.md new: where compiled output lives, the
Solutions, the first-compile options and
their cost, the evidence
…rst compile works Problem: since 4567fd6, the plugin's autoload.php read the standard library's compiled Module.sharp as it loaded. On a fresh clone nothing is compiled, so every PHP process on the engine that loads vendor/autoload.php died with "Module.sharp isn't compiled. Run vendor/bin/mago compile.": vendor/bin/mago compile itself, a mago extension host, and a Laravel app's artisan in composer install. Solution: Sharp\Internal\readModule names the library's module, and the container reads it at its first module lookup, before any other module, as it already reads every app module. A request that resolves no service never needs it compiled, and a missing compile is refused where PHP# code runs. ext/sharp/ └── sharp.c the container_library global; readModule names the file; sharp_container_read_folders and sharp_container_binding read it first Zend/tests/sharp/ ├── library_autoload.inc uncompiled: requires autoload.php before │ mago compiles, then builds a service │ through the library's Environment └── library_autoload_uncompiled.phpt new docs/architecture/ └── modules.md the Engine list says when it is read
Problem: route-attribute discovery, Laravel's console kernel and its
event discovery list a folder's *.php files and name each class by its
path. A PHP# class has only its .sharp source and a binary unit in
.sharp/, so none of them found it, and a user had to patch each
library.
Solution: mago compile writes a <Name>.php beside each of the project's
.sharp files that declares a type, before it compiles, so every
compiled file stays current. The file loads the .sharp file through the
engine, and on plain PHP it throws the "needs the PHP# engine" error.
The next compile rewrites a changed file and deletes the file of a
removed source, and a hand-written <Name>.php beside a .sharp file is a
compile error. A package in vendor/ and an autoload-dev folder get
none, so a test class keeps one file for PHPUnit, which loads a class
only from the file it lists. In a git repository each checkout keeps
its files in its own block of the info/exclude file git rev-parse
--git-path names.
sharp/mago/
├── src/commands/compile.rs writes, refreshes and deletes the
│ files, refuses one someone wrote
├── src/utils/git.rs exclude: the checkout's block
└── tests/compile.rs written, kept current, deleted with
its source, refused beside a
hand-written file, none in vendor/
or autoload-dev, passes lint, every
unit current, the block in a clone
and a worktree
Zend/tests/sharp/
└── discovery.phpt new: a directory iterator and glob
find and load the PHP# class
docs/
├── spec.md section 27: the rule, autoload-dev
│ and vendor/, phpunit.xml, editors
├── decisions/081-discovery.md new
├── architecture/modules.md phpunit.xml lists Test.sharp
└── architecture/slices/
└── sharp-discovery.md what was built, found not fixed
sharp/
└── README.md the Composer section names the files
Problem: a PHP file whose source was deleted stopped every scanner with
"Failed opening required". A post-autoload-dump callback in Composer's
own process found no binding of Sharp\Environment, because Composer's
loader includes the PHP file and the plugin never named the library's
module. A project whose analyzer loads only .sharp files kept every
orphan. Parallel spec runs filled the shared .git/info/exclude with 210
blocks and torn lines for folders git already ignores. The file failed
mago fmt --check. The refusal named no class and missed a file of
another case. Written files were 0600, which a PHP-FPM pool user
cannot read. composer run-script post-autoload-dump crashed on the
missing optimize flag. mago analyze knew no Sharp\Container in plain
PHP. No test ran an extension host on an uncompiled project.
Solution:
- The PHP file returns before its require_once once its source is
gone, in mago fmt's layout.
- autoload.php names the library's module whenever the engine runs.
- Orphans are found on disk: the folders of the sources and of the
last compile's units, by the file's first line.
- The exclude block lists only the files no .gitignore ignores, drops
the block of a folder that is gone or ignored, and is replaced by
rename. sharp/.gitignore ignores the hosts fixture's files.
- The refusal reads "app/Order.php and app/Order.sharp both name
App.Order", finds the file whatever its case, and the summary prints
at ERROR when the compile failed.
- write_by_rename gives a new file's mode.
- Plugin::dumpClassMap leaves the class map as it is without flags.
- The prelude declares Sharp\Container and Sharp\ContainerError.
- sharp/phpunit runs an extension host that loads vendor/autoload.php,
and sharp/bin/test --phpunit compiles it from nothing compiled and
runs composer run-script.
sharp/mago/
├── src/commands/compile.rs guard, layout, orphans on disk,
│ refusal, summary level
├── src/utils/mod.rs write_by_rename, moved, new mode
├── src/utils/git.rs exclude: .gitignore, stale blocks,
│ rename
├── crates/prelude/assets/extensions/sharp.php Container
├── crates/analyzer/tests/sharp.rs plain PHP row
└── tests/compile.rs fmt, orphans with sharp only, case,
exact name, mode, ignored files,
stale blocks
sharp/composer/
├── autoload.php readModule whenever the engine runs
└── src/Plugin.php run-script
sharp/phpunit/
├── extension-host.php new
├── mago.toml starts it
└── composer.json, composer.lock revolt/event-loop
sharp/bin/test --phpunit from nothing compiled
sharp/.gitignore the hosts fixture's PHP files
Zend/tests/sharp/
├── discovery.phpt a deleted source's file
└── library_autoload_composer_container.phpt new
docs/
├── spec.md section 27: guard, case, exclude,
│ the full VS Code setting
├── decisions/029-typed-compilation.md a deploy's compile
├── decisions/081-discovery.md the same
├── architecture/modules.md when the module is named
└── architecture/slices/sharp-discovery.md the review, found 5, 6
Problem: the prelude now declares Sharp\Container and Sharp\ContainerError, and the names crate's binder test checks its generated list of the class-likes declared in Sharp against the standard library and the prelude, so cargo test failed on every platform. Solution: regenerate the list with the regen-sharp-classes script, so PHP# code names the two engine classes by default, as it names Sharp\Position and Sharp\Listening. sharp/mago/crates/names/src/ └── sharp_classes.rs regenerated: Container, ContainerError
heyJordanParker
added a commit
that referenced
this pull request
Oct 17, 2026
heyJordanParker
added a commit
that referenced
this pull request
Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes found by validating PHP# on a real Laravel app. Design note:
docs/architecture/slices/sharp-discovery.md.The first compile works
On a fresh clone, every PHP process on the engine that loaded
vendor/autoload.phpdied withModule.sharp isn't compiled. Run vendor/bin/mago compile.:vendor/bin/mago compileitself, a mago extension host, and the@php artisan package:discovera stock Laravel app runs fromcomposer install. The plugin'sautoload.phpread the standard library's compiled module as it loaded, since 4567fd6.Sharp\Internal\readModulenow names the library's module, and the container reads it at its first module lookup, before any other module, as it already reads every app module. A request that resolves no service never needs it compiled. The name staysreadModule, becausesharp/bin/spec, which is guarded, writes it into every example's run script.PHP code that lists
*.phpfiles finds PHP# classesSpatie's route attributes, Laravel's console kernel and Laravel's event discovery list a folder's
*.phpfiles and name each class by its path, so they never saw a.sharpclass.mago compilewrites a<Name>.phpbeside each of the project's.sharpfiles that declares a type. It loads the.sharpfile through the engine, and on plain PHP it throws the "needs the PHP# engine" error. It is written before the compile, so every compiled file stays current.<Name>.phpsomeone wrote beside a.sharpfile is a compile error that names both.vendor/and a file in anautoload-devfolder get none. PHPUnit loads a test class only from the file it lists (TestSuiteLoadercomparesgetFileName()), so a test class keeps one file, andphpunit.xmllistssuffix="Test.sharp", as on master.git rev-parse --git-path info/excludenames, so they never show ingit status.Tests
Zend/tests/sharp/library_autoload_uncompiled.phpt:autoload.phploads before anything is compiled, then the container builds a service through the library'sEnvironment. It failed on master with the CompileError.Zend/tests/sharp/discovery.phpt: a directory iterator andglob('*.php')find and load the PHP# class and read its attribute. It failed with the files switched off.sharp/mago/tests/compile.rs, 8 rows: written, kept current, deleted with its source, refused beside a hand-written file, none invendor/, none inautoload-dev, passes lint, every compiled file current (a class that shadows a default included), and the exclude block in a clone and in a worktree.sharp/bin/test --phpunitpasses: PHPUnit runs the PHP# test class in one process and with process isolation.Not in this PR
getClassMap(), never lists a PHP# class, so discovery that reads it instead of folders misses them..phplink to a.sharpfile prints the PHP# source..phpfile.readModule, with the next pull request that changessharp/bin/spec.