Skip to content

Compile and serve a Symfony app natively: ownership/inference fixes, leak fixes, reflection and dispatch gaps - #165

Merged
blacktrs merged 195 commits into
mainfrom
fix/symfony-ownflow-inference
Oct 16, 2026
Merged

blacktrs merged 195 commits into
mainfrom
fix/symfony-ownflow-inference

Conversation

@blacktrs

@blacktrs blacktrs commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What

Takes the Symfony skeleton (symfony-app) from "fails in EmitLlvm" to a compiled
binary that serves / (200) and an HTML 404 under Http\Server, with no leak on
the request path and a markedly faster hot path. Refs #156 #157 #160; fixes #153
#157 #160 #164 #169 #177 #181 #182 #185 #190 #191 #192 #198 #199 #202 #208 #232
#239 #246.

Changes

Ownership / inference — a slot no longer holds a cell word and a raw pointer at
once; foreach bindings, erased arrays, by-ref params, closures' captured arrays and
finally deferred jumps agree between flow and inference; SpillFreshBases now also
owns fresh object arguments of may-throw calls so cleanup pads drop them on unwind.

Leaks on the request path (404 growth 1.7 KB → ~60 B per request)

  • a property store through an erased receiver never released the old value;
  • +, [...$a] and __mir_cell_to_bag retained a key string twice;
  • array_pop/array_shift results used as arguments, in-place invoked closure
    envs, closure by-ref cell params, (array)$obj results were never released;
  • the cycle collector did not count freed shells, so its threshold ratcheted up.

Dispatch and codegen — $c::$m(...) and dynamic new share helpers (IR −34%);
erased-receiver return joins; static/callable-array invoke; extract() and
included templates; fiber-local backtrace segments (was the 404 slowdown); EINTR in
io_poll.

Reflection / stdlib — Stringable objects bound to string parameters of builtins and the stdlib
render through __toString (#269); Reflection __toString (method, property), modifier constants, lazy-object
and reference APIs, ReflectionClass('Closure'); class_parents/implements of
interfaces; DATE_* and CASE_* constants; hash_init algos; named groups in
preg_replace_callback; (*MARK); typed-argument TypeError at the call site.

Performance (GET /, macOS, prod, wrk): 1 worker 8.9k → 15.8k rps, 8 workers
56k → 83k rps. On Linux (Docker VM) 14k rps per worker and ~100k on 8.

  • strtr byte form is a native builtin (it built a 256-entry table per call);
  • method_exists/is_a/property_exists with runtime names use sorted tables and
    binary search (was a linear strcasecmp scan);
  • filter_var: integer fast path, no regex for FILTER_VALIDATE_INT;
  • array_key_exists is O(1); int switch lowers to one LLVM switch.

Verification

  • macOS arm64, full AOT suite: 2088 pass, 1 fails (fresh_temp_builtin_arg_destructs_late, red before the
    later work on this branch).
  • Linux arm64 (glibc, Docker): self-host build and full suite at 4bebb13b 2082 pass / 4 fail (the same case
    plus three new leak tests whose RSS thresholds were too tight for Linux; loosened, re-run green). Later
    commits were re-checked with targeted runs only.
  • Symfony skeleton on Linux (Docker VM, 10 cores, wrk inside): / 14.0k rps on 1 worker, 54.8k on 4,
    101k on 8 (113.9k at 128 connections); stable workers, 200 on the first request with an empty var/cache.
    Found and fixed there: manifest builds did not link -lm; foreach over a Traversable-typed
    IteratorAggregate called rewind() through another class's layout (heap corruption on glibc).

Not verified

…depth

A nested try/finally inside a finally reused the outer finally's depth
index and took over its deferred return, failing the ownership flow with
'edge never reached its target' (symfony Dotenv::loadEnv).
…ays (#156)

- an erased foreach value bound to a name the function stores a cell into
  anywhere is a cell, not only when the loop body does
- an alias of an erased array parameter beside a concrete array store joins
  the erased release class
- the key of an erased-element vec is a cell, as InferNodes types it
…ds (#156, #157, #160)

- a property typed from a stored array no longer inherits that value's docblock
  shape, so a child's wider shape can read its own keys
- a closure beside a scalar at a merge boxes like any other tag-carried kind
- an instanceof-narrowed arm that never stores the local keeps its entry
  representation for the merge, and a box-back pair is not taken back while
  the arm's slot disagrees with the other arm

Fixes #157, Fixes #160
…e loop's reset, so a hidden local does not flip the per-iteration verdict
…eset reclaims it and a hidden local flips the reset verdict
…o a fresh receiver takes the shared name chain
…ing else reclaims the string (cmp_minted_string_cell_no_leak)
…l too; log the function and operand kinds in MANTICORE_DYNM_TRACE
…e spread unsafe-name set to the call site (#168 repro)
…roperty without its set hook (Symfony Request::setProperty)
…embers derivable from existing metadata; by-ref parameter bit; interfaces ride along with a reflected class
… and properties (compiler-synthesized per-class table, gated on the program asking)
…s TypeError at the call site instead of failing the build

php checks a parameter type when the call is made, so a call that cannot succeed
(an inherited new static cloned per subclass, a branch behind a feature guard)
is a run-time TypeError, not a compile error. The last argument becomes
true ? throw new TypeError(...) : arg, so earlier arguments evaluate first, and a
build-time warning stays. analyze (collect mode) and bin/build (which exports
MANTICORE_TYPECHECK_STRICT) keep it an error, so the tree compiling itself and
the analyzer report every such site. Memory-safety checks (array repr, shape)
stay fatal.
…of per arm, ending the O(N^2) unwind-pad blowup
…pread into one array so the site takes the shared dispatch instead of a per-candidate inline chain
… and passes the call's arguments to the constructor
…ere read as plain values, so the caller never saw the out param). Fixes #177
… classes, ending its O(classes x methods x params) inline dispatch
…receiver; count freed shells in the collector's productivity
… a 256-entry map per call; method_exists/is_a/property_exists runtime tables: sorted rows + binary search
…g translates); filter_var: integer fast path and no regex for FILTER_VALIDATE_INT
@blacktrs blacktrs changed the title Fix ownership-flow/inference disagreements found compiling a Symfony app Compile and serve a Symfony app natively: ownership/inference fixes, leak fixes, reflection and dispatch gaps, ~1.8x faster hot path Oct 15, 2026
@blacktrs blacktrs changed the title Compile and serve a Symfony app natively: ownership/inference fixes, leak fixes, reflection and dispatch gaps, ~1.8x faster hot path Compile and serve a Symfony app natively: ownership/inference fixes, leak fixes, reflection and dispatch gaps Oct 15, 2026
…y app failed to link: DSO missing from command line)
…t is an Iterator or an IteratorAggregate: rewind() was called on an aggregate, writing through another class's layout
…fony's ReflectionClassResource hashes a class through them, so a cold prod cache answered 500
…g parameter through __toString: stdlib bodies reach the program's dispatcher via the hook (the stdlib has no arm for a user class), every __toString class gets an arm, builtins get the cast (Fixes #269)
…ps attribute rows for constants (#244); a cold prod cache hashes every class through it
…nference

# Conflicts:
#	docs/builtins.md
#	src/Compile/Mir/Passes/LowerFromAst.php
#	src/Runtime/Stdlib/VarExtra.php
… statement end: the emitter releases it right after the call, so its destructor runs before the echo as in php (regressed by b0a5867)
… is stripped before the entry copy, and a bare ?array param promoted to a cell boxes its raw null as NULL, not int 0 ($a ??= $_SERVER['argv'])
… a by-reference cell parameter accept a cell-element array local (scratch cell, unboxed after the call), Exception/Error declare a reflectable private $trace; skip CI pushes that only touch examples/symfony-*
… native binary, with the build steps and the differences from a stock skeleton
…w declares $trace like php, so the exact property count of a Throwable cast is not a stable expectation
…d a cell starts as a Borrow, so the else edge no longer drops the caller's array; drop the duplicate discardedIncDec left by a merge
…nds to a block with an if, and the else arm inherited the then arm's ownership state, so the callee dropped the caller's array (musl abort)
@blacktrs
blacktrs merged commit 7f2be54 into main Oct 16, 2026
8 checks passed
@blacktrs
blacktrs deleted the fix/symfony-ownflow-inference branch October 16, 2026 08:31
blacktrs added a commit that referenced this pull request Oct 16, 2026
…ogress, COMPILER_VERSION (#286)

* Add CLI golden test: pin command behaviour before the restructure

* Fix CLI golden test exit-code capture and compile+run probe

* Add Cli\Command contract, declared options and generated help; migrate version

* Move dump-* and split-ir into Cli\Commands

* Move analyze into Cli\Commands

* Move build into Cli\Commands

* Move compile into Cli\Commands; drop compile_arg_spec

* Remove the legacy closure command path; document the Command contract

* Fix stale compile driver pointer; correct build --no-analyze help

* install.sh: strict mode, --check, staged atomic swap with rollback; ship it as share/install.sh

* install.sh: strict exit 5 on post-swap failure, never source-build in strict mode, rollback only own swap

* Add manticore upgrade (--check, --version) over the shipped install.sh

* Document manticore upgrade

* Harden upgrade rollback and staging; fix upgrade docs placement; add tag/version CI check

* Restore the bin/build 'atomically swaps in' wording in docs/modules.md

* Extract Cli\Install from upgrade; add version --check and Cli::registry()

* Add manticore doctor

* Add manticore completions (bash, zsh, fish); document doctor and completions

* Add COMPILER_VERSION as the single version source; bin/build generates Version.php

* Enforce COMPILER_VERSION in CI and release

* Add build progress: Compile\Progress, Cli\Style, --progress/--quiet/--timings/--color

* Fix progress option error wording; harden truncation and progress tests

* Announce stage starts and counters for the live progress line

* Report clang n/N for split builds; fix nested live stage; document progress options

* Harden split progress: liveness check, cache-free tests, README order

* Pair stage begin/end names; keep live progress clean under stats; refresh stale profiler text

* Make the live/stats progress tests real

* Re-baseline CLI golden IR/MIR checksums after merging main (#165 codegen changes)

* Document the CLI: command reference page, bootstrap versions, roadmap

* Trim README build-progress to a pointer at docs/cli.md
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.

A by-reference foreach variable captured by reference in a closure turns the array's elements into box addresses.

1 participant