Skip to content

JIT: try/catch/finally lowering phase 2 (#57, after VM #2084) #2114

Description

@PurHur

Category

language

Problem

#57 tracks VM try/catch/finally lowering; #2084 ✅ adds compliance PHPTs for phase 1. JIT still has no exception unwind model — phpc serve --jit and JIT compliance for caught exceptions remain blocked after VM lands.

#195 throw expressions need a catch target in JIT for 007-ThrowsWeb matrix parity (#2103). VM path for 007 is largely green; JIT column is the gap.

php-src reference

  • Zend/zend_compile.c — zend_compile_try(), catch/finally op array layout
  • Zend/zend_exceptions.c — zend_throw_exception_internal, unwind stack
  • Zend/zend_execute.c — ZEND_HANDLE_EXCEPTION, ZEND_FAST_RET, finally before catch
  • LLVM analogue: landing pads / invoke + personality (see docs/capabilities-syntax.md try row)

Repro (today)

<?php
try {
    throw new Exception('boom');
} catch (Exception $e) {
    echo $e->getMessage();
}
# VM — passes (#2084 compliance)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
# → boom

# JIT — gap (VM fallback or LogicException depending on build)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro.php'

# Compliance gate
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/JITTest.php --filter try_catch'

Done when JIT repro prints boom without requiring full-VM fallback for this script.

Finally slice:

<?php
try {
    throw new Exception('x');
} finally {
    echo 'fin';
}

Scope

Phase A — VM fallback bridge (fastest slice)

Layer Files Notes
JIT lib/JIT.php TYPE_TRY / catch: documented VM bridge or requiresVmLowering
Registry lib/Lint/UnsupportedRegistry.php Narrow try/catch kinds when bridge exists
Caps script/capability-syntax.php JIT row: partial until phase B

Phase B — LLVM landing pads (full parity)

Layer Files Notes
Compiler lib/Compiler.php Exception edges for JIT EH tables
JIT lib/JIT.php, lib/JIT/TryCatchHelper.php Landing pads / invoke-unwind (LLVM 9)
AOT lib/AOT/ Share EH metadata (#2101)
Tests test/compliance/cases/php/basic/try_catch_*.phpt Shared with #2084

Done when

  • JIT repro (bin/jit.php repro.php) prints boom for basic try/catch
  • vendor/bin/phpunit test/compliance/JITTest.php --filter try_catch green on php-compiler:22.04-dev
  • Finally block runs before catch on JIT path (or documented deferral with linked issue)
  • docs/capabilities-syntax.md try row JIT = yes (or partial + bridge documented)
  • ./script/ci-local.sh LLVM tail includes JIT try/catch when @group llvm runs

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/JITTest.php --filter try_catch'
make test-harness ARGS='--filter try_catch'
./script/ci-fast.sh

Dependencies

Links

Activity

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 / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions