Skip to content

Fix GH-23628: Tracing JIT reads undefined property slots of lazy proxies and unset properties - #23640

Merged
arnaud-lb merged 4 commits into
php:PHP-8.5from
lisachenko:claude/php-8.5-issue-23628-rh2179
Sep 24, 2026
Merged

arnaud-lb merged 4 commits into
php:PHP-8.5from
lisachenko:claude/php-8.5-issue-23628-rh2179

Conversation

@lisachenko

Copy link
Copy Markdown
Contributor

A lazy proxy keeps its own property slots IS_UNDEF|IS_PROP_LAZY even after it has been initialized, and the object handlers forward every property access to the real instance.

This caused the #23628 bug, because the tracing JIT was not aware of this in two places:

  1. When the recorded trace contained a FETCH_OBJ_R/IS/W on a known property whose slot was IS_UNDEF, the known-offset fast path was still compiled. For a lazy proxy this path never succeeds, and it deoptimized on every execution. Use the generic code path (that falls back to the object handlers for undefined slots) when the slot was IS_UNDEF at recording time. This also covers uninitialized and unset properties.

  2. During deoptimization of a failed result type guard after FETCH_OBJ_IS, an IS_UNDEF slot was turned into NULL, assuming an undefined property. For a slot flagged IS_PROP_LAZY the fetch has to be forwarded to the real instance instead, so re-execute the opline in the VM, the same way it is already done for FETCH_OBJ_R.

…roxies

A lazy proxy keeps its own property slots IS_UNDEF|IS_PROP_LAZY even after
it has been initialized, and the object handlers forward every property
access to the real instance. The tracing JIT was not aware of this in two
places:

1. When the recorded trace contained a FETCH_OBJ_R/IS/W on a known property
   whose slot was IS_UNDEF, the known-offset fast path was still compiled.
   For a lazy proxy this path never succeeds, and it deoptimized on every
   execution. Use the generic code path (that falls back to the object
   handlers for undefined slots) when the slot was IS_UNDEF at recording
   time. This also covers uninitialized and unset properties.

2. During deoptimization of a failed result type guard after FETCH_OBJ_IS,
   an IS_UNDEF slot was turned into NULL, assuming an undefined property.
   For a slot flagged IS_PROP_LAZY the fetch has to be forwarded to the
   real instance instead, so re-execute the opline in the VM, the same way
   it is already done for FETCH_OBJ_R.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ECekMqERF8jnqBxo1cXe3V
@lisachenko

Copy link
Copy Markdown
Contributor Author

For discussion: the compile-side change also routes uninitialized or unset typed properties through the generic path when the trace recorded the slot as undefined. That's a deliberate trade, since the fast path could never succeed in that state.

@lisachenko

Copy link
Copy Markdown
Contributor Author

@iliaal could you please have a look at this PR? Not sure if @dstogov will check this PR or not. Noticed that you have recently merged relevant Tracing JIT fix #23683

@iliaal

iliaal commented Sep 14, 2026

Copy link
Copy Markdown
Member

It looks right to me, tried it on 8.5 branch and it does address the issue based on tests

@lazerg lazerg left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bukka, @Girgias, @ndossche, please review when you have time, it is a blocker for most of the people.


I independently checked this on a debug NTS build. PHP-8.4 has the same bug: both tests fail there without the fix, and the patch applies cleanly and fixes them. Since 8.4 still gets bug fixes, this probably should target PHP-8.4 and be merged up.

Lazy ghosts are affected too. Without the fix, a trace compiled on a plain Table and run on an uninitialized newLazyGhost() returns 92 from parse(100) instead of 100. A test case next to the proxy one in gh23628_002.phpt would cover it.

@ndossche
ndossche requested a review from arnaud-lb September 24, 2026 08:25
@iliaal
iliaal self-requested a review September 24, 2026 12:18

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix, I'd just maybe trim the comments a bit

@devnexen

devnexen commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

not entirely no please do not merge, let s wait Arnaud review even I can see it does not fully address the issue (I might be wrong of course).

@iliaal

iliaal commented Sep 24, 2026

Copy link
Copy Markdown
Member

not entirely no please do not merge, let s wait Arnaud review even I can see it does not fully address the issue.

Yeah, let's wait, I looked at to me it appeared fairly complete, but perhaps a 2nd look is an order, but seemed right

Comment thread ext/opcache/jit/zend_jit_trace.c Outdated
IS_PROP_UNINIT is set on declared properties that are not initialized. Those skip magic methods.

Declared properties that were unset() also need to be excluded here, so we evaluate a potential __isset / __get by repeating the opcode

Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
@lisachenko

Copy link
Copy Markdown
Contributor Author

PS. Should I also strip extra comments from the code that Claude has added?

@lisachenko

Copy link
Copy Markdown
Contributor Author

Should I also address the @lazerg comment and re-target this PR to the 8.4 branch and then we will have cascade merge?

- Update the deoptimization comments for the IS_PROP_UNINIT check: only
  uninitialized declared properties skip the magic methods, unset()
  properties and lazy object slots re-execute the opcode in the VM
- Trim the explanatory comments
- Add a test for a declared property that was unset() and is served by
  __isset()/__get() after the trace was compiled
- Add an uninitialized lazy ghost case to gh23628_002.phpt

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ECekMqERF8jnqBxo1cXe3V
@iliaal

iliaal commented Sep 24, 2026

Copy link
Copy Markdown
Member

PS. Should I also strip extra comments from the code that Claude has added?

Please, they mostly seem redundant to me

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ECekMqERF8jnqBxo1cXe3V
@arnaud-lb arnaud-lb changed the title Fix GH-23628: Tracing JIT reads undefined property slots of lazy proxies Fix GH-23628: Tracing JIT reads undefined property slots of lazy proxies and unset properties Sep 24, 2026
@arnaud-lb
arnaud-lb merged commit 3565507 into php:PHP-8.5 Sep 24, 2026
18 checks passed
arnaud-lb added a commit that referenced this pull request Sep 24, 2026
* PHP-8.6:
  Fix GH-23628: Tracing JIT reads undefined property slots of lazy proxies and unset properties (#23640)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

pull Bot pushed a commit to wudi/php-src that referenced this pull request Sep 24, 2026
* PHP-8.5:
  Fix phpGH-23628: Tracing JIT reads undefined property slots of lazy proxies and unset properties (php#23640)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants