Skip to content

hash: JIT/AOT incremental hash_init/update/final/copy (#3357)#17087

Open
PurHur wants to merge 3 commits into
masterfrom
agent/issue-3357-hash-context-aot
Open

hash: JIT/AOT incremental hash_init/update/final/copy (#3357)#17087
PurHur wants to merge 3 commits into
masterfrom
agent/issue-3357-hash-context-aot

Conversation

@PurHur

@PurHur PurHur commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implement JIT/AOT lowering for hash_init(), hash_update(), hash_final(), and hash_copy() via JitHashContext (php-src ext/hash/hash.c).
  • Buffer incremental digest state on internal HashContext object properties (__hcAlgo, __hcData, __hcLive); finalize through existing JitHash::hash() / __compiler_hash.
  • Fix StringHashCryptoPhp bridge to coerce ABI i32 raw flags to helper i1 (JitNestedHelperCoerce) — unblocks AOT module verify for hash crypto.

php-src reference

  • ext/hash/hash.cphp_hash_init/update/final/copy

PHP implementation

Verification

# VM (green)
php bin/vm.php test/repro/hash_context_incremental.php
vendor/bin/phpunit --filter hash_context_incremental

# AOT compile (green in Docker)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/compile.php -o /tmp/hash_ctx test/repro/hash_context_incremental.php'
# COMPILE:0

# AOT execute (NOT green yet — startup segfault when update/final are in the same binary)
./script/docker-exec.sh -- bash -lc '/tmp/hash_ctx'
# phpc: fatal signal (segfault) after c:main_before_php

hash_init() alone AOT-runs; combining hash_update/hash_final in one binary currently segfaults at standalone main before user PHP. Next step: bisect LLVM IR from hash_update property concat + JitHash::hash finalize path.

Closes #3357 when AOT execute is green.

Made with Cursor

Wire hash_init/update/final/copy through JitHashContext with HashContext
object property buffering and JitHash::hash for finalize. Fix
StringHashCryptoPhp bridge i32→i1 coercion for AOT module verify.

VM + AOT compile verified; AOT execute still under investigation when
update/final are linked in the same binary (startup segfault in Docker).

php-src: ext/hash/hash.c
Co-authored-by: Cursor <cursoragent@cursor.com>
Store __hcAlgo/__hcData/__hcLive on HashContext as native string property
slots (not TYPE_VALUE boxes) so propertyFetch round-trips for hash_final().
Deep-copy strings in hash_copy(); defer StringHashCrypto link to hash_final.

VM/JIT repro green; AOT execute still empty output (follow-up on #3357).

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur

PurHur commented Jul 7, 2026

Copy link
Copy Markdown
Owner Author

Maintainer triage: VM repro + compile green per PR body; AOT execute still segfaults/empty — holding merge until Closes #3357 execute path is green. Bootstrap link + helloworld gates green on master (2026-07-07).

Pre-register __hcAlgo/__hcData/__hcLive on HashContext before allocate()
so JIT objects get three string property slots. Read/write digest buffers
via direct slot load/store instead of propertyFetch (avoids double
__string__separate on store).

VM repro green; AOT still segfaults on hash_update/hash_copy/hash_final
(read path) — next: bisect loadStringPtrProperty vs StringHashCrypto init.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: hash_init() / hash_update() / hash_final() / hash_copy() — incremental ext/hash API

1 participant