Skip to content

feat: modules, with services checked at compile time and resolved by the engine - #121

Merged
heyJordanParker merged 17 commits into
masterfrom
feat/modules
Oct 13, 2026
Merged

heyJordanParker merged 17 commits into
masterfrom
feat/modules

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Design

The full design is docs/architecture/modules.md.

Which classes PHP# creates. The classes a module binds, and the classes that declare an on method, and nothing else, as NestJS, ASP.NET Core, Angular and Guice with requireExplicitBindings() do. A concrete class binds to itself, as transient Checkout = Checkout;. A class no module binds is ordinary code, created with new, such as Money. 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-sharp feat/modules):

  • A module member is a law or a binding: 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.sharp holds the base module. Module.<Environment>.sharp holds an environment module headed module : <its namespace>. Any other file may hold a test module headed module : <the module it overrides>. The standard library's Sharp/Module.sharp serves the root namespace and binds Environment.
  • Each binding is checked where it is written. Its value must be assignable to the service, a class value must be concrete, and for must name a class. One module binds a service and for pair once.
  • Every parameter of a bound class's constructor, of a binding's expression and of a listener class's constructor needs a binding. A class gets a service from its own namespace's modules, then each parent's, then the standard library's. The first module with a binding wins, an override module comes before its base module, and a binding for the 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. A string or other type no binding can give is refused with the expression binding to write, in the binding's own lifetime.
  • The graph is walked from each binding through bindings only. It refuses a cycle and a scoped service held by a singleton. 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.

  • A file whose base or environment modules bind services returns, last, its binding table: [namespace, service id, for class or null, 'singleton'|'scoped'|'transient', value]. The value is a class name, a list of class names, or static fn (params) => expr.
  • A test file's module is the call \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.
  • A constructor or binding parameter that holds a collection of objects carries #[\Sharp\Internal\Service('list<app\pricing\pricerule>')]. Every other parameter's service is its PHP type.
  • A compiled module file, test file or listener file lists among its inputs the Module.sharp of 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's Module.<Environment>.sharp of each. The engine refuses the file after one of them is edited, added or deleted.

Engine. Sharp\Container has get(string $id): mixed, has(string $id): bool and static scope(\Closure $run): mixed.

  • It builds only what a binding binds, and has is true only for a bound id.
  • Before it builds a class, it reads the modules of the class's folder and each folder above it up to the project root. It reads Module.<SHARP_ENV>.sharp before Module.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's autoload.php reads the library's module through Sharp\Internal\readModule.
  • While a test runs, its services are the test file's module over the base modules, with no environment module, even with SHARP_ENV set, which is the set the checker checks. Sharp\Internal\startTest($class) and endTest() 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 to phpunit.xml.
  • It fills constructor and closure parameters from their argument information, with no reflection.
  • Singletons live for the request. Scoped services live for the request or a scope() call. Transient services are built each time.
  • It throws its own failures as Sharp\ContainerError, which extends Error: 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) throws ValueError when the variable is not set, with section 29's message.

PSR-11. Sharp\Psr\Container implements Psr\Container\ContainerInterface over Sharp\Container. It throws Sharp\Psr\NotFoundException for an id no module binds, and Sharp\Psr\ContainerException, with the engine's Sharp\ContainerError as its previous, for a service the container can't build. The Composer package requires psr/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

sharp/mago/crates/                      (subtree merge of mago-sharp feat/modules)
├── syntax, names, semantics            bindings, the parent header, placement
├── codex/src/metadata/module.rs        ModuleMetadata, BindingMetadata, service_id
├── codex/src/scanner/class_like.rs     the standard library's module serves the root namespace
├── analyzer/src/statement/module.rs    each binding, every parameter of a bound class, a binding and a
│                                       listener's class, and the service graph, an environment as one set
├── analyzer/src/statement/class_like/listener.rs   a listener's constructor takes services
├── orchestrator/src/service/incremental_analysis/compile.rs   the module files a compiled file resolves
│                                                              services through are among its inputs
├── prelude/assets/extensions/sharp.php Environment.require
└── sharp-bridge/src/lower.rs           the binding table, a test file's testModule call and its classes'
                                        __sharpStartTest and __sharpEndTest, the Service attribute
ext/sharp/
├── sharp.c                             Sharp\Container, Sharp\ContainerError, Sharp\Internal\{readModule,
│                                       testModule, startTest, endTest}, Environment.require
├── sharp.stub.php                      their public signatures
└── sharp_arginfo.h                     generated
sharp/composer/
├── composer.json                       requires psr/container; Sharp\Psr\ in src/Psr/
├── 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/ContainerException.php      new: Sharp\Psr\ContainerException
└── src/Psr/NotFoundException.php       new: Sharp\Psr\NotFoundException
sharp/phpunit/                          new: a Composer project whose PHP# test class runs under PHPUnit 11.5.57,
                                        as its composer.lock pins it, with sharp/composer/ as its library
sharp/bin/test                          --phpunit: installs, compiles and runs sharp/phpunit/ in one process and
                                        with --process-isolation
sharp/docker/                           the image installs composer, php-xml and unzip
.github/workflows/sharp.yml             LINUX runs sharp/bin/test --phpunit
Zend/tests/sharp/
├── Container.inc                       new: the app the container tests build, with the library's module
├── 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: each Sharp\ContainerError, a constructor that throws through a class,
│                                       a list and a closure, a module that won't load
├── container_test_module.phpt          new: a test file's module while its test runs
├── container_test_environment.phpt     new: no environment module while a test runs
├── container_phpunit.phpt              new: the methods PHPUnit runs around a test, here and in a child process
├── container_psr.phpt                  new: the PSR-11 adapter and its errors
├── library_autoload.inc                the package holds the library's module
├── environment.phpt                    Environment.require
└── project.inc                         a test project's files may sit in folders
docs/
├── spec.md                             sections 15 and 32 say which classes PHP# creates, and what an
│                                       environment's set is; scoped-binding and module-errors name their
│                                       Module.sharp; missing-service's error comes from `transient Checkout = Checkout;`
├── decisions/056-modules.md            matches section 32, with the rejected "any concrete class"
└── architecture/modules.md             the design as built
sharp/baseline/spec/                    every §28 and §32 example leaves, and 17 examples the newer
                                        sharp/mago passes

No file under sharp/harness/ changes.

Evidence

  • sharp/bin/spec with this branch's mago and engine: every §32 example and both §28 laws pass. 179 examples are checked and 86 fail, each one listed.
  • Each of the eight container tests, environment.phpt and 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.
  • LINUX runs sharp/bin/test --phpunit. In sharp/phpunit/, a PHP# test class extends PHPUnit's TestCase and 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 own Before method 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.
  • Each row fails with its code removed: the binding check of a class value, of a list of classes and of a binding's parameters, the library module's root namespace, a listener's services, a non-service parameter, a test module's lookup, the per-test rebuild, leaving the environment modules out of a test, clearing the service a failed build released, Sharp\ContainerError and the adapter's ContainerException, 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.
  • A bound class's value no binding gives gets a help that names the binding's service, as "Bind Mailer to an expression that creates it, as in singleton 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 compile accepts all 107 engine fixtures.

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
@heyJordanParker

Copy link
Copy Markdown
Owner Author

Review verdict: CHANGES NEEDED

Head: d7c39a81da0f98a18842d8297e5737e216399011. I built it in a scratch worktree: the engine with sharp/bin/build, and mago in release with CARGO_PROFILE_RELEASE_LTO=off on Rust 1.97.0.

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: Container::get of a bound class whose constructor throws

Any app crashes when a bound service fails in its constructor, for example when a database is down.

Code

app/Module.sharp

namespace App;

module
{
    transient Ledger = Ledger;
    transient Report = Report;
}

app/Ledger.sharp

namespace App;

import RuntimeException;

public class Ledger
{
    public Ledger()
    {
        throw new RuntimeException("the database is down");
    }
}

app/Report.sharp

namespace App;

public class Report
{
    public Report(private Ledger ledger) { }
    public Ledger usedLedger() => this.ledger;
}

The PHP side runs try { (new Sharp\Container())->get('App\Ledger'); } catch (Throwable $e) { … }.

Today

mago analyze reports No issues found. and mago compile compiles 4 files. The engine then dies inside the try:

Assertion failed: (zval_gc_type((ref)->gc.u.type_info) == 7 || zval_gc_type((ref)->gc.u.type_info) == 8), function gc_possible_root, file zend_gc.c, line 758.
exit 134

Through Sharp\Psr\Container::get, a plain PHP class whose constructor throws ends the process with zend_mm_heap corrupted (exit 139). get('App\Report') survives, because the failed Ledger lands in a local there and not in return_value. It prints get(App\Report) threw RuntimeException: the database is down.

Must

get throws the constructor's exception, and the request goes on.

Fix

sharp_container_build releases the object but leaves the zval pointing at it. Container::get passes return_value as that zval, so the VM releases the object a second time. sharp_container_bound does the same for a list and for a closure's result.

--- a/ext/sharp/sharp.c  (sharp_container_build)
 		if (EG(exception)) {
 			zval_ptr_dtor(object);
+			ZVAL_NULL(object);
 			built = false;
 		}
--- a/ext/sharp/sharp.c  (sharp_container_bound, the list and the closure)
 		if (!built) {
 			zval_ptr_dtor(service);
+			ZVAL_NULL(service);
 		}

Add rows to container_refusals.phpt and container_psr.phpt: a bound class whose constructor throws, asked for directly and through Sharp\Psr\Container.

2. An environment is checked one file at a time, not as one set

Section 32 says "the compiler checks every environment's set of services". Services in analyzer/src/statement/module.rs holds one override module:

fn new(codebase: &'ctx CodebaseMetadata, module: &'ctx ModuleMetadata) -> Self {
    Self { codebase, overrides: (module.kind != ModuleKind::Base).then_some(module) }
}

The engine applies every Module.<SHARP_ENV>.sharp on the folder path at once. So the checker refuses an environment that is complete, and it accepts one that fails at run time.

2a. A valid program is refused

app/Module.sharp

namespace App;

import App.Mail.Mailer;
import App.Mail.SmtpMailer;

module
{
    singleton Mailer = SmtpMailer;
    transient Checkout = Checkout;
}

app/Module.Production.sharp

namespace App;

import App.Mail.Mailer;
import App.Mail.QueueMailer;

module : App
{
    singleton Mailer = QueueMailer;
}

app/Mail/Module.Production.sharp

namespace App.Mail;

module : App.Mail
{
    singleton Queue = Queue;
}

QueueMailer(private Queue queue) is in App.Mail. Checkout(private Mailer mailer) is in App. Production binds Queue for App.Mail, so the Production set is complete. Today mago analyze and mago compile both report:

app/Module.Production.sharp:8:24: error[missing-service]: `QueueMailer` needs a `Queue`, and no module binds one: the container can't build `QueueMailer`.

The message is false: app/Mail/Module.Production.sharp binds one.

2b. A cycle compiles and fails at run time

Take the same base modules, with app/Mail/Module.sharp binding singleton Queue = MemoryQueue;. QueueMailer(private Queue queue) and MailQueue(private Mailer mailer) are both in App.Mail. The two Production modules are:

// app/Module.Production.sharp
module : App
{
    singleton Mailer = QueueMailer;
}

// app/Mail/Module.Production.sharp
module : App.Mail
{
    singleton Queue = MailQueue;
}

Each module alone is fine over the base modules. Today mago analyze reports No issues found. and mago compile compiles 12 files. Then SHARP_ENV=Production, get('App\Checkout') gives:

Error: App\Mail\QueueMailer needs itself, so the container can't build it

Must

Production is checked as one set: the base modules under every Module.Production.sharp. 2a compiles. 2b is refused with service-cycle at a Production binding.

Fix

Group the environment modules by ModuleKind::Environment(name). Services.overrides becomes the list of that environment's modules, and binding_for already filters them by namespace. Walk each environment once over the base bindings it changes. Report each problem at a binding of the file being analyzed. A test module keeps its single override. Add the 2a and 2b rows to an_environment_or_test_module_is_checked_with_the_base_bindings_it_changes.

3. The engine runs a stale compile after a Module.sharp is deleted

A .sharpc file's inputs never name a module file it resolves through. strings .sharp/app/Shop/Module.sharpc lists Module.lean, app/Mail/Mailer.sharp, app/Mail/SmtpMailer.sharp, app/Module.lean, app/Shop/Admin/Panel.sharp, app/Shop/Module.lean, app/Shop/Module.sharp and composer.lock. It does not list app/Shop/Admin/Module.sharp.

Code

app/Shop/Module.sharp

namespace App.Shop;

import App.Mail.Mailer;
import App.Mail.SmtpMailer;
import App.Shop.Admin.Panel;

module
{
    scoped Mailer = SmtpMailer;
    singleton Panel = Panel;
}

app/Shop/Admin/Module.sharp

namespace App.Shop.Admin;

import App.Mail.Mailer;
import App.Mail.SmtpMailer;

module
{
    singleton Mailer = SmtpMailer;
}

app/Shop/Admin/Panel.sharp has public Panel(private Mailer mailer) { }. mago compile compiles 9 files. Then I delete app/Shop/Admin/Module.sharp.

Today

  • mago compile refuses correctly: app/Shop/Module.sharp:10:5: error[captive-service]: The singleton Panelholds the scopedMailer, which would outlive the scope it belongs to.
  • mago analyze --watch reports the same error after the delete. It also reports missing-service at the binding after an edit to Panel's constructor.
  • The engine, before any recompile, runs the stale app/Shop/Module.sharpc. It builds Panel and keeps a scoped Mailer across scopes: Panel built; the singleton's Mailer is the same object in another scope: true. sharp.compile_command never runs, because no input of any file it loads changed.

The same hole covers an edit or an addition. Take a Module.sharp in a folder the request never reads, whose change refuses another module's file. The other module's other bindings keep running.

Must

Each compiled file whose check reads the modules is out of date when any module file it resolves through is edited, added or deleted. That covers a module's file, a test file's module and a listener's file. The engine then refuses the file or recompiles it, as it does for every other input.

Fix

In IncrementalAnalysisService::compile (orchestrator/src/service/incremental_analysis/compile.rs), take each class the module walk and the listener check read. Add as inputs the Module.sharp and Module.*.sharp of its folder and of each folder above it, up to the root. List the ones no file is at as absent, as the Module.lean inputs already are. Add a compile test: a file's inputs name the module files its bindings resolve through, the absent ones included. Also add a watch-mode test for the modules_changed branch of analyze_incremental, which no test covers today.

4. A test in a separate process runs without its test module

Sharp\PhpUnit\Extension starts each test from PHPUnit's Test\PreparationStarted subscriber. PHPUnit's child process (src/Framework/TestRunner/templates/method.tpl) loads the bootstrap file but bootstraps no extension. Facade::initForIsolation also seals a fresh dispatcher with no subscribers. So startTest never runs in the child.

Code

This is PHPUnit 11.5.57 on this branch's engine, with <bootstrap class="Sharp\PhpUnit\Extension"/>. The test file registers the module the compiler emits for module : App.Shop { singleton Mailer = LogMailer; }, and the base module binds singleton Mailer = SmtpMailer;:

#[RunInSeparateProcess]
public function testInASeparateProcess(): void
{
    $mailer = (new \Sharp\Container())->get('App\Shop\Checkout')->usedMailer();
    $this->assertSame('log', $mailer->name());
}

Today

The in-process tests pass. The test module applies, each test builds new services, and the next class gets the base modules. The isolated test fails:

1) Tests\CheckoutTest::testInASeparateProcess
Failed asserting that two strings are identical.
-'log'
+'smtp'

processIsolation="true" in phpunit.xml does the same to every test.

Must

A test gets its test module over the base modules wherever PHPUnit runs it.

Fix

The test has to start from code the child process runs, because no extension runs there. One way is a Sharp\PhpUnit trait with a #[Before] method that calls startTest(static::class) when isInIsolation() is true. That trait adds a public API, so its owner decides it. Otherwise, document that the test module does not apply in a separate process.

Smaller changes

5. A false "No module binds" after a module that won't load

sharp_container_read_folders marks a folder read before its module loads. It keeps reading the folders above while an exception is pending. In issue 3's project, I made app/Shop/Admin/Module.sharp stale and called get('App\Shop\Admin\Panel') twice in one request:

get(App\Shop\Admin\Panel) threw CompileError: app/Shop/Admin/Module.sharp is out of date (app/Shop/Admin/Module.sharp changed). Run vendor/bin/mago compile.
get(App\Shop\Admin\Panel) threw Error: No module binds App\Shop\Admin\Panel

The second message is false. app/Shop/Module.sharp binds Panel and is current, but it was never read. The fix: stop the loop at the first exception, and mark a folder read only after its module loads.

6. The help for a non-service parameter changes the lifetime

transient Report = Report;, where Report takes a string, gets this help:

Help: Bind `Report` to an expression that creates it, as in `singleton Report(…) = new Report(…);`.

report_missing_service hardcodes singleton, so copying the help silently makes a transient service a singleton. Carry the binding's lifetime in Builds::Bound and print it.

7. Errors the engine throws reach PSR-11 callers as plain Error

get('Needy') through Sharp\Psr\Container, where Needy needs a class no row binds, gives Error: No module binds Missing for Needy; ContainerExceptionInterface: false. PSR-11 says exceptions the container throws itself SHOULD implement ContainerExceptionInterface. A cycle and an untyped parameter behave the same way. The fix needs a public API decision: a Sharp\Psr\ContainerException, or an engine error class the adapter can wrap. A bound id, an unbound id, has and NotFoundException already behave as PSR-11 says.

8. Tests

  • Walk::visit's let held = held && binding.lifetime != Lifetime::Singleton; has no row. I replaced it with let held = held; and the 13 module and listener tests still passed. Add a row where a singleton holds a singleton that holds a scoped service: one captive-service error, at the inner singleton.
  • Issues 1 to 4 each need the rows named in their own section.
  • I removed the captive check (let held = false && …) as a control. a_binding_that_needs_itself_or_holds_a_scoped_service_in_a_singleton_is_refused and an_environment_or_test_module_is_checked_with_the_base_bindings_it_changes both went red, as they should.

What passed

  • Bindings. One project had a three-deep chain (SmtpMailer, then Transport, then Socket, then the library's Environment). It also had Mailer for SendReceipt, List<PriceRule> = [TaxRule, DiscountRule], an App.Shop.Admin module that overrides App.Shop's, and Label(Environment environment, QueueMailer queue) = new Label(…). Mailer in App.Mail is bound in App. mago analyze reported No issues found. The engine printed checkout mailer: smtp via transport on socket h1, checkout rules: 2, checkout label: L/queue, receipt mailer: queue and panel mailer: queue label: L/queue.
  • Refusals. Each was reported at the binding. These were a three-class cycle, a singleton holding a scoped service through a transient one, an unbound service, a string parameter, an abstract class value, a list of classes for a non-List service, a duplicate binding, and an unknown for class. An environment module's captive service is reported at its own binding. A test module's missing service is reported in the test file. Placement errors appeared for a header in Module.sharp, a module with no header in a test file, and an environment module naming another namespace. A listener with a bound, an unbound and a scoped service gets one missing-service, at the unbound parameter.
  • Lifetimes. Two requests to php -S built the singleton once per request and the scoped service once per scope. Within a request, the singleton was the same object, the scoped service was the same object, and scope() built a new scoped service.
  • Engine tests. The 8 container_*.phpt files, environment.phpt and the 6 library_autoload* tests pass in all four modes: without opcache, priming the file cache, using it, and shared memory with --repeat 2. That is 15 of 15 in each mode.
  • .php analysis. I ran mago analyze --sort with this head's mago and with master's (b8907a9c1e) over PHPUnit 11.5.57 and its dependencies. The two outputs match line for line over 13,163 lines. The one difference is a .sharp file I placed in that folder by mistake, which master's parser does not know.
  • Spec examples. sharp/bin/spec reports Checked 179 examples, ignored 1, and 88 fail. It matches the baseline, and every section 32 example passes.
  • Engine fixtures. mago compile of the fixtures refuses only CollectionMethods, EnumKeys, Lambdas, Roster and StaticCollections, the five that use Map.delete and filterValues.

# 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
```
@heyJordanParker
heyJordanParker marked this pull request as ready for review October 13, 2026 23:32
@heyJordanParker
heyJordanParker merged commit f208b11 into master Oct 13, 2026
22 checks passed
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
…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
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
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.
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
…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
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
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.
@heyJordanParker
heyJordanParker deleted the feat/modules branch November 3, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant