Repository navigation
feat: every host runs one app per worker and one scope per unit of work - #136
Merged
Merged
Conversation
A PHP# app runs under php-fpm, the CLI, FrankenPHP and Octane, and a long-running host serves many requests from one PHP request. Under a FrankenPHP worker, ext/sharp's RINIT runs once per worker thread, so a scoped service reaches every later HTTP request. The engine's Container::scope crashes when a Fiber suspends inside it, and no PHP# code can call it, because a method that takes a function refuses every argument that has an effect until section 29's uses f holds. docs/architecture/slices/32-hosts.md records what ran on master, Jordan's answers, team-lead's decisions, every rule this slice changes or adds with its state and mechanism, the Scope API, how ext/sharp keeps a scope per fiber, and the files the slice changes. docs/architecture/slices/ └── 32-hosts.md new: the design of section 6's statics and section 32's hosts
Problem: spec section 29 lets a method write `uses f` for one of its
function parameters, so that each call has the method's own effects plus
the effects of the function passed as f. The checker parsed the clause and
then held the argument to f's type: a lambda with any effect, passed where
`Function<T()>` is declared, was refused with invalid-argument. A
`Scope.run(body) uses body` written in the library would refuse every real
request handler.
Solution: the scanner marks each parameter a method's `uses` names with
USES_PARAMETER. An argument for such a parameter meets its type with no
effect list, and no function value records it. Each call of the method, a
constructor, or a method without a body adds the passed function's effects
through the path plain PHP callbacks already take: a lambda runs inline, a
method value calls its method, and a function value has its type's effects.
A call of f inside the body adds nothing, since each caller adds what it
passes, so `uses g` forwarding f to another `uses` parameter carries it on.
A method value of a method without a body now has the effects its `uses`
lists wherever it runs, as a call of it does.
sharp/mago/crates/
├── names/src/binding.rs MethodParts::uses_parameter
├── codex/src/
│ ├── metadata/flags.rs USES_PARAMETER
│ └── scanner/function_like.rs marks the parameters
└── analyzer/
├── src/invocation/analyzer.rs no effect list at a uses parameter
├── src/effects/summary.rs each call adds the passed function
└── tests/sharp.rs two tests
Problem: a long-running host, such as FrankenPHP's worker mode or Octane, serves many HTTP requests from one PHP request, so every scoped service was built once and reached every later request. PHP# code had no call to start a scope. Plain PHP's Sharp\Container::scope kept the scope in one global it restored in call order, so a Fiber that suspended inside it made the main code build from the fiber's scope, and a later get read a destroyed table (a segmentation fault). Solution: the standard library's Scope.run(body) uses body runs body in a new scope through Sharp\Internal\runScoped, which replaces Container::scope. A scope is a refcounted table with an ended mark. Each fiber context holds the scope it started in and the one it runs in, in a reserved slot that the fiber observers fill, so a fiber started inside a scope belongs to it and its own Scope.run is its own. Resolving a scoped service after its scope ended throws Sharp\ContainerError. PHP's request stays the default scope. ext/sharp/ ├── sharp.c sharp_scope, the fiber slot, runScoped ├── sharp.stub.php runScoped in place of Container::scope └── sharp_arginfo.h regenerated sharp/ ├── composer/library/Sharp/Scope.sharp └── mago/crates/prelude/assets/extensions/sharp.php runScoped Zend/tests/sharp/ ├── scope_run.phpt 15 rows ├── scope_fibers.phpt 12 rows ├── container_lifetimes.phpt its scope rows move to scope_run └── Container.inc copies Scope.sharp
Problem: the engine interns a type first read from input, or made by a substitution such as Node<List<T>>, in the PHP request's own tables, which request end frees. Under a long-running host the PHP request is the whole worker, so those tables live for the app. The app's own types are bounded by its program and reused on every request, as C# keeps each generic instantiation it makes at run time for the process's life. Input that invents new type texts grew them without limit: on master, one request that unserializes 65,536 new texts exhausts the 128 MB memory limit. Solution: the request's two tables hold at most 65,536 types together. Past that, a new type text from unserialize fails as other bad input does, and a new substitution throws an Error, while every type the tables hold keeps working. A type code spells always interns, since its source bounds those. ext/sharp/sharp.c SHARP_TYPE_APP_LIMIT Zend/tests/sharp/type_arguments_limit.phpt the limit, over two requests Zend/tests/sharp/type_arguments_requests.phpt its title names php-fpm
Problem: PHP# shipped one runtime image, php-fpm's, so no image ran a PHP# app under FrankenPHP, and nothing linked the engine into FrankenPHP at all: ext/sharp put libsharp.a in EXTRA_LIBS, which php-config --libs exports, so FrankenPHP's link looked for /usr/src/php/ext/sharp/target/release/libsharp.a and failed. Solution: ext/sharp adds libsharp.a to PHP_GLOBAL_OBJS, as build/php.m4 adds the DTrace objects, so it links into every SAPI and libphp, and php-config no longer names it. sharp/docker/runtime/frankenphp.Dockerfile builds the engine with docker-library's 8.5/trixie/zts recipe and --enable-embed, then runs FrankenPHP v1.13.0's own Dockerfile stages on it, with Go 1.27, e-dant/watcher 0.14.5 and install-php-extensions 2.12.0 at fixed releases. ext/sharp/config.m4 sharp/docker/runtime/frankenphp.Dockerfile
Problem: the example's last error was the harness Cart's missing `total`,
which `carts.map(c => c.total)` reads, so it stayed on sharp/baseline/spec.
Solution: the harness Cart gains `public int total { get; set; } = 0;`, and
the example leaves the baseline. sharp/bin/spec: 197 examples checked, 1
ignored, 33 fail, each on the baseline.
sharp/harness/app/Cart.sharp
sharp/baseline/spec/§29/function-effects removed
Problem: under sharp/bin/test --repeat, run-tests.php runs a test twice in one process and removes the CLI's "Executing for the first time..." and "Finished execution, repeating..." lines from its output. type_arguments_limit printed those lines from its own child, so that mode lost them and failed. Solution: the test renames its child's lines before it prints them. Zend/tests/sharp/type_arguments_limit.phpt
Problem: nothing ran a PHP# app under a real host, so no check showed what a scoped service, a singleton, a static or the type tables do across HTTP requests under php-fpm or FrankenPHP's worker mode, and no build made the thread-safe engine those hosts link. Solution: sharp/bin/build --zts builds with --enable-zts, --enable-embed and --disable-zend-signals in sharp/build/<os>-<arch>-zts and installs it into its install/ folder, and sharp/bin/test --zts tests it, with the other build's mago. Every build gains php-fpm. sharp/bin/hosts builds FrankenPHP v1.13.0 with Go against the installed libphp, serves sharp/hosts from php-fpm and from FrankenPHP's worker mode, and compares each host's requests with sharp/hosts/expected/: the lifetimes twice, /types 1,000 times with memory the same after the 1,000th request as after the 2nd, /flood past the type limit, then /types and / still working. Four FrankenPHP workers then serve 400 requests, 32 at once, in one process. The dev image gains Go 1.27 and libfcgi-bin's cgi-fcgi. sharp/ ├── bin/ │ ├── build --zts, php-fpm, an install/ prefix │ ├── test --zts │ └── hosts new ├── docker/ │ ├── Dockerfile Go, cgi-fcgi │ └── run GOPATH ├── hosts/ the fixture │ ├── app/Hosts/ Report, Visit, Counter, Box, Module │ ├── expected/ php-fpm.txt, frankenphp.txt │ ├── public/index.php php-fpm's entry │ ├── worker.php FrankenPHP's worker, one Scope.run per request │ ├── serve.php what each path prints │ ├── Caddyfile one worker on :8080, four on :8081 │ ├── php-fpm.conf │ ├── composer.json, composer.lock, mago.toml └── .gitignore the fixture's vendor/ and .sharp/
…h images Problem: CI built and tested only the non-thread-safe engine, which no threaded host runs, ran no host, and published only the php-fpm image. Solution: LINUX_ZTS builds with sharp/bin/build --linux --zts and runs every mode, the JIT passes included, since Linux has a thread-safe JIT. HOSTS runs sharp/bin/hosts --linux against what LINUX and LINUX_ZTS built: LINUX keeps its php-fpm and mago, and LINUX_ZTS its installed engine, each as a tar artifact, so HOSTS builds no engine. CI_PASSED needs both. IMAGE becomes a matrix over sharp/docker/runtime/Dockerfile and frankenphp.Dockerfile, tagged <version> and <version>-frankenphp. .github/workflows/sharp.yml
Problem: section 6 said a static's initial value runs when a request first uses its class's statics, which is wrong under a long-running host, where one app serves many requests. Section 32 said the host starts and ends each scope, and named no way to do it, nor what a fiber does inside one. Solution: section 6 says a static lives as long as the app runs, what that is under php-fpm and under a long-running host, and that a host with several workers runs one app in each. Section 32 gains Scope.run, with the example host-scope, and the rule that a scope follows the fiber that runs in it, with the example scope-fibers. sharp/bin/spec: 199 examples checked, 1 ignored, 33 fail, each on the baseline, and both new examples pass. docs/spec.md sharp/harness/app/Jobs/ ├── Job.sharp host-scope's jobs └── JobQueue.sharp and their queue
Problem: a method value passed where code runs it, to a `uses f` parameter or to plain PHP such as global.call_user_func, recorded a call only when PHP# declared the method. A plain PHP method value, as `this.meter.read`, added no effect, so a law that reached `Meter.read` through one passed although its extern declares `uses Clock`. patch-coverage also found the new branch for it unreached. Solution: such a method value has the effects its extern declares, or Unknown without one, as a call of the method has, and a prelude stub's none. sharp/mago/crates/analyzer/ ├── src/effects/summary.rs method_value └── tests/sharp.rs a_plain_php_method_value_has_its_extern_s_effects_where_it_runs
Problem: every Scope.run row called it from plain PHP, so nothing showed that a PHP# caller gets T with no cast, that the library's own Scope.sharp analyzes clean, or that its `uses body` gives the caller the body's effects. Solution: the checker test reads sharp/composer/library/Sharp/Scope.sharp as shipped. A pure body keeps a law pure, and a body that calls Environment.require makes the law that reaches it impure. Without `uses body` the same test fails, with the lambda refused. scope_run.phpt gains a PHP# method that returns Scope.run's value. sharp/mago/crates/analyzer/tests/sharp.rs scope_run_returns_what_its_body_returns_and_has_its_effects Zend/tests/sharp/scope_run.phpt Tally.bumpInScope
…host
Problem: the docs said a singleton and a static live for the request, named
Container::scope, which this branch deletes, and a php-sharp/laravel adapter,
which PHP# no longer ships. Nothing said how long a run-time type lives under
a worker, what limits it, how to build the ZTS engine or run the hosts
fixture, or what v1 is.
Solution: decision 78, Hosts, records the lifetimes under every host,
Scope.run, the scope that follows its fiber and the type limit, with C#'s
run-time generic instantiations as the precedent. Decision 56 is superseded
in part by it, as decision 34 is by 76. modules.md and 06-properties.md say
"as long as the app runs" and "once per app". 11-generics.md states how long
each type table lives and the 65,536 limit beside the tables. Both READMEs
name the FrankenPHP image, Scope.run, --zts, sharp/bin/hosts, LINUX_ZTS and
HOSTS. docs/v1.md states the v1 Goal. 32-hosts.md records what the build
found.
README.md
docs/
├── v1.md new: the v1 Goal
├── decisions/
│ ├── 056-modules.md superseded in part by decision 78
│ └── 078-hosts.md new
└── architecture/
├── modules.md Scope.run, the fiber scope, the new tests
└── slices/
├── 06-properties.md once per app
├── 11-generics.md how long a run-time type lives
└── 32-hosts.md decision 9 as Queue 4 set it, the files, what the build found
sharp/README.md
… runs Problem: two places decided what a method value runs. record_function_values held a method value to a function type's effects with the whole rule: a foreign class's effect, a bodyless method's `uses`, a PHP# body, a prelude stub's none, a plain PHP method's extern. The Recorder's method_value, which a `uses f` call and a call into plain PHP run, kept its own copy of part of it, and patch-coverage found that copy's prelude branch unreachable by any test, since the checker refuses a method value of a prelude object. Solution: method_value_runs holds the rule, and both places call it, so a method value has the same effects where a function type holds it and where code runs it. A test pins a foreign class's method value run through `uses f`. Every line the pull request adds to summary.rs now runs under cargo llvm-cov of the analyzer's PHP# tests. sharp/mago/crates/analyzer/ ├── src/effects/summary.rs method_value_runs, from record_function_values; method_value calls it └── tests/sharp.rs a_method_value_of_a_foreign_class_has_its_effect_where_it_runs
Problem: #136's review found that a pure caller could pass a static method value to code that runs it. `Scope.run(Job.ping)` and `global.call_user_func(Job.ping)` gave the pure `Runner.go` none of `Job.ping`'s effects, although `Job.ping` emits. The Recorder found a method value only as a property read from an object, and `Job.ping` is read from a class, so it never reached method_value_runs. Solution: method_value reads the methods from the method value's type, which names each method the analysis resolved it to, and runs each through method_value_runs. The object it is read from, if any, is the receiver. So passed_function and prelude_stub_call give an instance and a static method value the same effects. met_parameter_type is renamed effect_free_parameter_type, as the review asked. Both rows of the new test failed before the change, with no issue reported. sharp/mago/crates/analyzer/ ├── src/effects/summary.rs method_value reads the method value's type ├── src/invocation/analyzer.rs effect_free_parameter_type └── tests/sharp.rs a_static_method_value_has_its_method_s_effects_where_it_runs
Problem: #136's review found two ways a long-running host failed a request that should work. - The container kept the services it was building in one table for the request. A fiber that suspended in the middle of a build, as a constructor that waits on I/O does, made every other fiber's build of that service throw "needs itself", under every lifetime, and a fiber never resumed held it for the rest of the request. - The 65,536 limit counted every request type. Once input had filled it, a type the program's own code makes for the first time, as `new Box<List<T>>` for a new T, threw in the same worker. The program bounds those types, as C# bounds its run-time generic instantiations, so they need no limit. Solution: - sharp_fiber_scopes (was sharp_fiber_scope) holds each fiber's `building` table beside `started_in` (was `start`) and `current`, and frees it with the fiber. Two fibers that finish one service at once each get the one kept first. sharp_running_fiber_scopes() returns the running fiber's, and the main context's are SHARP_G(container_main_scopes). The review named the function sharp_fiber_scopes(), which C refuses beside a type of that name. - sharp_type_intern takes a sharp_type_source: code, a substitution, or input. Only types input makes count toward SHARP_TYPE_INPUT_LIMIT (was SHARP_TYPE_APP_LIMIT), in SHARP_G(request_input_types). - Rows, each seen failing on the engine before the change: scope_fibers_building.phpt under scoped, transient and singleton, and a fiber never resumed; type_arguments_limit.phpt's new substitution after the flood in the CLI; and the fixture's /words after /flood in the same FrankenPHP worker. ext/sharp/sharp.c Zend/tests/sharp/ ├── scope_fibers_building.phpt new └── type_arguments_limit.phpt a substitution past the input limit works sharp/ ├── bin/hosts requests /words after /flood └── hosts/ ├── app/Hosts/Box.sharp Box.words ├── serve.php /words └── expected/ /words prints App\Hosts\Box under both hosts
Problem: decision 78, the hosts note, the generics note and modules.md said
the limit counted every run-time type and a substitution past it threw, and
modules.md did not say a fiber holds its own builds.
Solution: each says what the engine now does, with the fixture's /words row.
docs/
├── decisions/078-hosts.md
└── architecture/
├── modules.md
└── slices/
├── 11-generics.md
└── 32-hosts.md
sharp/README.md
Problem
A method had a function's effects only when its declaration wrote `uses f`,
so every method that takes a function repeated its parameter's name, and one
that forgot it refused every function with an effect. Scope.run wrote
`uses body`. Nothing stopped a method from storing the function it was given,
so its effects could run later, where no caller saw them.
Solution
Jordan's answer to Queue 6 item 1 replaces `uses f`, as Swift's `rethrows`
and Kotlin's inline lambdas do:
- A PHP# function parameter whose type states no effects takes on the
effects of each function a call passes. The scanner marks it
TAKES_ON_EFFECTS (was USES_PARAMETER). A promoted constructor parameter is
its field, so it takes none on.
- Such a parameter never escapes the call. effects/check.rs refuses it, or a
local or a lambda that holds it, stored in a field, a collection or a new
object, returned, or passed where it may be kept. The error names the type
the place states, as `Function<string() uses Environment>`, or the
parameter's type with `uses …`.
- A parameter whose type states its effects keeps them as a cap.
- A function parameter in `uses` is a compile error that says to delete it.
- Scope.run drops `uses body`. Decision 79 supersedes decision 6, and spec
section 29 holds Jordan's specimen. sharp/bin/spec keeps its `uses`
signature rule, since it changes only in a pull request of its own.
docs/
├── spec.md section 29's function parameters
├── decisions/006-function-argument-effects.md superseded by decision 79
├── decisions/078-hosts.md Scope.run takes on body's effects
├── decisions/079-function-parameter-effects.md new
└── architecture/ modules.md, spec-examples.md, slices 29 and 32
sharp/
├── composer/library/Sharp/Scope.sharp no `uses body`
├── harness/app/Holder.sharp new: the function-effects example's class
├── spec-self-test.md uses-signature expects the new error
└── mago/crates/
├── names/src/binding.rs takes_on_effects, uses_function_parameters
├── codex/ TAKES_ON_EFFECTS
├── semantics/ a function parameter in `uses` is refused
├── analyzer/src/effects/check.rs report_escaping_functions
├── analyzer/src/effects/summary.rs names follow the rule
├── analyzer/src/invocation/analyzer.rs names follow the rule
├── analyzer/src/statement/class_like/method.rs runs the escape check
├── analyzer/tests/sharp.rs rows; tests that stored a function state its effect
└── sharp-bridge/tests/lower.rs sources that stored a function state its effect
Zend/tests/sharp/Nulls.sharp the function a field keeps states its effect
Problem Queue 8 says a function parameter left in a method's `uses` is a parse error that says to delete it. 20a84c2 refused it in semantics, as a compile error. Solution The method parser refuses each name in `uses` that names a function-typed parameter, nullable or not, with or without a body, with FunctionParameterInUsesInSharp: "`f` is a function parameter, and a method takes on the effects of each function it is given, so `uses` names no parameter: delete it." Semantics keeps only the rule that a method with a body names no effect, and MethodParts loses uses_function_parameters. sharp/mago/crates/ ├── syntax/src/error.rs FunctionParameterInUsesInSharp ├── syntax/src/parser/internal/class_like/method.rs refuses it ├── syntax/tests/sharp.rs its rows ├── names/src/binding.rs uses_function_parameters deleted ├── semantics/src/internal/checker/sharp.rs the body rule alone └── semantics/tests/sharp.rs the body rule's rows sharp/spec-self-test.md uses-signature expects the parse error docs/ spec section 29, decisions 6 and 79, slice 32 say parse error
Problem #136 conflicted with master 45644db in 8 files, so its CI could not run. Solution Both sides' behaviour is kept, and where both built one mechanism, one stays: - codex flags: master's RUNTIME_INITIAL_VALUE keeps bit 61, and TAKES_ON_EFFECTS moves to bit 62. - ext/sharp/sharp.c: the includes of both sides. sharp_arginfo.h is regenerated from the merged stub with build/gen_stub.php. - Base images: master's BASE_IMAGE pulls Debian from this repository's registry. LINUX_ZTS and HOSTS build sharp/docker the way LINUX does, with its login, pull and BASE_IMAGE, the IMAGE matrix passes BASE_IMAGE to both runtime Dockerfiles, and frankenphp.Dockerfile takes it as the fpm one does. The golang stages still pull from ECR Public. - docs/spec.md section 6 and slice 06: a static lives as long as the app, and master's rules for a throw in its initial value and for generic statics. - spec-self-test.md: master's file-per-type examples, then the uses-signature example that expects the parse error. - effects/check.rs: master's LocalDeclaration declares a target, so each name it declares joins. .github/workflows/sharp.yml LINUX_ZTS and HOSTS pull BASE_IMAGE; IMAGE passes it docs/spec.md, docs/architecture/slices/06-properties.md ext/sharp/sharp.c, ext/sharp/sharp_arginfo.h sharp/docker/Dockerfile, sharp/docker/runtime/frankenphp.Dockerfile sharp/spec-self-test.md sharp/mago/crates/codex/src/metadata/flags.rs sharp/mago/crates/analyzer/src/effects/check.rs
…ough its extern Problem Queue 9: team-lead decided that passing a function parameter to a plain PHP callable keeps it inside the call, even when the library keeps it, and asked for the decision file to say so. Solution Decision 79 states it, with Events.on as the case. docs/decisions/079-function-parameter-effects.md
Problem #153 landed while the first merge was pushed, and #136 conflicted with master c4adf74 in two files, which `gh pr update-branch` cannot resolve. Solution - docs/architecture/slices/06-properties.md: a static runs its initial value once per app, in #153's hidden `#init`. - ext/sharp/sharp_arginfo.h: regenerated from the merged stub with build/gen_stub.php, so it holds #153's stub and Sharp\Internal\runScoped. docs/architecture/slices/06-properties.md ext/sharp/sharp_arginfo.h
…gap in a collection literal Problem - Master's new mago-hir crate matches every ParseError, and the merge left out FunctionParameterInUsesInSharp, so the workspace did not compile and build-and-test failed on all three runners. - patch-coverage found line 971 of effects/check.rs unrun on nightly: no test gave walk_in_array_element an element without a value. Solution - lower_parse_error lowers FunctionParameterInUsesInSharp to UnexpectedToken, with the other PHP# syntax the grammar refuses. - a_gap_in_a_collection_literal_holds_no_function_parameter checks `[f, , f]`: the gap gets its own refusal, and each `f` is refused as stored in a collection. sharp/mago/crates ├── hir/src/lower/error/mod.rs the missing arm └── analyzer/tests/sharp.rs the gap test
Problem
- LINUX_ZTS failed: ECR Public answered "429 Too Many Requests: Data
limit exceeded" for golang:1.27-trixie. sharp/docker/Dockerfile and
frankenphp.Dockerfile pulled Go from ECR Public directly, while
base-images.yml exists to be the one place that reads public
registries, and copied only Debian.
Solution
- base-images.yml copies golang:1.27-trixie beside debian:trixie and
debian:trixie-slim, to ghcr.io/heyjordanparker/golang:1.27-trixie.
- Both Dockerfiles take GOLANG_IMAGE as they take BASE_IMAGE, with the
public image as the local default. sharp/docker/run passes it.
- LINUX, LINUX_ZTS and HOSTS set GOLANG_IMAGE and pull it. IMAGE gives
each Dockerfile only the build arguments it declares.
.github/workflows
├── base-images.yml copies Go's image too
└── sharp.yml GOLANG_IMAGE in LINUX, LINUX_ZTS, HOSTS and IMAGE
sharp/docker
├── Dockerfile FROM ${GOLANG_IMAGE} AS golang
├── run --build-arg GOLANG_IMAGE
└── runtime/frankenphp.Dockerfile FROM ${GOLANG_IMAGE} AS golang-base
Problem - #145, names and imports, landed, and #136 conflicted with master in three files. Both sides added a ParseError variant in the same place, and #145 moved NAMED_EFFECTS into mago_names. - #145 generates the list of classes declared in `Sharp`, and that list lacked this branch's `Sharp\Scope`. Solution - syntax/src/error.rs keeps both variants in every match: FunctionParameterInUsesInSharp and #145's UsesOnImportInSharp. - hir/src/lower/error/mod.rs keeps #145's comment and adds a function parameter a method names in `uses`. - effects/check.rs imports NAMED_EFFECTS from mago_names, as #145 does, and keeps this branch's Binding import. - names/src/sharp_classes.rs is regenerated with `php scripts/regen-sharp-classes.php ../composer/library`, the command of `just regen-sharp-classes`, and gains `Sharp\Scope`. sharp/mago/crates ├── syntax/src/error.rs both variants ├── hir/src/lower/error/mod.rs both comments ├── analyzer/src/effects/check.rs both imports └── names/src/sharp_classes.rs regenerated, gains Sharp\Scope
Problem - #152, PHP# files, landed, and #136 conflicted with master in four files. - Both sides took bit 62 of MetadataFlags: #152's CALLER_POSITION and this branch's TAKES_ON_EFFECTS. Solution - codex/src/metadata/flags.rs keeps both flags. TAKES_ON_EFFECTS moves to bit 63, the last free bit, and the accessor and the flag test list cover both. - ext/sharp/sharp.c's container globals comment keeps #152's one class per test file and this branch's per-fiber scopes. - ext/sharp/sharp_arginfo.h is regenerated from the merged stub. Against master it adds runScoped and drops Container::scope, as before. - hir/src/lower/error/mod.rs names both `partial` before a type and a function parameter a method names in `uses`. - Every .sharp file this branch adds already declares one type, so no fixture splits. ext/sharp ├── sharp.c container globals comment └── sharp_arginfo.h regenerated sharp/mago/crates ├── codex/src/metadata/flags.rs TAKES_ON_EFFECTS at bit 63 └── hir/src/lower/error/mod.rs both comments
heyJordanParker
marked this pull request as ready for review
October 16, 2026 22:42
heyJordanParker
added a commit
that referenced
this pull request
Oct 16, 2026
Both sides keep their behaviour, with one mechanism where both built one: - Default names: master generates every class-like directly in Sharp into sharp_classes.rs, so the effect classes and ProcessResult come from it, and this branch's standard exceptions join that list. NAMED_EFFECTS, which #145 moved into mago_names, goes, as decision 1 deleted it: each effect is a class now. - `Error` always names Sharp.Error (spec section 31), so sharp/bin/builtins no longer declares PHP's engine Error, which PHP# code never names. - The bridge tests' library takes the effect classes on master's two-pass name resolution. Two master tests no longer pass ENVIRONMENT, which every analyzer test project holds through EFFECT_CLASSES. - The yield test loads its Import fixture folder and the effect classes. - Messages keep this branch's wording: echo names Console, a refused law says "A law cannot reason about…", an undeclared call names the class.
heyJordanParker
added a commit
that referenced
this pull request
Oct 16, 2026
… given Spec section 29, line 4123: the standard library's collection methods take on the effects of their functions the way a PHP# method does. Decision 6 builds them on #136's mechanism: the scanner flags each \Closure parameter of the prelude's ListMethods, MapMethods, SetMethods and IterableMethods TAKES_ON_EFFECTS, so passed_functions takes on what each call passes, as it does for a PHP# method's function parameter. prelude_stub_call keeps only its change of the receiver, and callbacks runs only for plain PHP, which may run any function it is given. The second path through the stubs is gone.
heyJordanParker
added a commit
that referenced
this pull request
Oct 17, 2026
…136 keeps a function parameter from escaping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A PHP# app behaves the same under php-fpm, the CLI, FrankenPHP's worker mode and Octane. A
scopedservice lives for one unit of work. Asingletonand a static live as long as the app runs, and a host that runs several workers runs one app in each.Problem
On master, FrankenPHP's worker mode runs ext/sharp's request start once per worker thread, so every HTTP request shares one scope. Under FrankenPHP 1.13.0's worker mode, on master's engine, the second request gets the first request's
scopedservice:PHP# code had no call to start a scope.
Sharp\Container::scopecrashed when a fiber suspended inside it. No image ran PHP# under FrankenPHP, and FrankenPHP could not link the engine at all. Type textsunserializereads would grow a worker until it exits.What changes
Scope.run(body)starts a scope. It returns whatbodyreturns and takes onbody's effects.Sharp\Internal\runScopedreplacesSharp\Container::scope.Scope.runbelongs to that scope, and aScope.runinside a fiber is that fiber's own. Ascopedservice resolved after its scope ended throwsSharp\ContainerError. Each fiber builds on its own, so a fiber suspended in the middle of a build holds no other fiber back, and two that finish one service at once each get the one kept first.rethrowsand Kotlin's inline lambdas do. This replacesuses f, and a leftoveruses fis a parse error that says to delete it. A method value passed to a function parameter, or to plain PHP, has its method's effects, whether it is read from an object or from a class, asJob.ping.@escaping. Storing it in a field, a collection or a new object, returning it, passing it where it may be kept, and a local or a lambda that does any of these are compile errors that name the type to take instead, asFunction<string() uses Environment>. Calling it, and passing it on to another method's function parameter, compile. A parameter whose type states its effects keeps them as a cap.sharp/bin/speckeeps its rule for a signature that ends inuses, because the spec guard lets it change only in a pull request of its own.unserializefails as other bad input does. A type the program's own substitution makes, and every type the app holds, keep working. C# keeps run-time generic instantiations for the process's life the same way.ghcr.io/heyjordanparker/php-sharp:<version>-frankenphp, fromsharp/docker/runtime/frankenphp.Dockerfile.ext/sharp/config.m4linkslibsharp.aintolibphpthroughPHP_GLOBAL_OBJS.sharp/bin/build --zts,sharp/bin/test --ztsandsharp/bin/hosts, and CI'sLINUX_ZTSandHOSTSjobs, which pull Debian from this repository's registry asLINUXdoes.base-images.ymlalso copiesgolang:1.27-trixie, and every Dockerfile that builds Go takes it asGOLANG_IMAGE, so CI reads no public registry.IMAGEis a matrix over both images, each with the build arguments it declares.docs/v1.mdstates the v1 Goal.Harness files changed
sharp/harness/app/Cart.sharpgainspublic int total { get; set; } = 0;, whichfunction-effectsreads.sharp/harness/app/Jobs/Job.sharp, new:public void handle() { }, whichhost-scopecalls.sharp/harness/app/Jobs/JobQueue.sharp, new:public List<Job> pending() => [];, whichhost-scopereads.sharp/harness/app/Holder.sharp, new:public Holder(private Function<string() uses Environment> body) { }, whichfunction-effectsrefuses to store a function parameter in.CI time
On fef47fb,
HOSTSran 2 minutes 20 seconds, 19:32:38 to 19:34:58 UTC. It starts whenLINUX_ZTSends, after 20 minutes 39 seconds, so its chain ends at 23 minutes 2 seconds.MACOS, the slowest job, ran 33 minutes 46 seconds, soHOSTSadds no time to the run.Verification
sharp/bin/test --opcache --repeaton macOS: 282 of 282 pass in each of the 4 modes.sharp/bin/test --linux --zts --opcache --repeat --passeson the scope and limit tests: 4 of 4 pass in each of the 22 modes.sharp/bin/hosts --linux: php-fpm and FrankenPHP each print whatsharp/hosts/expected/holds, memory after the 1,000th/typesrequest equals memory after the 2nd,/wordsworks in the worker after/flood, and 400 of 400 concurrent requests over four workers pass.cargo test -p mago-analyzer -p mago-semantics -p mago-names -p mago-codex -p mago-sharp-bridge -p mago-fingerprint -p mago-orchestrator, and-p mago --test compile: every test passes.cargo llvm-covof the analyzer's and semantics' PHP# tests runs every line this pull request adds tocrates/analyzer/srcandcrates/semantics/src(diff-coveragainst master: 419 lines, 100%).sharp/bin/spec: 199 examples checked, 1 ignored, 33 fail, each onsharp/baseline/spec.