Skip to content

JIT: stub external Class::method for self-host bundle (Fixes #579) - #583

Merged
PurHur merged 1 commit into
masterfrom
fix/issue-579-external-method-stubs
May 22, 2026
Merged

JIT: stub external Class::method for self-host bundle (Fixes #579)#583
PurHur merged 1 commit into
masterfrom
fix/issue-579-external-method-stubs

Conversation

@PurHur

@PurHur PurHur commented May 22, 2026

Copy link
Copy Markdown
Owner

Summary

Implements Option A from #579: at JIT compile time, undefined Class::method and static Class::method dispatches are bound to JIT\Call\ExternalMethod stubs instead of aborting.

  • Instance/static calls: Context::resolveFunctionProxy() lazily registers ExternalMethod, which records the proxy name in Context::$externalMethodStubs and emits LLVM that returns null (__value__writeNull). No Zend/vendor code runs in the native binary.
  • External classes: Object_::lookup() registers unknown class names (e.g. ReflectionClass, PhpParser\NodeTraverser) so new and instanceof lowering can proceed.
  • Static calls: TYPE_STATICCALL_INIT now uses the same proxy path as instance calls (master already called resolveFunctionProxy for instance calls but the implementation was missing).

Progress (Docker php-compiler:22.04-dev)

Before After
Call to undefined method phpparser\nodetraverser::addvisitor (and similar) JIT proceeds past vendor method calls
Next blocker on bundled compile: IteratorHelper / __value__ literals (separate issues)

php bin/compile.php -l test/bootstrap-aot/external_method_stub.php passes.

Stubbed vs implemented

API Treatment
Any bundled Class::method without a compiled TYPE_DECLARE_METHOD body Stub → returns null
phpcompiler\… methods with CFG in the bundle Implemented (existing Call\Native proxies)
Builtin/internal proxies (is_string, VM context, …) Implemented (unchanged)

Runtime introspection: after a successful link, JIT\Context::$externalMethodStubs lists proxy names touched during codegen (e.g. phpparser\nodetraverser::addvisitor).

Test plan

  • phpunit test/unit/JitExternalMethodStubTest.php (Docker)
  • php bin/compile.php -l test/bootstrap-aot/external_method_stub.php
  • ./script/bootstrap-selfhost-link.sh (still fails past IteratorHelper; progress gate only)

Fixes #579

Made with Cursor

Option A: lazily register ExternalMethod proxies that return null instead of
failing JIT on vendor APIs (PhpParser NodeTraverser::addVisitor, etc.).
Register unknown class names for `new` and static dispatch; add lint smoke
test and bootstrap-selfhost-link progress gate script.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit c193c7c into master May 22, 2026
@PurHur
PurHur deleted the fix/issue-579-external-method-stubs branch May 22, 2026 16: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.

Self-host P0: JIT external class method calls in bundled lib (PhpParser, etc.)

1 participant