Skip to content

Stdlib: serialize() append-self-ref R: graph matches php-src (#22653)#22666

Merged
PurHur merged 1 commit into
masterfrom
fix/22653-serialize-append-self-ref
Jul 23, 2026
Merged

Stdlib: serialize() append-self-ref R: graph matches php-src (#22653)#22666
PurHur merged 1 commit into
masterfrom
fix/22653-serialize-append-self-ref

Conversation

@PurHur

@PurHur PurHur commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Align VmSerialize with php-src php_add_var_hash (ext/standard/var.c): scalars/arrays bump the stream index but are not stored for R: lookup; ISREF sets are keyed by the shared target Variable.
  • Fixes $a=[1]; $a[]=&$a emitting a:2:{i:0;i:1;i:1;a:2:{i:0;i:1;i:1;R:3;}} (was wrongly R:2 for the inner scalar).
  • Keeps empty self-ref (R:2), shared scalar/array refs, and object R:/r: cases matching Zend.
  • PHP-in-PHP only (ext/standard/VmSerialize.php); JIT uses the same path via SerializeJitHelper.

Closes #22653

php-src reference

  • ext/standard/var.cphp_add_var_hash / php_var_serialize_intern (IS_REFERENCE → goto again)

Verification

php bin/vm.php test/repro/issue_22653_serialize_append_self_ref.php
# a:2:{i:0;i:1;i:1;a:2:{i:0;i:1;i:1;R:3;}}

php bin/jit.php test/repro/issue_22653_serialize_append_self_ref.php
# same

./script/phpunit.sh --filter serialize_append_self_ref
# OK (2 tests, 2 assertions) — VM + JIT compliance

AOT note: exact circular repro needs AssignRef (not implemented in AOT escape lowering). Host AOT serialize([1,1]) also segfaults on current master (c:main_before_php) — pre-existing, not this diff. Shared helper will apply once AssignRef/AOT serialize runtime is healthy.

Gates (pre-claim probe): inventory OK 6454/6454; north-star5-fast red on master (gen-0 manifest mismatch #8713) — unrelated.

Made with Cursor

Align php_add_var_hash: bump n for scalars/arrays without hashing them for
R: lookup; key ISREF sets by shared target Variable so `$a=[1]; $a[]=&$a`
re-emits the scalar and emits R:3 like Zend var.c.

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

PurHur commented Jul 23, 2026

Copy link
Copy Markdown
Owner Author

Cleanup hygiene

Deleting remote branch fix/22653-serialize-append-self-ref.

Reason: PR merged into master (#22666 / 5e716a8ce); issue #22653 closed; no open PR on this head.

Open PR #22717 (agent/issue-22642-gen0-refresh-oom) and release/v1.1.0-dev left untouched.

@PurHur
PurHur deleted the fix/22653-serialize-append-self-ref branch July 23, 2026 19:44
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.

Regression: serialize() $a=[1]; $a[]=&$a — wrong R: graph (re-#12825, ext/standard/var.c)

1 participant