Repository navigation
fix: each compiled file names the native fingerprint its library was built for - #169
Merged
Merged
Conversation
Problem: since #160, mago compile writes a <Name>.php beside each .sharp file. Inside Composer's own process, autoload.php skipped requireNative so composer install runs on any engine, and only the plugin's loader checked the engine. Composer's own loader includes the .php file, which loads the .sharp file directly, so a post-autoload-dump callback ran PHP# code on an engine the installed library does not match, until it reached a missing native body. Solution: the engine keeps the refusal requireNative throws, and refuses every .sharp file the request loads after it with the same message, whatever loads it. autoload.php calls requireNative in Composer's process too and ignores its refusal there, so composer install still runs and only PHP# code fails. ext/sharp/ └── sharp.c native_refusal: requireNative keeps its refusal, sharp_compile_file throws it sharp/composer/ └── autoload.php requireNative runs in Composer's process, its refusal ignored there Zend/tests/sharp/ └── library_autoload_composer_container.phpt a mismatched library is refused through the .php file, the container and a require, also preloaded docs/ ├── decisions/081-discovery.md the .php file meets the same refusal ├── architecture/modules.md the test's new rows └── architecture/slices/sharp-discovery.md found-not-fixed 6 is fixed
…built for #169's review found three paths that still ran PHP# code on an engine the installed library does not match: composer --no-plugins, a file opcache already caches, and composer update to such a library in one run. One rule closes all three, whatever loads the file. - mago compile writes the library's native fingerprint, from its native.php, and the version installed.json lists into each .sharpc header, now 128 bytes. - sharp_check refuses a compiled file whose fingerprint is not SHARP_NATIVE. Every loader reaches it, and opcache's revalidation through sharp_compiled_revision. - The per-request refusal and the per-body check are gone. requireNative keeps its three arguments, so engines and libraries of any version refuse each other. - The Composer plugin calls requireNative at each post-autoload-dump, before its early return, and prints the refusal as an error line. Composer goes on. - The refusal names both versions and the two fixes.
patch-coverage found no test that runs header()'s refusal of a version text outside the texts section.
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.
Closes a path #160 opened: inside Composer's own process, PHP# code ran on an engine the installed standard library was not built for.
The problem
mago compilewrites a<Name>.phpbeside each.sharpfile since #160. Inside Composer's own process,autoload.phpskipsrequireNative, socomposer installruns on any engine. Composer's own loader includes the.phpfile, which loads the.sharpfile directly. So apost-autoload-dumpcallback ran PHP# code on a mismatched engine.The first version of this PR kept
requireNative's refusal for the request. Its review found three paths that still ran PHP# code:composer --no-plugins dump-autoload, where nothing callsrequireNative.composer updateto a mismatched library in one run. Composer skips the newautoload.php, so the run only said "out of date".The fix
One rule closes all three, whatever loads the file.
mago compilewrites the library's native fingerprint, from itsnative.php, and the versioninstalled.jsonlists into each.sharpcheader, which grows from 104 to 128 bytes. A project without the standard library writes an all-zero fingerprint.sharp_checkcompares the fingerprint withSHARP_NATIVE. Every loader reachessharp_check, and opcache reaches it when it revalidates a cached file, throughsharp_compiled_revision.requireNativekeeps its three arguments, so an engine and a library of any two versions refuse each other with the engine's message. Outside Composer,autoload.phpstill calls it first.post-autoload-dump, before its early return, and prints the refusal as an error line.composer updateruns the new version's plugin, so the refusal names the new version at once. Composer still exits 0.The refusal names both versions and the two fixes:
When both are the same version, it says they were built from different sources: rebuild the engine, or reinstall the library. When Composer reports no version, it names only the engine's.
Opcache
opcache.revalidate_freq. The file cache validates on load whenopcache.validate_timestampsis on. Both callsharp_compiled_revision, which runssharp_check.opcache.validate_timestamps=0never revalidate any file, by opcache's design. They only serve op arrays this engine'ssharp_checkaccepted. A mismatch needs a new.sharpcon disk, which a revalidating cache sees, and the next restart preloads throughsharp_checkagain.Tests
Each new row failed first, with the check switched off.
Zend/tests/sharp/library_autoload_composer_container.phptruns apost-autoload-dumpcallback on a matching and a mismatched library. It runs without opcache, under opcache preloading, and with--no-plugins. On the mismatched library,App\Greetingthroughapp/Greeting.php,Sharp\Container, the plugin's loader,requireandrequire_onceeach refuse.Zend/tests/sharp/native_fingerprint_opcache.phptcaches a file in the CLI file cache and in a server's shared memory. After a compile against other native bodies, both refuse it.Zend/tests/sharp/library_autoload_composer_plugin.phptdrives the plugin'sdumpClassMapand checks the error line.sharp/mago/tests/compile.rschecks thatmago compilewrites the fingerprint and the version. It also checks that a library with nonative.phpwrites none, and that anative.phpwith no fingerprint fails the compile.require_native.phptand thelibrary_autoload_*tests expect the new messages.refusal_damaged.phptrefuses a version text past the texts.A real Composer ran on the review's fixtures:
mm, the mismatched project:composer --no-plugins dump-autoloadrefuses at the.phpfile, atrequireand atrequire_once.composer install,dump-autoloadanddump-autoload --optimizeexit 0 and print the refusal.up,composer updatefrom 0.3.1 to 0.3.2 prints the refusal and exits 0.fc, a file cached at 0.3.1 is refused after the update and the compile. This holds for the CLI file cache and for php-fpm's shared memory in the same worker.okandfx2, the matching projects, nothing changed.okprintshelloin Composer's process andno greetingin a separate one.fx2printsno greetingin both.