php: integers, bits and UInt64 under PHP (slice 4A of #64) #804
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#804
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 5 of #64 (backend: PHP), slice 4 of
docs/design/PHP.mdsection 6, part A: the integer kernel. Steps 1 to 4 (#702, #727, #735, #761) are onmain:compiler/src/backend/php/{emit,body,type,natives,witness,count,writer}.trb,runtime/php/core.php,tools/conformance.sh --php,tests/conformance/php.allow,tools/php-output.sh, CI jobconformance-php(5.6.40, 7.4.33, 8.4). Todaybody.trbreports "UInt64 arithmetic", "a UInt64 constant", "a comparison of floats or UInt64" and "a conversion to a float or UInt64" as findings, andnatives.trbmaps only the show natives andtorb_process_exit. This issue makes every integer operation work, which is the sibling of the JavaScript slice 4B (#724) restricted to integers.Source
docs/design/PHP.mdsection 2.3 ("Integers",UInt64), section 3 rows K1, K2, K4, K7 (integer to integer) and K8, section 6 row 4 and the paragraph "What slice 3 left out".docs/design/JAVASCRIPT-BACKEND.mdsection 6 row 4B and #724 for the property-test shape;runtime/int64.candruntime/as the reference of what each symbol means;compiler/src/backend/javascript/natives.trb(emitsIntrinsic) for the sweep.What
php: integers, bits and UInt64 under PHP. Extend the PHP emitter and the runtime; no native is added to the manifest.
Add,Subtract,Multiply,Divide,Remainder,Negate, the bit operations and both shifts, the wrapping pair (addedWrapping,multipliedWrapping), comparisons andConvertbetween integers, forInt8toInt64andUInt8toUInt32, as PHP.md 2.3 and 3 specify (theis_inttest, the guarded/and%, the shift-count panic of the C leg, the mask after a narrow left shift and after a logical shift of an unsigned type). Population count and the leading and trailing zeros are table-driven loops over bytes.UInt64as the signed 64-bitintof 2.3: newruntime/php/int64.php(arithmetic, wrapping family, comparison by sign-bit flip, multiplication, division, remainder,torb_shift_amount, conversion to text and to integer types on 32-bit halves), written in front of a program only if the program reaches it; the "UInt64 arithmetic", "UInt64 constant" and UInt64 comparison/conversion findings go away. Conversion to a float stays a finding named for slice 5 (floats).===and the orderings on integers, characters, booleans andisSameon objects (already===); build constants as literals (OperatingSystem.current,Architecture.current,ByteOrder.current, the page size).Intrinsicsweep.natives.trbgains anemitsIntrinsiclike the JavaScript one, so eachIntrinsicover each width is emitted or named as deferred (floats: slice 5,LazyForce: stays a finding).pack/unpack, lists, maps, sets,Shown values, text natives beyond slice 1 and the whole manifest walk stay as onmain.Decided by the loop
UInt64, storage and the manifest walk; that is not one reviewable PR (the JavaScript slice 4 was cut into 4A and 4B for the same reason). Part A (this issue) is the integer kernel withint64.php; part B (storage of section 4: list, buffer and text natives, the shared walk ofnativeEntries()with an explicit deferred list, the memory figures of section 4,MakeUniquecheck) is filed as the next step when A is merged, just in time as LOOP.md asks. The #64 step 5 line says so.bcis not assumed):tools/php-int-vectors.shbuilds a small C generator with the runner's compiler, writes random and boundary operands for each operator and width, and compares with the PHP helpers on all three interpreters. Case count: 10^6 per operator and width is the record's figure; the implementer measures the job time in the first CI run and lowers it to a size under 10 minutes only with the figure written into PHP.md (a measurement decides, no owner question).Files
compiler/src/backend/php/{body,natives,emit,type,writer}.trb; newruntime/php/int64.php;runtime/php/core.phponly for shared helpers.tools/php-int-vectors.sh(and a small C generator undertools/),.forgejo/workflows/gates.ymlfor the call inconformance-php,tools/php-output.sh(a program withoutUInt64has noint64.phptext in its output;php_first.trboutput unchanged).tests/conformance/php.allow, newtests/conformance/php-integers.trbwith.expected,.stderr,.exit(every width, overflow panics,UInt64boundaries, shifts, wrapping, conversions),tests/php-findings/updated (UInt64 case removed, float case stays).docs/design/PHP.md: row 4 split into 4A done and 4B open, a "What slice 4A left out" paragraph; docs regenerated astorb docsrequires.Tests
.expected,.stderr,.exitof the C leg joinphp.allow; the PR names each candidate left off (list, map,Show, float, task) with the finding.php-integers.trbpasses on the C, VM, JavaScript and PHP legs (JavaScript only if it already passes there; otherwise the PR says why).tools/php-output.sh: no output contains&$,= &or__destruct; a program with noUInt64carries noint64.php; float arithmetic still fails the build with a named finding and no file.Acceptance criteria
UInt64, on 5.6.40, 7.4.33 and 8.4, in theconformance-phpjobUInt64arithmetic, constants, comparisons and conversions to integer types build and run; conversion to a float still fails with a finding that names slice 5php.allowgrows by the programs listed in the PR; none is removed; they pass with the same expected files as the other legsphp_first.trboutput unchanged, a program withoutUInt64has noint64.phpcode, and the JavaScript leg is unchanged (--jswith the samejs.allow)docs/design/PHP.mdsplit (4A done, 4B open), "What slice 4A left out" written;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, runtime and tools only: no syntax change, no new native, no new std name looked up by string, no new
Architecturecase. Not touched:seed/, releases.Size
One PR, one or two Conventional Commits (
feat(php): ...,test(php): ...). Model: sonnet, thinking high (compiler work). Out of scope: part B (storage, manifest walk, memory figures), slices 5 to 8, a minifier.Dependencies
main).Part of #64 (epic; do not close it).
[loop:torbscript] claim implement by session:loop-torbscript-804-impl until 2026-11-15T09:35Z
[loop:torbscript] release implement: PR #809 open, CI queued (runs 3009/3010 waiting behind 2997/2998/3003 on the busy runner, not started after ~15 min; nothing has run yet, so the build is unverified and the conformance-php vector timing is not yet recorded in PHP.md), worker usage about 600k tokens (sonnet). next: waiting (merge gate)
[loop:torbscript] claim review-fix by session:loop-torbscript-804-fix until 2026-11-15T06:06Z
[loop:torbscript] release review-fix by session:loop-torbscript-804-fix: bootstrap (linux-x64) failed because the seed has no command call inside an expression; 23 errors, all
if isWide shape {,isFloating kind,needsWide symbolin compiler/src/backend/php/body.trb andSome kindin compiler/tests/php-natives.test.trb. Fixed with parentheses in commit4e48f8b3(11 lines, nothing else touched). Not run locally (no runnable torb on the worker), CI on4e48f8b3is queued (runs 2979/2980 waiting for a runner), not yet green. next: review (merge gate)