Skip to content

Fix AOT examples smoke LLVM verify regressions (#11206)#11213

Merged
PurHur merged 5 commits into
masterfrom
agent/issue-11206-aot-smoke-regression
Jun 24, 2026
Merged

Fix AOT examples smoke LLVM verify regressions (#11206)#11213
PurHur merged 5 commits into
masterfrom
agent/issue-11206-aot-smoke-regression

Conversation

@PurHur

@PurHur PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #11206 (partial — parentless standalone-main IR fixed; merge-block blocker remains).

  • Root cause: #10854 routed http_response_code through HttpResponseRuntime php-in-PHP JIT; emitResetForStandaloneMain() re-entered implement() during C main wrapper emit, clearing the LLVM insert block → parentless globals (__phpc_session_module_storage, __phpc_progress_note, …).
  • Fix: Context::compileToFile() repositions builder for every standalone-main emission via dedicated standalone_main BB; HttpResponseRuntime::implement() saves/restores insert block and early-returns when bridges exist; emitResetForStandaloneMain() no longer calls ensureLinked().
  • Nested helper ABI: JitNestedHelperCoerce + JitVmHelperLink bridge arg/return coercion; alignRetvalToLlvmFnReturn for typed static/pending-return paths; ListUnpackRuntime/StreamSyncJit/SessionEncodeRuntime bridge fixes.

Verification

./script/docker-exec.sh -- bash -lc './vendor/bin/phpunit test/unit/HttpResponseCodeRuntimeShrinkTest.php'
# OK (5 tests, 17 assertions)

./script/docker-exec.sh -- bash -lc './script/examples-aot-smoke.sh'
# Still fails — verify errors reduced vs master parentless failure; remaining:
#   Terminator found in the middle of a basic block! label %try_merge_27788
#   SessionEncodeJitHelper encodeWire hashtable→object ABI mismatch
#   i64/i32 return mismatches in nested helpers

Baseline: examples-aot-smoke.sh green at 1d13db7ba; red on current master (parentless globals).

Remaining (handoff)

  1. try_merge_* BB gets terminator mid-block during InfoJitHelper nested compile (TryCatchHelper::compileIncludedAtEntry merge path).
  2. SessionEncodeJitHelper::encodeWire — bridge passes __hashtable__*, compiled helper expects __object__*; similar __value__*/__string__* mismatches on session create-id helpers.
  3. Audit other php-in-PHP JIT bridges added after 1d13db7ba for the same insert-block / ABI pattern.

@PurHur

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Maintainer review (2026-06-24): Verified bootstrap gates green on master (bootstrap-selfhost-link, helloworld, inventory 3016/3016). Re-ran targeted repro from PR description — agree this is not merge-ready while examples-aot-smoke.sh still fails on try_merge_* terminator. Good progress (verify errors down from ~50+). Handoff items in PR body match remaining blocker. Will merge once smoke is green end-to-end.

@PurHur

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

claim: cursor-agent-lane-c — continuing handoff (issue #11213 / parent #11206 AOT smoke)

@PurHur

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Update (lane-B continuation)

Pushed nested-helper ABI coercion:

  • JitNestedHelperCoerce::coerceArgToHelper / coerceReturnFromHelper__value__* ↔ typed pointers, i64 scalars, object/hashtable bitcasts
  • JitVmHelperLink::callCompiled — shared entry for all php-in-PHP JIT bridges
  • Bulk bridge migration via script/convert-helper-calls.php (87 Builtin files)
  • alignRetvalToLlvmFnReturn on main compileBlockEnd return path

Verification

./script/docker-exec.sh -- bash -lc './vendor/bin/phpunit test/unit/HttpResponseCodeRuntimeShrinkTest.php'
# OK (5 tests, 17 assertions)

./script/docker-exec.sh -- bash -lc './phpc build -o /tmp/hw /compiler/examples/000-HelloWorld/example.php'
# LLVM verify still fails (down from ~50+ mismatches to 3 classes):
#   - parentless @__compiler_get_include_path call
#   - ret i64 vs i32 in nested helper bodies
#   - try_merge_* terminator mid-block (InfoJitHelper nested compile)

examples-aot-smoke.sh not green yet — not merging until smoke passes.

#11206).

Reposition C main wrapper emissions via standalone_main BB, avoid
re-entering HttpResponseRuntime::implement during reset, and add nested
helper ABI coercion (JitNestedHelperCoerce, JitVmHelperLink bridges).

Smoke still blocked on try_merge terminator + SessionEncode helper ABI;
handoff on issue #11206.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur force-pushed the agent/issue-11206-aot-smoke-regression branch from d3505f8 to 0548944 Compare June 24, 2026 15:11
).

Extend JitNestedHelperCoerce for bridge callHelper/scalar coercion, route
StringInfo and ReadonlyRaise bridges through it, align merge-block returns,
and split try_merge header/body with open insert-block for TYPE_TRY.

Smoke still fails LLVM verify (try_merge / nested-helper returns); handoff on #11206.

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

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Update (lane C continuation)

Pushed 88c4c0cc1 with additional bridge coercion + try/catch merge work.

Changes

  • Extended JitNestedHelperCoerce (callHelper, scalar/pointer coercion helpers)
  • StringInfo + ReadonlyRaise bridges use coercion (fixes i1/i8 icmp + nullable string ABI)
  • TryCatchHelper::beginTry: prefer open insert block; try_merge header/body split
  • JIT.php: alignRetvalToLlvmFnReturn on merge-block returns; compileIncludedAtEntry insert-block guard

Verification

./script/docker-exec.sh -- bash -lc './vendor/bin/phpunit test/unit/HttpResponseCodeRuntimeShrinkTest.php'
# OK (5 tests, 17 assertions)

./script/docker-exec.sh -- bash -lc './script/examples-aot-smoke.sh'
# Still fails LLVM verify — try_merge / nested-helper i32/i64 returns / phi-not-in-block in ProgressNoteJitHelper compile

Next steps

  1. Finish SessionEncode / date builtin bridges (callHelper + coerceToHashtablePtr) — same pattern as StringInfo
  2. Debug try_merge_body_* showing unreachable only — merge CFG not lowering into body BB
  3. Re-run smoke until green, then merge

@PurHur

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Maintainer triage (local verify): not merging — smoke still red per PR verification block.

Re-ran mandatory bootstrap gates on master workspace: bootstrap-selfhost-link + bootstrap-selfhost-helloworld both green (gen-0 sidecar path).

HttpResponseCodeRuntimeShrinkTest not re-run this pass; merge blocked until ./script/examples-aot-smoke.sh is green vs the three remaining handoff items (try_merge BB, SessionEncode hashtable→object ABI, nested-helper return coercion audit).

Route getdate/localtime/gmgetdate, session encode/create-id, and include-path
bridges through JitNestedHelperCoerce; restore LLVM insert blocks after
ensureLinked; harden JitVmHelperLink and alignRetval fallbacks for i8/i64 and
pointer returns.

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

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Lane B continuation (df95506a3)

Widens nested-helper ABI coercion beyond the initial HttpResponse/try_merge fixes.

Changes

  • JitNestedHelperCoerce: coerceBridgeResult, i8→i64 arg/return coercion
  • JitVmHelperLink: always coerceArgForHelper + coerceBridgeResult
  • Bridges: StringGetdate, StringLocaltime, StringGmgetdate, SessionEncodeRuntime, SessionCreateIdRuntime use callHelper + typed result extractors
  • IncludePathRuntime / StringInfo: save+restore LLVM insert block after ensureLinked (fixes parentless __compiler_get_include_path under IniRuntime)
  • JIT::alignRetvalToLlvmFnReturn: fallback to functionReturnType when LLVM sig missing; pointer/int catch-all

Verification (Docker ./script/docker-exec.sh)

./vendor/bin/phpunit test/unit/HttpResponseCodeRuntimeShrinkTest.php
# OK (5 tests, 17 assertions)

./script/examples-aot-smoke.sh
# FAIL — improved vs master parentless globals; remaining LLVM verify:
#   ret __object__* vs __hashtable__* (1 fn)
#   ret i64 vs i32 (3 fn)
#   terminator mid-block label %block_917

Master baseline still fails earlier with parentless session/progress globals.

Next

  • Identify the 4 mis-typed return functions (likely compiled php-in-PHP helpers bypassing alignRetval)
  • Seal %block_917 — probably insert-block restore missing in another Type/String_.php implement() callee

@PurHur

PurHur commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Update — LLVM verify + link green (runtime handoff)

Pushed commit 2ba2764b9 extending nested-helper ABI coercion across date/session/include-path/meta-tags/stream-filter bridges, try-branch terminator guard, and phpc_fn_static_init_table zeroinit.

Verification

./script/docker-exec.sh -- bash -lc './script/examples-aot-smoke.sh'
# 000-HelloWorld: phpc build OK (LLVM verify + link pass)
# binary exit 139 — segfault after `c:main_before_init`
./script/docker-exec.sh -- bash -lc 'php bin/vm.php examples/000-HelloWorld/example.php'
# Hello World

Not merging — issue acceptance requires examples-aot-smoke.sh exit 0 (runtime segfault during initFunc remains).

PurHur and others added 2 commits June 24, 2026 15:53
Route php-in-PHP JIT bridges through JitNestedHelperCoerce for hashtable/string/scalar
mismatches; guard try-branch terminators; define phpc_fn_static_init_table with zeroinit.

LLVM verify + link green for examples/000-HelloWorld; runtime still segfaults at c:main_before_init.

Co-authored-by: Cursor <cursoragent@cursor.com>
#11206).

Try/catch merge lowering pins header/body LLVM blocks; MetaTags and stream-filter
bridges coerce nested helper returns; function-static init table gets a zeroinit
global; Ini include-path bridges restore insert block after ensureLinked.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur merged commit 63d55e1 into master Jun 24, 2026
@PurHur PurHur deleted the agent/issue-11206-aot-smoke-regression branch June 24, 2026 15:56
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.

Release v1.1.0: fix examples 000–009 AOT smoke regression (LLVM Module.php)

1 participant