Category
php-in-php | bootstrap
Problem
Date arithmetic exists in two parallel implementations:
- VM path:
ext/standard/VmDateTimeNative.php (PHP) — applyIntervalState, modifyRelative, diffTimestamps
- JIT path:
lib/JIT/Builtin/DateMutationRuntime.php — hand-emitted LLVM IR (__phpc_date_apply_interval, __phpc_date_modify_delta, __phpc_date_diff_scalars)
The JIT IR duplicates calendar rules from php-src ext/date/php_date.c and drifts from VM behavior. Both files are on the self-host inventory but only VM helpers are exercised by compliance tests today.
#8702 adds spine coverage; this issue consolidates semantics so one PHP module owns the rules and JIT lowers through it (or shared PHP compiled to native), shrinking bespoke LLVM date math.
php-src reference
Repro (drift today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit test/unit/DateMutationJitCompileTest.php --filter DateMutation
# JIT compile smoke only — no php-src parity assert vs VmDateTimeNative for edge cases (month-end, DST)
'
Add a maintainer script comparing VM DateTime::modify vs JIT-compiled date_modify() on:
<?php
$d = new DateTime('2024-01-31');
$d->modify('+1 month');
echo $d->format('Y-m-d'), "\n"; // 2024-03-02 (Zend) — verify JIT agrees
Scope (PHP-in-PHP)
| Piece |
Path |
| Shared math |
new ext/date/DateCalendarMath.php (or extend VmDateTimeNative) — single source of truth |
| VM |
route VmDateTimeNative through shared module |
| JIT |
lib/JIT/Builtin/DateMutationRuntime.php — replace IR emission with call to compiled PHP helper / thinner LLVM trampoline |
| Spine |
coordinate with #8702 (JitDateMutation.php on spine) |
| Tests |
test/compliance/cases/ext/date_modify_jit_vm_agree.phpt |
Allowed thin C: libc timegm/mktime FFI trampolines only — no new date rule tables in runtime/*.c.
Done when
Verify
php script/check-selfhost-spine-coverage-sync.php
make bootstrap-selfhost-vm-driver-execute-probe
./script/ci-fast.sh --filter date_modify
Links
#8702 · #4604 · #1492
Category
php-in-php|bootstrapProblem
Date arithmetic exists in two parallel implementations:
ext/standard/VmDateTimeNative.php(PHP) —applyIntervalState,modifyRelative,diffTimestampslib/JIT/Builtin/DateMutationRuntime.php— hand-emitted LLVM IR (__phpc_date_apply_interval,__phpc_date_modify_delta,__phpc_date_diff_scalars)The JIT IR duplicates calendar rules from php-src
ext/date/php_date.cand drifts from VM behavior. Both files are on the self-host inventory but only VM helpers are exercised by compliance tests today.#8702 adds spine coverage; this issue consolidates semantics so one PHP module owns the rules and JIT lowers through it (or shared PHP compiled to native), shrinking bespoke LLVM date math.
php-src reference
ext/date/php_date.c—php_date_add,php_date_sub,php_date_diff,date_modifyext/date/lib/astro.c— calendar primitives (reference only)Repro (drift today)
Add a maintainer script comparing VM
DateTime::modifyvs JIT-compileddate_modify()on:Scope (PHP-in-PHP)
ext/date/DateCalendarMath.php(or extendVmDateTimeNative) — single source of truthVmDateTimeNativethrough shared modulelib/JIT/Builtin/DateMutationRuntime.php— replace IR emission with call to compiled PHP helper / thinner LLVM trampolineJitDateMutation.phpon spine)test/compliance/cases/ext/date_modify_jit_vm_agree.phptAllowed thin C: libc
timegm/mktimeFFI trampolines only — no new date rule tables inruntime/*.c.Done when
date_add/date_sub/date_modify/date_diffagree on compliance matrixDateMutationRuntime.phpLLVM IR line count shrinks (hand-rolled calendar IR removed or gated)make north-star5-verify-fastgreen after Self-host M2 spine unit: JitDateMutation + DateMutationRuntime #8702 spine mergeDateMutationRuntime.phpVerify
Links
#8702 · #4604 · #1492