php: Variant, Switch, arrays, closures and references under PHP (slice 2 of #64) #735
Labels
No labels
loop
queue/failed
queue/queued
ready
status/parked
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
torbscript/language#735
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Step 3 of #64 (backend: PHP), slice 2 of
docs/design/PHP.mdsection 6: the rest of the language, part 1. Step 2 (#727, PR #730, merged as187618a9) is onmain: targetlinux-php,compiler/src/backend/php/{emit,body,type,natives,writer}.trb,runtime/php/{core,int64}.php,tools/conformance.sh --php,tools/php-guards.sh,tests/conformance/php.allow, the action.forgejo/actions/phpand the jobconformance-php. It is the sibling of #684 (slice 2 of the JavaScript back end, PR #694), whose choices it copies where the IR, not the host, decides.Source
docs/design/PHP.mdsection 6 row 2, section 2.1 (Switch, no PHP reference), 2.3 (values,Read/Write), 2.4 (closures, captures, projections), section 7 (statements pinned by this slice).docs/design/JAVASCRIPT-BACKEND.mdsections 2.3 to 2.4 and "What slice 2 left out".What
php: Variant, Switch, arrays, closures and references under PHP. Extend the slice-1 emitter, compiler only. What
body.trbreports as unsupported today and this issue makes work:VariantandTag: a payload-free enumeration is theintof the case; otherwise one class per case withtfirst, thenf0, ... (type.trb:isPlainLayoutand the "variant or boxed layout" reports inConstruct,placeOf).Switchon an integer or a tag is a PHPswitchwhose cases are integer literals, each holding agoto; the unsupported report forSwitchon a non-integer stays.FixedArrayandBuffer: an object that owns its storage ({a}with a PHP array, a string for 8-bit elements), with a bounds check wherever the IR has one; theElementstep ofplaceOfandRead/Writethrough everyPathStep(field, tuple field, variant payload, element).Closurewith the three captures,CallClosure($f = $c->f; $r = $f($c->e, ...), neverfunction () use), and thevarparameters andvararguments that slice 1 reports (parametersOf,emitCall): aCellis an object with->v, aProjectionan object withget()andset($x). No PHP reference (&) in the output.Lazyas the IR builds it, as far as the lowering produces it;BoxNew,LazyForce, aPlacecapture and aContentsstep are not produced by the lowering and the C and JavaScript back ends name them as unsupported, so this one names them too (PHP.md section 1.1; amend the record if the code shows otherwise).Decided by the loop
Bufferasnew List(ListStorageof slice 4), that stays unsupported here, as in #684;FixedArrayis a PHP array wrapper until then. Programs that print lists, maps or aShown value stay offphp.allow(slice 4).Files
compiler/src/backend/php/{body,type,emit,writer}.trb(andnatives.trbonly if a runtime helper is named);runtime/php/core.phpfor the array and cell helpers.tests/conformance/php.allow; a newtests/conformance/php-variants-arrays.trbwith.expected,.stderr,.exit, modelled onjs-variants-arrays.trb, plus a check that greps the emitted file for&$and= &.docs/design/PHP.md(row 2 marked done, a "What slice 2 left out" paragraph, section 7 figures); docs regenerated astorb docsrequires.Tests
matching,match-order,closures,closure-counts,closure-frame,records,places,place-counted,rest-patterns,array-index-bounds) joinphp.allowonce they pass on 5.6.40, 7.4.33 and 8.4 with the C leg's expected files.php-variants-arrays.trbexercises each construct above; a program that aliases through a reference proves no PHP reference is emitted.Acceptance criteria
php.allowgrows by the programs on enums, matching, closures and arrays; none is removed; they pass on 5.6.40, 7.4.33 and 8.4 with the same.expected,.stderrand.exitfiles as the C, VM and JavaScript legsphp-variants-arrays.trb) passing on all four legs&$and= &and finds noneBoxNew,LazyForce, aPlacecapture and aContentsstep still failtorb build --target linux-phpwith a named finding and no output filedocs/design/PHP.mdmarked done;torb format --checkandtorb docs checkgreentools/check-commits.shclean;sh tools/gates.sh aand theconformance-phpjob green in forge CI (CI only, no local bootstrap or gates)Seed
Compiler only: no syntax change, no new native, no new std name looked up by string, no new
Architecturecase, so the two-commit rule of #727 does not apply. One PR; one Conventional Commit per logical change (feat(php): ...), confirmed bytools/check-commits.sh. The seed refresh stays Torben's.Size
One PR. If a review cannot hold it, cut closures and references into a second commit of the same PR; nothing is carved out into a new issue. Model: sonnet, thinking high (compiler work). Out of scope: slices 3 to 8 (witnesses, trait values, objects, counts and
Closeorder; kernel; tasks; limits; subset andtorb test), a minifier.Dependencies
main).Part of #64 (epic; do not close it).
[loop:torbscript] claim implement by session:loop-torbscript-20261113 until 2026-11-13T12:30:00Z
[loop:torbscript] release implement: the worker died before its first reply (provider 403 at login), no branch and no PR; respawned on a fresh claim
[loop:torbscript] claim implement by session:loop-torbscript-20261113 until 2026-11-13T12:50:00Z
[loop:torbscript] implement: the worker hit its time limit after opening PR #738 (head
bbfd637); CI is running, no red job yet, Argus is requested. Claim released.next: review
[loop:torbscript] claim implement by session:loop-torbscript-20261113 until 2026-11-13T18:32:00Z
[loop:torbscript] implement checkpoint: done: root causes found. (1) "conformance (PHP ...)": the 10 programs added to php.allow end through
Process.exit, and the PHP back end did not listtorb_process_exit. (2) "tier B":php-variants-arrays.trbhad no allocation budget (15 blocks measured). Fix pushed asffecc839(torb_process_exitmapped totorb_exitin natives.trb and core.php, plusphp-variants-arrays.allocations= 15). In flight: forge CI onffecc839. Next: read CI, fix any remaining PHP-leg findings.[loop:torbscript] implement checkpoint: done: torb_process_exit for the PHP back end, php-variants-arrays allocation budget (15), php-output.sh findings replaced by ones the back end can reach (float and UInt64 arithmetic; BoxNew/LazyForce/Place capture/Contents are not reachable from source). In flight: forge CI on
ba641fd8(branch loop/735-php-variants-arrays, worktree code/wt/torbscript-language-735-php2). Next: read conformance (PHP) and tier B results, then final comment.[loop:torbscript] release implement: worker run timed out after checkpoints on PR #738; branch keeps the work, next: implement (respawn when a slot is free)