Skip to content

php-in-php: DateMutationRuntime LLVM helpers — share calendar math with VmDateTimeNative (ext/date, #8702) #8770

Description

@PurHur

Category

php-in-php | bootstrap

Problem

Date arithmetic exists in two parallel implementations:

  1. VM path: ext/standard/VmDateTimeNative.php (PHP) — applyIntervalState, modifyRelative, diffTimestamps
  2. 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

  • VM and JIT/AOT date_add / date_sub / date_modify / date_diff agree on compliance matrix
  • DateMutationRuntime.php LLVM IR line count shrinks (hand-rolled calendar IR removed or gated)
  • make north-star5-verify-fast green after Self-host M2 spine unit: JitDateMutation + DateMutationRuntime #8702 spine merge
  • PR body cites lines removed from DateMutationRuntime.php

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevEx

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions