Repository navigation
feat: modules, with services checked at compile time and resolved by the engine - #121
Conversation
Problem Section 32's modules have no design across the checker, compiler and engine, and decision 56 still describes `Factory<T>`, a static `Environment.require` and `APP_ENV`, which section 32 replaced with binding parameters, an `Environment` method and `SHARP_ENV`. Solution docs/architecture/modules.md draws the mechanism: how the checker reads and checks bindings and the service graph, the binding table each module file compiles to, and `Sharp\Container` in the engine. Decision 56 states the rules section 32 holds. docs/ ├── architecture/modules.md new: the modules design └── decisions/056-modules.md binding parameters, Environment.require as a method, SHARP_ENV
…e, a cycle and a captive scoped service
Problem: a PHP# module could state only laws. Spec section 32 makes it the
place where an app binds its services: each binding names a lifetime, the
service, the services it needs as parameters, an optional `for` class, and a
class, a list of classes or one expression as its value. A binding read
"not supported yet", so no app could wire a single service, and nothing
checked that the container could build what the app asks for.
Solution: the parser reads a binding, the scanner records each module's
bindings in the codebase, and the analyzer checks them as Dagger checks a
graph and .NET's scope validation checks lifetimes:
- a class value must be a concrete class of the service, a list of classes
binds a `List` service, and an expression is analyzed as a lambda over the
binding's parameters that returns the service;
- a class whose main constructor takes an interface or abstract class of the
app needs a binding in a module of its namespace or one above it, the
nearest namespace winning and a `for` binding before any other
(missing-service);
- a service that needs itself is refused (service-cycle);
- a singleton that holds a scoped service, directly or through transient
services and unbound classes, is refused (captive-service);
- an environment module (`Module.Production.sharp`) or a test module names
the module it overrides as `module : App.Shop`, states no laws, and is
checked with the base bindings it changes.
crates/
syntax/
src/cst/cst/module.rs Binding, BindingTarget, BindingValue, BindingClasses, ModuleParent
src/parser/internal/module.rs reads a binding's value as one expression, then classifies it
tests/sharp.rs a binding's parts, a module header
names/src/internal/walker.rs a header, a `for` class and a class value resolve as class names
semantics/src/internal/checker/sharp.rs
which file holds which module; no laws in an override
codex/src/
metadata/module.rs ModuleMetadata, BindingMetadata, Lifetime, BindingValueMetadata (new)
scanner/class_like.rs records each module and its bindings
scanner/function_like.rs an expression binding is a lambda over its parameters
populator/mod.rs populates each binding's service type
analyzer/src/
statement/module.rs the binding, missing-service, cycle and captive checks (new)
statement/return.rs a wrong expression names the binding and its service
code.rs invalid-binding, missing-service, service-cycle, captive-service
fingerprint/src/class_like/mod.rs a module's header and bindings change its fingerprint
orchestrator/src/service/incremental_analysis.rs
a changed module re-analyzes the project
sharp-lean/src/translate/mod.rs an override module states no laws to translate
Problem: the checker accepted bindings, but the compiler dropped every
module, so the engine had nothing to build a service from. A constructor's
`List<PriceRule>` also runs as PHP's `array`, so the engine could not tell
which service such a parameter takes.
Solution: a file whose modules bind services returns their bindings last,
after any class a test file declares beside its module:
return [
['app\shop', 'app\mail\mailer', null, 'singleton', 'App\Mail\SmtpMailer'],
['app\shop', 'app\mail\mailer', 'App\Shop\SendReceipt', 'scoped', 'App\Mail\SmtpMailer'],
['app\shop', 'list<app\pricing\pricerule>', null, 'transient', ['App\Pricing\TaxRule']],
['app\shop', 'app\mail\mailer', null, 'singleton', static fn (\App\Mail\SmtpMailer $smtp) => $smtp],
];
Each row is the namespace the module serves, the service id, the class a
`for` names, the lifetime and the value. A module of laws alone returns
nothing. A constructor or binding parameter whose type is a collection of
objects carries `#[\Sharp\Internal\Service('list<app\pricing\pricerule>')]`,
since the engine reads every other parameter's service from its PHP type.
The service id is one function, `service_id` in codex, which the analyzer,
the table and the attribute share. A binding's expression is checked as a
method's expression body, so it reads its parameters.
crates/
codex/src/metadata/module.rs service_id: a type's id, in lowercase
analyzer/src/statement/module.rs resolves bindings by service_id
semantics/src/internal/checker/sharp.rs
a binding's expression is a body
sharp-bridge/
src/lower.rs module_bindings, the returned table, and the Service attribute
src/lower/types.rs module, constructor_parameters, binding_parameters
tests/lower.rs the table's rows, and which parameters carry the attribute
Problem: section 32's module example creates its RedisStore with
`environment.require("REDIS_URL")`, and section 29 specifies `require`,
but the checker knew only `Environment.variable`, so the example was
refused with "Method `Environment.require` does not exist."
Solution: the prelude's Environment declares
`require(string name): string`, which throws `ValueError` when the
variable is not set. The engine implements it with the spec's message.
crates/
prelude/assets/extensions/sharp.php Environment.require
analyzer/tests/sharp.rs a required variable is a string
…ings Problem: the checker proves every service a class needs has a binding, and the compiler writes each module's binding table, but nothing at run time read those tables, so no app could get a PHP# class built with its services. Section 32's module example also calls Environment.require, which the engine lacked. Solution: Sharp\Container resolves a service as the checker does. Before it builds a class, it reads the modules of the class's folder and of each folder above it up to the project root, the environment module SHARP_ENV names before the base module. The first module with a binding wins, and a binding for the class wins over one for any class. It builds a class through its constructor, or calls a binding's closure, and fills each parameter from the parameter's own argument information, with no reflection. A singleton lives for the request and a scoped service for the scope: the request, or a Container::scope call. A transient service and an unbound class are built each time. A missing service, a class that needs itself and an untyped parameter each throw an Error that names them. Environment.require throws ValueError when its variable is not set, with section 29's message. Two section 32 examples name their Module.sharp, so the harness checks their bindings instead of refusing their placement. Every section 32 example and both section 28 module laws leave the failing list. ext/sharp/ sharp.c Sharp\Container, Environment.require sharp.stub.php their public methods sharp_arginfo.h generated Zend/tests/sharp/ Container.inc new: the app the container tests build container_resolution.phpt new: each kind of binding, nested namespaces container_environment.phpt new: SHARP_ENV's module first container_lifetimes.phpt new: singleton, scoped, scope(), transient container_refusals.phpt new: missing service, cycle, untyped parameter environment.phpt Environment.require project.inc a test project's files may sit in folders docs/ spec.md scoped-binding and module-errors name their Module.sharp architecture/modules.md the design as built sharp/baseline/spec/ 8 entries removed
…sten, and a test file's module reaches the container
Problem: the checker built any concrete class nothing binds through its constructor, and checked the
constructor of every class in the app, bound or not. A class such as `Money`, which code creates with
`new`, got a missing-service error for a parameter no container ever fills. A `string` parameter of a
bound class passed the checker and failed in the engine. A listener whose class takes constructor
parameters was refused as not supported. A test file's module compiled to nothing the container read.
Solution: PHP# creates the classes a module binds, and the class of every `on` listener, a new one for
each event. Each parameter of their main constructors, and of a binding's expression, needs a binding
in the module of its namespace or of one above it. A bound class's error is reported at the binding,
with a note at the parameter. A listener's is reported at the parameter. A parameter the container
can't fill, such as a `string`, is refused with the binding to write. The service graph walks bindings
only. The standard library's module binds what the library gives, such as `Environment`, for the root
namespace, so every class reaches it after its own modules. A test file's module compiles to
`\Sharp\Internal\testModule([...classes], [...bindings])`.
crates/
├── analyzer/src/statement/
│ ├── module.rs every parameter of a bound class, a binding and a listener's class
│ │ needs a binding; the walk visits bindings only; Services::missing
│ └── class_like/
│ ├── listener.rs a listener's constructor takes services; no "not supported yet"
│ └── mod.rs a class's analysis no longer checks its constructor's services
├── analyzer/src/utils/names.rs article(), the "a" or "an" before a name
├── analyzer/tests/sharp.rs every_parameter_of_a_bound_class_or_a_binding_needs_a_binding,
│ a_listener_class_takes_services_its_namespace_modules_bind
├── codex/src/scanner/class_like.rs the standard library's module serves the root namespace
├── codex/src/metadata/module.rs ModuleMetadata::namespace says so
└── sharp-bridge/
├── src/lower.rs a test file's module calls \Sharp\Internal\testModule
└── tests/lower.rs the library's table names the root namespace; a test module's call
# Conflicts: # sharp/mago/.github/actions/setup-lean/action.yml # sharp/mago/.github/workflows/ci.yml
…dule applies while its test runs, and PSR-11 reaches the container
Problem: Sharp\Container built any concrete class it was asked for, so what the engine created and what the
checker checked were two different sets. The spec said the container builds every class. A test file's
module compiled but nothing applied it, the host had no PSR-11 container, and `Environment` reached a
binding only because the container built any concrete class.
Solution: the container builds only what a binding binds, and `has` is true only for a bound id. The
standard library's module binds `Environment` for every namespace, and the library's autoloader reads it
through `Sharp\Internal\readModule`. A test file's compiled `Sharp\Internal\testModule` call records its
module for each class the file declares. `Sharp\Internal\startTest` and `endTest` apply that module first
while one of those tests runs and build every service again for each test, and the library's PHPUnit
extension calls them. `Sharp\Psr\Container` implements PSR-11 over `Sharp\Container`. Sections 15 and 32
say PHP# creates the classes a module binds and the classes that declare an `on` method.
ext/sharp/
├── sharp.c no unbound class; a test's module first; readModule, testModule,
│ startTest, endTest; a cycle names the bound class
├── sharp.stub.php the four Sharp\Internal functions
└── sharp_arginfo.h generated
sharp/composer/
├── composer.json requires psr/container; Sharp\Psr\ and Sharp\PhpUnit\ in src/
├── autoload.php reads the library's module
├── library/Sharp/Module.sharp new: singleton Environment = Environment;
├── src/Psr/Container.php new: Sharp\Psr\Container
├── src/Psr/NotFoundException.php new: Sharp\Psr\NotFoundException
└── src/PhpUnit/Extension.php new: Sharp\PhpUnit\Extension
Zend/tests/sharp/
├── Container.inc the app binds the classes it builds, beside the library's module
├── container_lifetimes.phpt no unbound-class row
├── container_refusals.phpt a concrete class no module binds is refused
├── container_test_module.phpt new: a test file's module while its test runs
├── container_phpunit.phpt new: the PHPUnit extension starts and ends a test
├── container_psr.phpt new: the PSR-11 adapter
└── library_autoload.inc the package holds the library's module
docs/
├── spec.md the rule sentence, section 15's listener sentence, the examples
├── decisions/056-modules.md the same, and the rejected "any concrete class"
└── architecture/modules.md the design as built
sharp/baseline/spec/ drops the 17 examples sharp/mago's newer checker passes, which the
subtree merge of feat/modules brought in
…onment module
Problem: with SHARP_ENV set, a test applied its test module over the environment module, and the checker
checks a test module over the base modules only, so a test ran a set of services nothing checked.
Solution: the container keeps the environment modules apart from the base modules, and leaves them out
while a test runs. Section 32, decision 56 and the modules note say so.
ext/sharp/sharp.c container_environment beside container_bindings; a test skips it
Zend/tests/sharp/
└── container_test_environment.phpt new: under SHARP_ENV=Production, a test gets its test module's
service and the base module's in place of the environment module's
docs/
├── spec.md the test-module line
├── decisions/056-modules.md the same
└── architecture/modules.md the same, and the new test
|
Review verdict: CHANGES NEEDED Head: Four changes block the merge. The first is a crash. The second makes the checker compile wrong under an environment. The third makes the engine run a stale compile. The fourth drops the test module from isolated PHPUnit tests. Smaller changes and the passes follow. 1. Crash:
|
# Conflicts: # ext/sharp/sharp_arginfo.h # sharp/mago/crates/analyzer/src/statement/class_like/mod.rs # sharp/mago/crates/semantics/src/internal/checker/sharp.rs # sharp/mago/crates/syntax/src/cst/cst/module.rs # sharp/mago/crates/syntax/src/parser/internal/module.rs
…k matches what runs Problem - `Container::get` of a bound class whose constructor throws ended the process: the build released the object and left the return value pointing at it, so the engine released it again. - The checker checked each `Module.<Environment>.sharp` alone over the base modules, while the engine applies all of an environment's modules at once. It refused complete environments and passed a cycle across two folders. - A compiled file never named the module files its check resolved services through, so the engine ran a stale module after another folder's module was edited, added or deleted. - A test in a separate PHPUnit process ran without its test module, because PHPUnit bootstraps no extension there. - After a module failed to load, the container marked its folder read and answered "No module binds" for a class that a module above binds. - The help for a non-service parameter always wrote `singleton`, so copying it changed the service's lifetime. - PSR-11 callers got the engine's failures as a plain `Error`. - No row covered a singleton that holds another singleton. Solution - A failed build clears the zval it released, for a class, a list and a closure's result. - An environment module's set is every module of its environment over the base modules. Each file still reports only at its own bindings. - A module file, a test file's module and a listener's file list the `Module.sharp` of each folder their check resolves through, present or absent, and an environment module its environment's modules too. - The compiler gives each class of a test file `__sharpStartTest` and `__sharpEndTest`, marked PHPUnit `Before` and `After` at the highest and lowest priority. PHPUnit runs them in its own process and in a child one, so `Sharp\PhpUnit\Extension` is deleted. A test module that binds nothing still registers. - The container records a module file as read only once it loads, and stops at the first one that throws. - `Builds::Bound` carries the binding's lifetime into the help. - The engine throws its own failures as `Sharp\ContainerError extends Error`, and the adapter wraps it in `Sharp\Psr\ContainerException` with the original as its previous. A constructor's exception passes through. ```text ext/sharp/ ├── sharp.c clear the released service; ContainerError; read each module file once it loads ├── sharp.stub.php Sharp\ContainerError └── sharp_arginfo.h regenerated sharp/composer/ ├── composer.json drops the Sharp\PhpUnit\ mapping ├── src/PhpUnit/Extension.php deleted: the compiled test class starts and ends its tests ├── src/Psr/Container.php wraps ContainerError in ContainerException └── src/Psr/ContainerException.php new: PSR-11's error for a service the container can't build sharp/mago/crates/ ├── analyzer/src/statement/module.rs an environment checked as one set; the binding's lifetime in the help ├── analyzer/tests/sharp.rs the complete and the cyclic environment, a singleton holding a singleton ├── orchestrator/src/service/incremental_analysis/compile.rs module files among a compiled file's inputs ├── orchestrator/src/service/incremental_analysis.rs a watch-mode row for an edited, deleted and added module ├── sharp-bridge/src/lower.rs a test class's __sharpStartTest and __sharpEndTest └── sharp-bridge/tests/lower.rs their nodes, and a test module that binds nothing Zend/tests/sharp/ ├── Container.inc container_load, so a child process loads a compiled project ├── container_refusals.phpt each ContainerError, a constructor that throws, a module that won't load ├── container_psr.phpt each failure through the adapter └── container_phpunit.phpt the methods PHPUnit runs around a test, here and in a child process docs/ ├── spec.md an environment's set is all of its modules ├── decisions/056-modules.md the same └── architecture/modules.md the test methods, the compile inputs, ContainerError, the adapter's errors ```
Problem
The proof that a test module applies under PHPUnit, in one process and in the child process of
`#[RunInSeparateProcess]` or process isolation, ran once in a scratch folder. No check in the repository ran
PHPUnit, so a change to the emitted `__sharpStartTest` and `__sharpEndTest` could break it unseen.
Solution
`sharp/phpunit/` is a Composer project that requires `sharp/composer/` and PHPUnit 11.5.57, pinned in its
`composer.lock`. Its PHP# test class extends `TestCase`, declares a test module, and has a `[Before(priority: 10)]`
method of its own. `sharp/bin/test --phpunit` installs it, compiles it with the `mago` it built, and runs it with the
engine in one process and with `--process-isolation`. The `LINUX` job passes `--phpunit`, and the `sharp/docker/`
image gains `composer`, `php-xml` for Composer's platform check, and `unzip` for its archives. With the emitted
methods removed, both runs fail.
```text
sharp/phpunit/
├── composer.json requires sharp/composer/ by path and phpunit/phpunit 11.5.57
├── composer.lock the pinned versions
├── mago.toml checks app/, tests/ and the library, with vendor/ as context
├── phpunit.xml boots vendor/autoload.php; runs *Test.sharp and *Test.php
├── app/Mail/ Mailer, SmtpMailer, LogMailer
├── app/Shop/ Module.sharp binds SmtpMailer and Checkout; Checkout takes a Mailer
└── tests/
├── Probe.php reads the container for the tests
├── Shop/CheckoutTest.sharp a test module binding LogMailer, in one process and in a separate one
└── Shop/OtherTest.php a test with no test module gets the base modules
sharp/bin/test --phpunit
sharp/docker/Dockerfile composer, php-xml, unzip
sharp/docker/run COMPOSER_HOME under sharp/build/
sharp/.gitignore the fixture's vendor/ and .sharp/, and its tests kept
sharp/README.md --phpunit, the gate and the CI step
.github/workflows/sharp.yml LINUX passes --phpunit
docs/architecture/modules.md the fixture
```
Problem Mago's patch-coverage gate failed on this branch: 16 new lines of the module checks ran under no test. Some were refusals no test reached: a binding to an enum or an abstract class, a bound plain PHP class whose constructor takes an untyped parameter, a walk that reaches its start binding twice, and an environment module in a file with no namespace. The rest could never run, and each was written as an ordinary arm: two `continue`s where the scanner already guarantees an expression binding's value and lambda, a lookup of a bound class the class check had already found, a lookup of each class on a cycle, and the unsupported-construct note of a module. Solution Tests reach each refusal. The impossible arms are gone or say why they can't run: - `check_class_value` returns the class it found, so `check_constructor_services` and its second lookup are deleted. - A walk's path holds each class's declared name, so `report_cycle` prints it without a lookup. - The two arms the scanner rules out, and a module's unsupported-construct note, are `unreachable!` with the reason. ```text sharp/mago/crates/ ├── analyzer/src/statement/module.rs check_class_value returns the class; check_constructor_services │ deleted; the cycle path holds declared names ├── analyzer/tests/sharp.rs an abstract class and an enum bound; a plain PHP class with an │ untyped parameter; a class that needs its own service twice ├── semantics/src/internal/checker/sharp.rs a module's unsupported-construct note is unreachable again └── semantics/tests/sharp.rs an environment module in a file with no namespace docs/architecture/modules.md the image installs composer, php-xml and unzip ```
… help Problem When a bound class takes a value no binding can give, the help told the user to bind that class to an expression. For `singleton Mailer = LegacyMailer;` it said "Bind `LegacyMailer` to an expression that creates it". Doing that changes nothing, because the `Mailer` binding still builds `LegacyMailer` through its constructor. A class in a list value, as in `singleton List<PriceRule> = [TaxRule, CouponRule];`, got the same help for `CouponRule`. Solution `Builds::Bound` carries the binding, so the help names the binding's service and writes the expression that replaces its class value: `singleton Mailer(…) = new LegacyMailer(…);`, and for a list, `singleton List<PriceRule>(…) = [new TaxRule(), new CouponRule(…)];`. There, each class whose main constructor takes parameters shows them as `(…)`. Test rows cover both cases, and each help's fix, with its arguments written, compiles with no refusal. ```text sharp/mago/crates/analyzer/ ├── src/statement/module.rs Builds::Bound(class, binding, span); binding_expression writes the help's value └── tests/sharp.rs Mailer = LegacyMailer and a list with CouponRule, and each help's fix compiled ```
Problem Master gained #110 (constructors), #113 (the verification slice) and #115 (extensions). Four Mago files conflicted with this branch's modules, and the bridge's extension members called `attributes` and `parameter` without the service argument this branch added. The analyzer tests also declared `STANDARD_LIBRARY` twice. Solution Each conflict keeps both sides: the codebase keeps its modules and its extensions, and merges and removes each of them. The warm path reanalyzes when modules or extensions change, and when a namespace's classes change. A compiled file lists its namespace's class files and folder files, and its module files. The semantics checker keeps both `unreachable!` notes. An extension member is no service the container fills, so its attributes and parameters pass `None`. ```text sharp/mago/crates/ ├── codex/src/metadata/mod.rs modules and extensions, both merged and removed ├── orchestrator/src/service/incremental_analysis.rs modules, extensions and namespace classes each reanalyze ├── orchestrator/src/service/incremental_analysis/compile.rs namespace files and module files both inputs ├── semantics/src/internal/checker/sharp.rs the module and extension notes both unreachable ├── sharp-bridge/src/lower.rs an extension member's attributes and parameters take no service └── analyzer/tests/sharp.rs one STANDARD_LIBRARY ```
…s branch Problem #121 landed modules and the container, spec section 32, while #102's CI ran, so #102 conflicts with master again. Solution Merge master. Each conflict keeps both sides, and four places where the features meet are joined: - The engine's globals, stub and Sharp\Internal functions keep both sides. sharp_arginfo.h is generated again from the merged stub. Both sides registered `ext_functions` in MINIT, so the engine warned "duplicate name" for each function. Master's one call stays. - A module member resets the parser's type parameter names, as every other class-like member does. - A binding declares no type parameters, so its scan passes an empty TypeResolutionContext, and its lambda captures no type arguments. A module's comparison follows PHP# rules through `for_dialect`. - A constructor parameter whose type names a type parameter, as `List<TItem>` does, is no service: its objects are of a type each type argument fixes. Before this, it got a `Sharp\Internal\Service` attribute naming a Mago template id. ext/sharp/ ├── sharp.c both sides' globals; one ext_functions registration ├── sharp.stub.php both sides' functions └── sharp_arginfo.h generated from the stub sharp/mago/crates/ ├── analyzer/src/statement/module.rs ComparisonResult::for_dialect(Dialect::Sharp) ├── analyzer/tests/sharp.rs both sides' tests ├── codex/src/scanner/{class_like,function_like}.rs empty TypeResolutionContext for a binding ├── sharp-bridge/src/lower.rs both fields; dropped_service skips a type parameter └── syntax/src/parser/internal/module.rs master's members, with type_parameters_of reset
Brings #121's modules and container. Both sides keep their behaviour: - Environment stays the standard library's `foreign` class. #121 added `require` to the C class, its stub and Mago's prelude stub, which this branch deletes; the library's `require` already throws the same ValueError. The container keeps sharp_environment_variable, which reads SHARP_ENV as getenv() does. - sharp_arginfo.h is regenerated from the merged stub: Container, ContainerError and Sharp\Internal, and no Environment. - decision 56 and docs/architecture/modules.md call `require` on the binding's `Environment` object, and the note no longer lists a C or prelude `Environment.require`. - The library's Module.sharp binds `Environment`, so every fixture that compiles it compiles Environment.sharp too: the analyzer and bridge module tests, Container.inc, whose autoloader loads a Sharp class from the library folder, and library_autoload.inc, whose package gets the library's composer.json so its native body and `@` stay the library's. - issue codes: invalid-effect, foreign-in-static and incompatible-effects beside invalid-binding, missing-service, service-cycle and captive-service.
…eside structs and Map and Set objects
Problem
master gained spec section 32's modules and container, section 26's
extensions, and the warm-compile fix. Both sides changed the same bridge,
scanner, checker and flag code, so 13 files conflicted, and four places
compiled apart but not together.
Solution
Each side's behaviour stays, through one mechanism where both had one:
- A parameter's `Map` or `Set` crosses through `collection_parameters`,
which now takes any parameters, so master's extension members cross a
`Map` as well as a `Set`. master's `set_parameters`, `set_parameter` and
`set_from` go: `collection_parameters`, `collection_hint` and `crossed`
do their job.
- `attributes` takes the one group the lowering adds last: a property's
`#[\Sharp\Crossing]` or master's parameter `#[\Sharp\Internal\Service]`,
each from its own builder over a shared `attribute_group`.
- The test hooks of a test module's file go on a class in `class`, since
`class_members` serves a struct too and the module names only classes.
- `STRUCT` and `REQUIRED` move to flag bits 51 and 52, after master's
extension flags.
- The bridge's `constructor_parameters` for `new` becomes `new_parameters`,
beside master's `constructor_parameters` for the container.
- master's extension call drops the key argument our side deleted with the
key text, and `Key` joins the default class names master moved to
`shadowable_default_classes`.
- Two of master's test-module tests assert their rule rather than "no
method" and "no return anywhere", which every class's generated `parse`
and `tryParse` broke.
- `Stamp.sharp` calls `value.trim()`, as section 26 now requires.
`struct-equality` passes, a struct's `==` calling the new `trim()`, and
leaves the spec baseline.
- `sharp_arginfo.h` is regenerated from the merged stub.
php-sharp
├── ext/sharp/sharp_arginfo.h <- regenerated from the merged sharp.stub.php
├── Zend/tests/sharp/Stamp.sharp <- value.trim()
├── sharp/baseline/spec/§19/struct-equality <- deleted: the example passes
├── docs/architecture/slices/10-structs.md <- names collection_parameters and crossed
└── sharp/mago/
├── scripts/regen-analyzer-issue-codes.php
│ <- both sides' issue codes
└── crates/
├── codex/src/metadata/flags.rs <- STRUCT 1 << 51, REQUIRED 1 << 52
├── codex/src/scanner/ <- register_struct and walk_struct beside modules'
│ bindings; the names binding enum by its module path
├── names/src/lib.rs, internal/walker.rs
│ <- Sharp\Key a default class name
├── semantics/src/internal/checker/sharp.rs
│ <- check_struct_declaration beside check_extension
├── syntax/src/parser/internal/class_like/method.rs
│ <- both doc lines
└── sharp-bridge/
├── src/lower.rs <- collection_parameters for every parameter list;
│ attributes, crossing_attribute, service_attribute,
│ attribute_group; test hooks in class
├── src/lower/inline.rs <- form refuses a Map or Set parameter
├── src/lower/types.rs <- new_parameters
└── tests/lower.rs <- both sides' tests; two test-module asserts narrowed
Brings #110, #113, #115, #118, #121 and #126. Both sides keep their behaviour: - #115 wraps `trim` with the extension `string.trim()` through `[Replaces]`, which this branch retires for the checker's table. The table gains `trim -> Sharp.Text.Text.trim`, and the table's member form renders an extension member on the call's first argument, as #115's wrapper did: `name.trim()`, `name.trim(…)`, `name.trim`, and the class's import only where the file lacks the extension by default. `Sharp\Replaces` leaves the default class names. #115's tests move to the table row. - Every PHP# source master adds calls plain PHP through `global.`: the library's Environment and Text extension, Accessors.sharp, Constructors.sharp, the test fixtures, and the slice notes. - The import check keeps #115's reference to an imported class, so its extensions reach the file. - Issue codes hold both sides': bare-function-call and function-import beside the effect and module codes. - §29 pure-interface joins sharp/baseline/spec again: this branch's example writes through `Files`, which ships with the effect classes.
Design
The full design is docs/architecture/modules.md.
Which classes PHP# creates. The classes a module binds, and the classes that declare an
onmethod, and nothing else, as NestJS, ASP.NET Core, Angular and Guice withrequireExplicitBindings()do. A concrete class binds to itself, astransient Checkout = Checkout;. A class no module binds is ordinary code, created withnew, such asMoney. A listener's class needs no binding: PHP# creates a new one for every event.Checker (
sharp/mago, brought in by subtree merge of mago-sharpfeat/modules):lifetime Service[(parameters)] [for Class] = value;. The value is a class, a list of classes, or one expression over the binding's parameters. Any other member is an error, so a module holds no statements.Module.sharpholds the base module.Module.<Environment>.sharpholds an environment module headedmodule : <its namespace>. Any other file may hold a test module headedmodule : <the module it overrides>. The standard library'sSharp/Module.sharpserves the root namespace and bindsEnvironment.formust name a class. One module binds a service andforpair once.forthe class comes before one for any class. A bound class's missing service is reported at the binding, with a note at the parameter. A binding's or a listener's is reported at the parameter. Astringor other type no binding can give is refused with the expression binding to write, in the binding's own lifetime.scopedservice held by asingleton. Each environment is walked again as one set, the base modules under all of that environment's modules, and each test module over the base modules alone. Each environment or test module file reports, at its own binding, what its bindings take part in.Compiler.
[namespace, service id, for class or null, 'singleton'|'scoped'|'transient', value]. The value is a class name, a list of class names, orstatic fn (params) => expr.\Sharp\Internal\testModule([...the file's classes], [...rows]), even when it binds nothing. Each class of a test file also gets__sharpStartTest, marked#[\PHPUnit\Framework\Attributes\Before(PHP_INT_MAX)], which calls\Sharp\Internal\startTest(static::class), and__sharpEndTest, marked#[\PHPUnit\Framework\Attributes\After(PHP_INT_MIN)], which calls\Sharp\Internal\endTest(). PHP# refuses a member name that starts with__, so no member a test declares takes them.#[\Sharp\Internal\Service('list<app\pricing\pricerule>')]. Every other parameter's service is its PHP type.Module.sharpof its own folder, of each folder of a class its check reads, and of each folder above those, most of them absent. An environment module also lists its environment'sModule.<Environment>.sharpof each. The engine refuses the file after one of them is edited, added or deleted.Engine.
Sharp\Containerhasget(string $id): mixed,has(string $id): boolandstatic scope(\Closure $run): mixed.hasis true only for a bound id.Module.<SHARP_ENV>.sharpbeforeModule.sharp. It reads each module file once per request, stops at a module that throws as it loads, and reads that one again the next time. The library'sautoload.phpreads the library's module throughSharp\Internal\readModule.SHARP_ENVset, which is the set the checker checks.Sharp\Internal\startTest($class)andendTest()apply it and build every service again for each test. PHPUnit calls them through the two methods each test class gets, in its own process and in a child process alike, so a project adds nothing tophpunit.xml.scope()call. Transient services are built each time.Sharp\ContainerError, which extendsError: a missing service, a class that needs itself, an untyped parameter, and a bound class that isn't there. A constructor's own exception passes through unchanged, and the request goes on.Environment.require(name)throwsValueErrorwhen the variable is not set, with section 29's message.PSR-11.
Sharp\Psr\Container implements Psr\Container\ContainerInterfaceoverSharp\Container. It throwsSharp\Psr\NotFoundExceptionfor an id no module binds, andSharp\Psr\ContainerException, with the engine'sSharp\ContainerErroras its previous, for a service the container can't build. The Composer package requirespsr/container^2.0.Problem
Section 32 was all on the failing list. The checker took no bindings, the compiler dropped modules, and nothing at run time built a class with its services.
Solution
No file under
sharp/harness/changes.Evidence
sharp/bin/specwith this branch's mago and engine: every §32 example and both §28 laws pass. 179 examples are checked and 86 fail, each one listed.environment.phptand the six library autoload tests passes in four modes: without opcache, priming the opcache file cache, using it, and shared memory with each test run twice.LINUXrunssharp/bin/test --phpunit. Insharp/phpunit/, a PHP# test class extends PHPUnit'sTestCaseand has a[Before(priority: 10)]method of its own. Under PHPUnit 11.5.57 the test module applies in one process, under#[RunInSeparateProcess]and with--process-isolation, before the test's ownBeforemethod runs, and a test of a file with no test module gets the base modules. With the emitted methods removed, the run fails in one process and with--process-isolation.Sharp\ContainerErrorand the adapter'sContainerException, recording a module read only once it loads, an environment checked as one set, a singleton that holds a singleton, the binding's lifetime in the help, a compiled file's module inputs, the warm run after a module changes, and the emitted test methods and their priorities.Mailerto an expression that creates it, as insingleton Mailer(…) = new LegacyMailer(…);", and for a list,singleton List<PriceRule>(…) = [new TaxRule(), new CouponRule(…)];. Each help's fix, with its arguments written, compiles with no refusal.mago compileaccepts all 107 engine fixtures.