Skip to content

Fix AOT ?? compile lowering for superglobals (partial #148)#464

Open
PurHur wants to merge 1 commit into
masterfrom
fix/aot-coalesce-compile-prep
Open

Fix AOT ?? compile lowering for superglobals (partial #148)#464
PurHur wants to merge 1 commit into
masterfrom
fix/aot-coalesce-compile-prep

Conversation

@PurHur
Copy link
Copy Markdown
Owner

@PurHur PurHur commented May 21, 2026

Summary

  • Skip duplicate ArrayDimFetch before ?? when php-cfg emits a ConstFetch (e.g. default literal) between fetch and Coalesce (findsCoalesceUsingFetchAsLeft).
  • Defer leftBlock scope inheritance until after ISSET is lowered (avoids slot collision with the isset temp).
  • Do not call freeDeadVariables on the coalesce branch block before LLVM branch lowering (merge target was freed early).
  • Refresh endBlock scope after coalesce branches are wired.
  • Pass dim operand into dimFetch for compile-time string keys; expose IssetHelper::literalStringKey.

Test output (Docker php-compiler:22.04-dev, tar pipe)

script/install-llvm9.sh
export PATH="$PWD/.llvm/bin:$PATH"
export PHP_COMPILER_LLVM_PATH="$PWD/.llvm"
vendor/bin/phpunit --group aot-link --exclude-group serve
Tests: 118, Assertions: 645, Failures: 1.

Remaining failure (blocks merge for full #148)

1) PHPCompiler\AotTest::testCases with data set #18 ('AOT: $_GET['name'] ?? default... #148)')
--- Expected
+++ Actual
@@ @@
-'Ada'
+''

/compiler/test/BaseTest.php:207
/compiler/test/aot/AotTest.php:178

Repro:

printf '%s\n' '<?php' '$name = $_GET["name"] ?? "Guest";' 'echo $name, "\n";' > /tmp/coalesce.php
php bin/compile.php -q name=Ada -o /tmp/coalesce /tmp/coalesce.php
QUERY_STRING=name=Ada /tmp/coalesce   # prints newline only

Tracked as the separate LLVM merge fix called out in commit e02df36 (AOT/JIT coalesce on runtime superglobals remains a separate LLVM merge fix).

Test plan

  • vendor/bin/phpunit --group aot-link --exclude-group serve in Docker (117/118 pass)
  • coalesce_get_present.phpt AOT output Ada (still open)
  • Full ./script/ci-local.sh in Docker when LLVM merge is fixed

Made with Cursor

Skip eager ArrayDimFetch before coalesce when php-cfg inserts ConstFetch
between fetch and Coalesce; defer leftBlock scope inherit until after ISSET;
avoid freeing the merge target before branch lowering; refresh endBlock
scope after wiring branches.

Pass dim operand into dimFetch for literal keys. Do not free coalesce
result before branch JIT (issue #99).

Remaining: coalesce_get_present.phpt still prints empty at AOT runtime
(LLVM merge of branch assignments into coalesce result — see #148).

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.

1 participant