Skip to content

Language: user class const fetch from global functions (#2215) - #2226

Merged
PurHur merged 2 commits into
masterfrom
issue-2215-class-const-fetch-user
May 26, 2026
Merged

PurHur merged 2 commits into
masterfrom
issue-2215-class-const-fetch-user

Conversation

@PurHur

@PurHur PurHur commented May 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Hoist DECLARE_CLASS / enum / interface opcodes before FUNCDEF in Compiler::compileOps so JIT/AOT compile member constants before function bodies that reference ClassName::CONST (MiniWebApp Router::DEFAULT_CONTACT_NAME_MAX pattern).
  • Add compliance case test/compliance/cases/classes/class_const_fetch_user.phpt, AOT fixture, and ClassConstFetchVMTest for ci-fast --filter ClassConstFetch.

Problem

examples/003-MiniWebApp/src/Router.php declares a global helper above class Router with public const. VM worked (constants exist at call time), but JIT compiles FUNCDEF bodies eagerly and previously hit Undefined class constant when TYPE_DECLARE_CLASS ran later in the opcode stream.

Test plan

Closes #2215

@PurHur

PurHur commented May 26, 2026

Copy link
Copy Markdown
Owner Author

Runforge harness verification

  • VM: Router-style `ClassName::CONST` from a function declared above the class returns `200`.
  • Lint: `./phpc lint examples/003-MiniWebApp/src/Router.php` — no unsupported nodes.
  • Opcode order: top-level `TYPE_DECLARE_CLASS` now precedes `TYPE_FUNCDEF` (see `bin/print.php`).

Not merged here: `./script/docker-ci-local.sh fast` stops on pre-existing `docs/capabilities.md` drift on `master` (before PHPUnit). JIT CLI also fails in this image during LLVM bitcode preload (`MemoryBuffer::parseBitcode`), unrelated to this diff.

Recommend merge after `make test-harness` (or full `ci-local.sh`) on a host with working LLVM 9.

@PurHur
PurHur force-pushed the issue-2215-class-const-fetch-user branch from 730537d to 70b293c Compare May 26, 2026 00:49
PurHur and others added 2 commits May 26, 2026 00:49
JIT compiles function bodies at TYPE_FUNCDEF before member constants exist
when a global function references ClassName::CONST above the class in source
(MiniWebApp Router). Emit DECLARE_CLASS/enum/interface before FUNCDEF and add
a compliance case for the Router-style pattern.

Co-authored-by: Cursor <cursoragent@cursor.com>
JIT/AOT compile member constants before function bodies that reference
ClassName::CONST (MiniWebApp Router::DEFAULT_CONTACT_NAME_MAX). Add VM/AOT
compliance tests and register ClassConstFetchVMTest for ci-fast --filter.

Closes #2215

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur force-pushed the issue-2215-class-const-fetch-user branch from 70b293c to d213e25 Compare May 26, 2026 00:49
@PurHur
PurHur merged commit 82698b1 into master May 26, 2026
@PurHur
PurHur deleted the issue-2215-class-const-fetch-user branch May 26, 2026 00:49
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.

Language: Class constant fetch on user-defined classes (Router::CONST)

1 participant