leanfran compiles Lean 4 IR into PHP classes with a Composer runtime. See the backend README for the quick start. Paths in Layout and Conventions are relative to langs/PHP/.
Main.lean implements the leanfran-php CLI. LeanPhp/EmitPhp.lean collects the IR reachable from the roots, emits PHP, and assembles initializers and entry points.LeanPhp/Marshal.lean collects type descriptors and compiles invariant decisions. LeanPhp/Generate.lean emits public types, facade methods, and their descriptor-backed conversions. The implementation class sits in the generated Internal/ directory.bin/leanfran runs the Composer CLI. src/Embed/ scans attributes, reflects PHP models, hashes block dependencies, builds a Lake workspace, and publishes the generated traits and manifests. tests/Embed/ and tests/fixtures/embed/ exercise the embedding workflow.src/Model.php declares #[Model]. src/Verify/ discovers modeled functions with nikic/php-parser, resolves signature types, translates bodies and obligations, invokes Lean's proof checker, and maintains leanfran.lock. LeanPhp/Check.lean compares proof types and checks axiom dependencies. src/lean/LeanPhpLib/Php.lean defines the modeled PHP operations.src/Verify.php runs property tests against the generated Lean specifications. It shares signature resolution with the translator, while src/Verify/Inputs.php samples boundary and seeded random values. tests/fixtures/verify/ holds the proof, differential, and property test fixtures.src/Schema/, src/Marshal.php, and src/Json.php implement the public descriptor, value conversion, validation, and JSON representations. src/Valinor.php adapts validation exceptions for an optional mapper.src/Runtime/ contains Lean's C ABI functions as namespaced PHP functions. The autoload.files list in composer.json loads them. phpstan-types.neon defines the runtime value type shared by container, scalar, and closure code.LeanPhp/RuntimeExterns.lean is the generated inventory of runtime symbols. The compiler checks the symbols a job needs before emitting PHP.LeanPhpTest/Vectors.lean and Io.lean contain differential fixtures. The corresponding Lake executables run the native C oracles. LeanPhpTest/Control*.lean covers IR constructors, call depth, and complexity. tests/Differential/ holds PHP drivers, tests/Runtime/ holds PHPUnit tests, and test-out/ holds generated test artifacts.LeanPhpTest/Public*.lean, LeanPhpTest/Json.lean, and tests/Public/ cover public wrappers, JSON, JSON Schema, and Valinor. tests/Public/schema/typescript.json records schemas generated by the TypeScript backend from the same Lean modules.make/ register checks through CHECK_TARGETS. ../../maint/PHP/ holds the oracle, fuzz, and extern scripts and the PHPStan path configuration. samples/ includes an internal entry point, a generated CLI, a public pricing example, embedded applications, and verified PHP functions.lean-toolchain selects Lean for the compiler and the C oracle. Use the Lean sources and lean.h to check the C symbol, argument order, erased parameters, and ownership when implementing an extern. Increment a retained value read out of a container, and leave borrowed arguments owned by the caller.LeanPhpTest/Vectors.lean or Io.lean. Register a new IO case in ../../maint/PHP/test-io.sh with its expected exit status. The differential check compares stdout, stderr, and status with the C oracle. The IO check also compares the resulting files.autoload.files, run make gen-externs in the PHP shell, and commit the generated LeanPhp/RuntimeExterns.lean with the runtime change. make externs-check regenerates the list for comparison.generatorVersion in Main.lean and regenerate the checked-in classes under samples/. Raise Lean::GENERATOR_VERSION in src/Lean.php to the same version. The embedded block manifests include this version in their hashes. make test compares test-out/samples/LeanSumTo.php with the checked-in sum-to class. make pricing-fixture regenerates the pricing classes in test-out/samples/pricing/ for comparison with samples/pricing/src/_lean/. Review the generated PHP files before copying them into the samples.declare(strict_types=1); in handwritten PHP. Mago formats the runtime, tests, and maintenance scripts. PHPStan checks src/, generated public types and facades, their tests, and the pricing sample at level max. It reads the generated Internal/ classes for symbol and signature discovery. make test-static-docs expects five type errors from a separate consumer fixture with invalid arguments.src/Embed/Models.php and the PHPDoc subset in src/Embed/PhpDocType.php. The compiler emits model descriptors for the user class, with Lean deciders for imported constraints. make test-embed compares the embedded fixture with the C backend. make test-embed-samples runs the embedded samples and compares their checked-in files with a fresh sync. make test-embed-static analyzes the fixture and samples at level max, with their generated internal classes available for symbol discovery.tests/fixtures/verify/ and the operation tests in tests/Verify/. Keep PHPDoc constraints out of verification assumptions. If translation dependencies change, update the inputs hashed by src/Verify/Lock.php.tests/fixtures/verify/pbt/. make test-verify-pbt uses the same generated specs as make test-verify. It runs PHPUnit after the shared verify-fixture prerequisite.make test-schema uses the committed TypeScript output. Run make schema-oracle-check in the PHP Nix shell to regenerate it with the TypeScript Nix shell and compare all three targets. Review a changed oracle before copying test-out/schema/typescript.json to tests/Public/schema/typescript.json.suggest and their test dependencies in require-dev. The pricing sample installs just conao3/leanfran and verifies the public API in that environment.From the repository root, run both PHP versions with the root Makefile.
nix shell nixpkgs#gnumake -c make check BACKENDS=PHP
nix shell nixpkgs#gnumake -c make format-check BACKENDS=PHP
nix build .#php
The check runs differential, numeric, depth, complexity, IR coverage, and fuzz tests, plus PHPUnit, PHPStan, the extern inventory comparison, proof state and freshness checks, property tests, and the samples. The verified samples require all their obligations to be proved and compare their runtime output and checked-in generated PHP. The named shells .#php and .#php85 provide PHP 8.4 and 8.5 with matching Composer, PHPStan, and PHPUnit. Select the shell when running a backend target directly.
nix develop .#php -c make -C langs/PHP gen-externs
nix develop .#php85 -c make -C langs/PHP test
The PHP Publish job snapshots the tagged checkout into the root of the read-only mirror conao3/leanfran-php, updates its main branch and applies the same vX.Y.Z tag. Packagist reads the mirror's Composer manifest and tags for conao3/leanfran. For the first release, set PHP_MIRROR_DEPLOY_KEY in the packagist environment so Publish can push the first snapshot. Once the mirror has the snapshot, register https://github.com/conao3/leanfran-php on Packagist and set PACKAGIST_USERNAME and PACKAGIST_API_TOKEN in the same environment. If the initial run stopped at the registry step, rerun Publish with the same tag. To exercise the snapshot, tag retries, and Composer installation with a local bare mirror, run nix develop .#php -c make -C langs/PHP test-publish.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |