Repository navigation
Bug sweep: lexer, reference cells, hooks, reflection, array_splice (#428–#449, #34 #59 #61 #395) - #461
Merged
Conversation
A store through a union or cell-typed receiver wrote the backing slot directly. Dispatch on the runtime class and call the set hook per arm. Fixes #448
The prelude spelled it isReadonly, which method lookup does not fold. Fixes #434
Keep such a param erased in Monomorphize and make the caller's array hold cells. Fixes #428
Already fixed on this base; the repro passes against php. Fixes #442
The alias shared the source's alloca, decided once at emit time, so it could not follow control flow: a binding made on one branch aliased every path, rebinding from an element box left its tag in the new target, and the two names kept separate flow types over one slot (stale raw reads, values dropped from ownership). Both names of a local alias pair are now ref-cell targets (cell-typed, frame-boxed) and the alias copies the box pointer with a count. By-ref params, statics, globals, superglobals and any chain through them keep the shared slot; generators and by-ref returning frames too. Fixes #445 Fixes #441 Fixes #59 Fixes #395
…to it A by-ref foreach iterates a copy written back into the element at the step. A reference taken to the loop variable (`$out[$k] = &$v`, `[&$v]`, `$w = &$v`, inside or after the loop) pointed at that one copy, and a boxed variable wrote its box address back into the element. After lowering, every such loop takes the `$v = &$xs[$k]` form the closure-capture case already used, built from the lowered subject. Fixes #439 Fixes #446 Fixes #440
…-ref parameter
Every spread read its elements through __mir_array_value_at, which
dereferences a REF cell, so a reference another binding still names
became a value copy in `[...$refs]`. The merge now keeps such a REF
(__mir_array_raw_value_at + __mir_ref_shared). A spread of a plain
variable that reaches a by-ref parameter (a by-ref variadic pack, plain
argument plus spread, or a fixed by-ref param) lowers to
`$t = []; foreach ($xs as $k => &$v) { $t[$k] = &$v; }` and `...$t`,
and a fixed by-ref param fed from the pack binds to the element's box
instead of a scratch slot.
Fixes #443
Fixes #438
Fixes #444
Fixes #61
`$o->{$e} = &$x` lowered to a value copy, and `$o->n = &$x` on a bag
class fell back to one too. Both now store the REF cell in the property
bag: __mir_bag_set_str replaces the binding for a REF and writes
through an existing reference otherwise, and __mir_bag_get_str
dereferences on every bag read.
Fixes #34
…eference holdShimArgs, the `$f = $o->m(...)` arm, only boxed bare locals; a property or element argument at a storing by-ref slot was handed over as a plain address and the stored reference became a stale copy. It now marks them like holdAnyStoring does (refCellPropNames / refStored). Refs #353
This was referenced Oct 26, 2026
Closed
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.
What
Fixes ~25 open bugs, grouped by root cause.
;;objectis a name outside casts;readonly(is a function name. Fixes Constant named OBJECT is lexed as the object type keyword in a default value #430 A line comment ends at the closing tag, so a trailing comment before it still closes PHP mode #431 A closing tag terminates a statement without a semicolon #432readonlyis accepted as a function name #433 Lexer:?>inside a // line comment does not end PHP mode #447$a = &$bbetween locals now boxes both names (control-flow and rebinding correct); by-ref foreach with an&taken on the loop variable binds per element; spreads keep references; by-ref variadic fed from spread/plain; dynamic-property bag stores/reads honour REF cells. Fixes Dynamic property ops:$o->{e} = &$xdoes not bind, dim write is lost, unset is a no-op #34 A referenced local whose type changes reads a stale/raw word (use (&$d),$r = &$d) #59 A by-ref argument fed from a spread lands in a throwaway slot #61 A local aliased with =& is dropped from ownership tracking and its string leaks. #395 Spreading a variable into a by-reference variadic (a forwarder's...$vars) passes values, not references. #438 A reference taken to a by-ref foreach variable ($out[$k] = &$v,[&$v]) points at the loop's copy, not the element. #439$w = &$vwhere$vis itself bound by reference (a by-ref param, a by-ref foreach variable) overwrites the binding instead of writing through it. #440 Rebinding a reference from an array element to a local ($w = &$a[0]; $w = &$x; $w = 3) writes a tagged cell into the local. #441 A reference stored from a raw-typed by-ref param (int &$p,$out[0] = &$p) is a copy; writes through it never reach the caller. #442 Spreading an array of references into an array literal ([...$refs]) copies the values; php keeps the references. #443 A by-ref variadic fed by a plain argument AND a spread (put($b, ...$rest)) loses the writes to the spread part. #444 A reference bound on one branch only (if ($c) { $p = &$x; } $p = 5;) aliases on every path: the false path writes $x too. #445 A by-ref foreach whose value variable is reference-taken elsewhere in the function writes the box address (or a dangling value) back into the element. #446. Partial: A typed or dynamically-called property passed by reference to a storing callee is stored as a stale copy. #353 (first-class callables fixed; typed-property and dynamic-name cases need a design decision, stays open).get_object_vars()outside the class)class_exists(class_exists() is case-sensitive; php resolves class names case-insensitively. #436),ReflectionProperty::isReadOnly(ReflectionProperty::isReadOnly() is missing from the reflection prelude (method_exists says true, the call is fatal). #434),array_spliceon int-valued string-keyed copy (array_splice on a copy of an int-valued string-keyed array with string replacements throws TypeError #428), promoted ctor property order (A class with a promoted constructor property lists that property before the declared ones in get_object_vars(). #302),strval()regression test (strval() of an object that defines __toString throws "could not be converted to string". #249).Not done
#457/#72 (object handle numbers): needs an object-header ABI change, deferred.
Risk / gates owed
$a = &$bbetween plain locals now heap-boxes both names: watch perf andleaks --atExit.src/Compile/Runtimeand Monomorphize/InferScans/LowerClasses: Linux gate, difftest and the self-host fixpoint are NOT run yet. Only targeted-kgroups were run locally (all green; xfail.sh: 39 XFAIL, 0 XPASS).