Uh oh!
There was an error while loading. Please reload this page.
VAR|TMP overhaul - #20628
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
2a3d9dd to
9ddff66Compare
This comment was marked as outdated.
This comment was marked as outdated.
Uh oh!
There was an error while loading. Please reload this page.
0e52da0 to
4ad5861Compare| if ((t1 & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY && MAY_BE_EMPTY_ONLY(t1)) { | ||
| return false; | ||
| } | ||
| return true; |
There was a problem hiding this comment.
YIELD_FROM from generators can throw if the generator is closed, even for empty arrays. So this optimization may be unsound.
There was a problem hiding this comment.
I would not mind doing the inverse - changing YIELD_FROM to not throw on empty array, though...
There was a problem hiding this comment.
Taking into account the "closed" generator, this is wrong.
dstogov
left a comment
There was a problem hiding this comment.
I think this should work, but the effect is not great.
(I see 30KB reduction in PHP code size and very slight performance difference).
The path breaks Symfony demo with function JIT (probably because of missing changes in FETCH_(DIM|OBJ)_FUNC_ARG handlers). This needs to be fixed of course.
| if (src < op_array->opcodes + block->start) { | ||
| break; | ||
| } | ||
| src->result_type = IS_UNUSED; | ||
| VAR_SOURCE(opline->op1) = NULL; | ||
| MAKE_NOP(opline); | ||
| ++(*opt_count); | ||
| if (src->op1_type & (IS_VAR|IS_TMP_VAR)) { | ||
| src->opcode = ZEND_FREE; |
There was a problem hiding this comment.
Replacing QM_ASSIGN with FREE opens possibility to deeper application of the same optimization.
Uh oh!
There was an error while loading. Please reload this page.
| if ((t1 & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY && MAY_BE_EMPTY_ONLY(t1)) { | ||
| return false; | ||
| } | ||
| return true; |
There was a problem hiding this comment.
Taking into account the "closed" generator, this is wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
dstogov
commented
Dec 22, 2025
I think the patch makes sense, but still has problems. |
iluuu1994
commented
Dec 22, 2025
Thank you, I missed those. I'll have a look. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
0f72e19 to
ca60df5CompareAWS x86_64 (c7i.24xl)
Laravel 12.11.0 demo app - 100 consecutive runs, 50 warmups, 100 requests (sec)
Symfony 2.8.0 demo app - 100 consecutive runs, 50 warmups, 100 requests (sec)
Wordpress 6.9 main page - 100 consecutive runs, 20 warmups, 20 requests (sec)
bench.php - 100 consecutive runs, 10 warmups, 2 requests (sec)
|
39de75b to
7fa98fdCompare0c56d0d to
838adceCompare399ef34 to
824a4abCompareUh oh!
There was an error while loading. Please reload this page.
mbeccati
commented
Feb 1, 2026
@iluuu1994 I'm afraid there are issues with this commit. In my CI both Symfony and Revive Adserver cannot run the test suite. Symfony 7.4 doesn't even start: In order to replicate just clone symfony 7.4, run composer install, then run ./phpunit with a freshly compiled php from master. In the Revive Adserver suite, I'm getting: In this case it might just be some deprecation being promoted to error perhaps. Code is very much legacy, so it might just be something that needs to be adjusted on our side. I will report back my findings on this. |
iluuu1994
commented
Feb 1, 2026
@mbeccati Thanks for letting me know. I'll have a look today. I did test this change with nightly, which runs all Symfony tests (along with many others). |
@iluuu1994 Thanks! I can confirm that the Revive Test Suite fails to run because of: vs: which I'm totally OK with, but will probably need to be listed in UPGRADING (or RFC?). Simple enough to replicate: |
iluuu1994
commented
Feb 1, 2026
@mbeccati Changing behavior was not the intention. I'll make sure this keeps working. The first case might just be a bad assertion, we'll see. |
@mbeccati The first issue should be solved. It was just a faulty assertion ("surely adding this code after testing is fine, right?"). The other will take more consideration. Sadly, PHP has inconsistent error types when passing non-vars as references: https://3v4l.org/lE72G Maybe it wouldn't be such a bad idea to unify this case after all, but that would need an RFC. I'll see how easy it is to find a resolution tonight, I'm out of time for now. |
iluuu1994
commented
Feb 2, 2026
@mbeccati After thinking about this some more, and discussing with @bwoebi, I think the second case can be considered a fix. As mentioned, PHP already errors when things that can never be references are passed to by-ref parameters. For example: namespaceFoo;
functiontakesRef(&$ref) {}
takesRef(count([])); // This will warntakesRef(\count([])); // This will throwThe first may be a locally-shadowing |
mbeccati
commented
Feb 2, 2026
@iluuu1994 I agree about the behaviour, but I'm not convinced 100% we can get away with it without a proper RFC. |
bwoebi
commented
Feb 2, 2026
@mbeccati What would need a RFC would be reversing the behaviour. This is a pure bugfix. |
Fixes OSS-Fuzz #481017027 Introduced in phpGH-20628
mbeccati
commented
Feb 3, 2026
My point is that the bug has existed long enough that the bugfix is effectively a BC-break. Either way I'm fine with it, as I've been busy fixing the legacy code that was not working with master anymore. |
bwoebi
commented
Feb 3, 2026
@mbeccati Yes, that happens. I've also fixed a handful of long-standing bugs recently - in the end it's still considered a bugfix, but only applied to the next minor version (rather than patch version). |
Fixes OSS-Fuzz #481017027 Introduced in GH-20628
Fixes OSS-Fuzz #481014628 Introduced in phpGH-20628
Fixes OSS-Fuzz #480111866 Introduced in phpGH-20628
Fixes OSS-Fuzz #481014628 Introduced in GH-20628 Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
The aim of this PR is twofold:
This is achieved by guaranteeing that all zend_compile_expr() calls, as well as all other compile calls with BP_VAR_R, will result in a TMP variable. This implies that the result will not contain an IS_INDIRECT or IS_REFERENCE value, which was mostly already the case, with two exceptions:
Calls to return-by-reference functions. Because return-by-reference functions are quite rare, this is solved by delegating the DEREF to the RETURN_BY_REF handler, which will examine the stack to check whether the caller expects a VAR or TMP to understand whether the DEREF is needed.
By-reference assignments, including both
$a = &$b, as well as[&$a] = $b. When the result of these expressions is used in a BP_VAR_R context, it will be passed to a new ZEND_DEREF opcode beforehand. This is exceptionally rare.Preliminary testing shows a 1.1% wall time improvement in Symfony Demo and roughly 0.5% in Wordpress. Edit: Sadly I can now only measure a 0.15% improvement for Symfony, but 0.8% for Wordpress. Zend/bench.php improves by ~3% in my tests. There seems to be quite a bit of volatility involved, potentially in relation to binary layout. Regardless, I think this is unlikely to cause true slowdowns for code that doesn't use return-by-ref.
TODOs:
zend_unwrap_reference(). I missed this function, I was looking for a macro.DEREFwithQM_ASSIGN.R/IScompile-paths, asserting noVARs are generated.