Skip to content

php-in-php: hash_crypto_jit_runtime.c (~800 lines) — delete after VmHashNative JIT/AOT link (#5989 phase 2) #7189

Description

@PurHur

Category

php-in-php | runtime

Problem

JIT/AOT still compile and link lib/JIT/Builtin/hash_crypto_jit_runtime.c (~800 lines) for hash() / hash_hmac() / hash_file() native lowering, duplicating digest logic that already lives in PHP (ext/hash/, ext/standard/VmHashNative.php).

#5989 tracks deleting hash_crypto.c (~779 lines) from AOT runtime; this issue is the companion JIT bitcode object wired via lib/JIT/Builtin/StringHashCryptoJit.php and lib/AOT/Linker.php.

Workers should not extend this C file — port algorithms to PHP and shrink link surface.

php-src reference

Repro (failure today — C still linked)

./script/docker-exec.sh -- bash -lc 'wc -l lib/JIT/Builtin/hash_crypto_jit_runtime.c
rg -n hash_crypto_jit_runtime lib/AOT/Linker.php lib/JIT/Builtin/StringHashCryptoJit.php
./script/ci-local.sh --filter StringHashCryptoRuntimeStandalone
'
Check Today
hash_crypto_jit_runtime.c line count ~800 (must trend ↓)
Linker includes C source yes (Linker.php)
PHP path ext/standard/VmHashNative.php, ext/hash/* handlers exist on VM

Scope (this repo)

Layer Path Work
JIT lib/JIT/Builtin/StringHashCryptoJit.php, lib/JIT/Builtin/JitHash.php Lower to PHP/LLVM helpers backed by VmHashNative, not C SHA/MD5
AOT link lib/AOT/Linker.php Remove hash_crypto_jit_runtime.c from $runtimeSources when symbols satisfied
Delete lib/JIT/Builtin/hash_crypto_jit_runtime.c after AOT+JIT green
Tests existing StringHashCryptoRuntimeStandaloneTest, compliance hash*.phpt must stay green
Matrix script/capability-matrix.php no regression on hash/hmac JIT/AOT rows

PHP-in-PHP first: digest tables and update loops belong in ext/hash/ + JIT lowerers; C allowed only as thin extern until deletion proof is green.

Pairs: #5989, #5227, #7174 (HashContext incremental API).

Done when

  • lib/JIT/Builtin/hash_crypto_jit_runtime.c deleted (or ≤40-line frozen ABI stub like phpc_progress.c)
  • ./script/ci-local.sh --filter hash and --filter StringHashCrypto green on VM and JIT/AOT
  • PR body notes lines removed from C and PHP implementation path
  • No new digest logic added to runtime/*.c in the same PR

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/ci-local.sh --filter hash_hmac'
make bootstrap-selfhost-link  # when touching AOT link set

Links

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 7, 2026
  2. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#7189: replace hash_crypto_jit_runtime.c with PHP LLVM lowering from VmHashNative, delete ~800 lines C).

  3. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Handoff: full deletion of hash_crypto_jit_runtime.c requires porting sha256/sha1/md5/HMAC/PBKDF2 digest loops from VmHashNative into PHP LLVM emission (~800 lines IR). Scope matches #7078 json_decode migration. Next run should add HashCryptoNativeJit.php mirroring VmHashNative + StringGetrusage pattern, then drop C from Linker + StringHashCryptoJit bitcode path.

  4. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#7189: StringHashCryptoNativeJit LLVM from VmHashNative, delete hash_crypto_jit_runtime.c ~800 lines).

  5. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Phase 1 merged via #7480.

    C shrink: 38 lines removed from `hash_crypto_jit_runtime.c` (`__compiler_hash_equals`, `__compiler_hash_hmac_algos` deleted).

    PHP LLVM: `lib/JIT/Builtin/StringHashEquals.php`, `StringHashHmacAlgos.php` — wired from `StringHashCryptoJit::implement()` before MCJIT bitcode link.

    Verification (green): JIT compliance `hash_equals` / `hash_hmac_algos` / `hash_hmac`; JIT repro `hash_equals('abc','abc')` → true, `count(hash_hmac_algos())` → 3, `hash('sha256','x')` unchanged.

    Phase 2 handoff: port remaining digest/PBKDF2 (~762 C lines) to PHPLLVM Builder from `VmHashNative.php`, then delete `hash_crypto_jit_runtime.c` from Linker entirely.

  6. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#7189 phase 2 complete: verify StringHashCryptoNativeJit standalone LLVM + close issue).

  7. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    Merged via #7754.

    C shrink: hash_crypto_jit_runtime.c + hash_crypto.c deleted (~800 lines total, phase 1 in #7480/#7437; phase 2 completed here).

    PHP LLVM: StringHashCryptoNativeJit now emits all helper symbols (__phpc_hc_digest_len, __phpc_hc_hex_encode, __phpc_hc_result_string + digest transforms). StringHashEquals CFG/allocation fix removes standalone segfault.

    Verification (green):

    vendor/bin/phpunit --filter StringHashCryptoRuntimeStandaloneTest -c phpunit.xml.dist  # OK 2/2
    php bin/jit.php -r "echo hash_hmac('sha256','body','key'), PHP_EOL;"  # 515aae133b...
    php bin/jit.php -r "echo hash_equals('abc','abc') ? 'eq' : 'no';"     # eq
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 / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions