Skip to content

Deprecate autovivification on false #7131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from

Conversation

kamil-tekiela
Copy link
Member

@kamil-tekiela kamil-tekiela commented Jun 9, 2021

@kamil-tekiela kamil-tekiela marked this pull request as ready for review June 11, 2021 13:52
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

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

This will also need adjustments in zend_jit_helpers.c (grep for the error message).

@kamil-tekiela
Copy link
Member Author

I have tried using this code in the test, but it doesn't even compile.

<?php

class A
{
    public  const array1 = [false];
}

A::array1[0][] = 42;

I get the error:

Cannot use temporary expression in write context

@kamil-tekiela kamil-tekiela changed the title WIP: Deprecate autovivification on false Deprecate autovivification on false Jun 15, 2021
@kamil-tekiela kamil-tekiela force-pushed the autovivication branch 2 times, most recently from cbd0f93 to 393aa51 Compare June 15, 2021 12:52
@nikic nikic force-pushed the autovivication branch from f8c4304 to 7a18e81 Compare July 7, 2021 15:30
@nikic
Copy link
Member

nikic commented Jul 7, 2021

@dstogov Could you please take a look at my JIT implementation? I assumed it would be best to move handling of false to the slow path entirely, rather than generating JIT code to emit the deprecation. Does this make sense to you?

@nikic nikic force-pushed the autovivication branch from 7a18e81 to 8c8ce03 Compare July 8, 2021 09:01
@nikic
Copy link
Member

nikic commented Jul 8, 2021

The arm64 build fails in zend_vm_execute.h, but I don't understand the error at all. There are no interesting changes to zend_vm_def.h and nothing that is ARM specific.

@nikic nikic added this to the PHP 8.1 milestone Jul 14, 2021
@nikic
Copy link
Member

nikic commented Jul 15, 2021

@shqking Do you have an idea where the ARM build failure on Travis is coming from? It's failing to build zend_execute.c, which doesn't have ARM specific code, so I'm a bit stumped.

@shqking
Copy link
Contributor

shqking commented Jul 15, 2021

@shqking Do you have an idea where the ARM build failure on Travis is coming from? It's failing to build zend_execute.c, which doesn't have ARM specific code, so I'm a bit stumped.

Hi @nikic as commented in this file zend_jit_arm64.dasc, I think one ')' is removed by accident. In my local machine, the building succeeds if we fix this typo.

@nikic
Copy link
Member

nikic commented Jul 15, 2021

@shqking Thanks! Unfortunately, the build still fails after fixing the typo: https://app.travis-ci.com/github/php/php-src/jobs/524706767#L1960

@shqking
Copy link
Contributor

shqking commented Jul 15, 2021

@shqking Thanks! Unfortunately, the build still fails after fixing the typo: https://app.travis-ci.com/github/php/php-src/jobs/524706767#L1960

It seems like one compiler warning.

However, in my local machine Ubuntu20+gcc10 (Ubuntu18+gcc7 is used in travis-ci)), using the same configure options as travis-ci, I didn't get this compiler warning. Let me try more times...

./configure --enable-option-checking=fatal --prefix=/home/travis/php-install --enable-debug --enable-zts --enable-phpdbg --enable-fpm --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-pgsql --with-pdo-pgsql --with-pdo-sqlite --enable-intl --without-pear --enable-gd --with-jpeg --with-webp --with-freetype --with-xpm --enable-exif --with-zip --with-zlib --with-zlib-dir=/usr --enable-soap --enable-xmlreader --with-xsl --with-tidy --enable-sysvsem --enable-sysvshm --enable-shmop --enable-pcntl --with-readline --enable-mbstring --with-curl --with-gettext --enable-sockets --with-bz2 --with-openssl --with-gmp --enable-bcmath --enable-calendar --enable-ftp --with-pspell=/usr --with-enchant=/usr --with-kerberos --enable-sysvmsg --with-ffi --with-sodium --enable-zend-test=shared --enable-werror --with-pear

@nikic
Copy link
Member

nikic commented Jul 15, 2021

Okay, I suspect this is some kind of race condition in our build system, where we try to regenerate zend_vm_execute.h while building zend_execute.c. Probably the only relation this has to ARM is that the ARM builder on Travis has high parallelism. I'm not sure what exactly is wrong, but looking at the order in the log it seems plausible.

@shqking
Copy link
Contributor

shqking commented Jul 15, 2021

I still cannot reproduce this failure in my environment.

Yes. Your conjecture sounds reasonable.

@shqking
Copy link
Contributor

shqking commented Jul 16, 2021

The building on arm64 machine can pass now, but JIT/arm64 failed for the new test case, i.e. falsetoarray.phpt.

The error might be related to the opcode sequence ZEND_FETCH_DIM_W -> ZEND_ASSIGN_DIM.
As note in https://github.com/php/php-src/blob/master/ext/opcache/jit/zend_jit_arm64.dasc#L14027, RAX is reused in JIT/x86, I suspect in JIT/arm64, the corresponding REG0 doesn't hold the expected address.

Let me dig it deeper.

@shqking
Copy link
Contributor

shqking commented Jul 16, 2021

The patch below can fix this test failure.

diff --git a/ext/opcache/jit/zend_jit_arm64.dasc b/ext/opcache/jit/zend_jit_arm64.dasc
index 94595b66f7..1d93b298b7 100644
--- a/ext/opcache/jit/zend_jit_arm64.dasc
+++ b/ext/opcache/jit/zend_jit_arm64.dasc
@@ -11222,9 +11222,11 @@ static int zend_jit_fetch_dim(dasm_State    **Dst,
                        case ZEND_FETCH_DIM_W:
                        case ZEND_FETCH_LIST_W:
                                |       EXT_CALL zend_jit_fetch_dim_obj_w_helper, REG0
+                               |       mov REG0, RETVALx
                                break;
                        case ZEND_FETCH_DIM_RW:
                                |       EXT_CALL zend_jit_fetch_dim_obj_rw_helper, REG0
+                               |       mov REG0, RETVALx
                                break;
 //                     case ZEND_FETCH_DIM_UNSET:
 //                             |       EXT_CALL zend_jit_fetch_dim_obj_unset_helper, REG0

In JIT/x86, the return register, i.e. r0, is updated silently in [1]. However, when implementing JIT/arm64, we thought the return value of function zend_jit_fetch_dim_obj_rw_helper() is void, and hence mov REG0, RETVALx is omitted.

It seems that the return register is updated by one callee inside function zend_jit_fetch_dim_obj_rw_helper(). I suspect it's [2], which is added in this patch.
Note that this return value, i.e. r0 in x86 or REG0 in arm64 is used at [3] and [4] in JIT/x86 and JIT/arm64 respectively.

[1] https://github.com/php/php-src/blob/master/ext/opcache/jit/zend_jit_x86.dasc#L11883
[2] https://github.com/php/php-src/pull/7131/files?file-filters%5B%5D=.c&file-filters%5B%5D=.dasc&file-filters%5B%5D=.phpt#diff-8cb8c8a4f53eff1333144fb356d40fef020fffec5743f744da4547fc6b9526bdR1083
[3] https://github.com/php/php-src/blob/master/ext/opcache/jit/zend_jit_x86.dasc#L14877
[4] https://github.com/php/php-src/blob/master/ext/opcache/jit/zend_jit_arm64.dasc#L14027

IMHO, the workaround can fix the test failure, but I don't think it's a good fix...

Besides, with this workaround, I tested all the .phpt test cases under tests/, Zend/tests, ext/opcache/tests/jit/ with tracing JIT on arm64, and didn't find any test failure.

nikic added 3 commits July 16, 2021 11:40
Move handling of false to the slow path.
We now may_throw for MAY_BE_FALSE. Also don't set
indirect_feference in this case, as we now go through the slow
path and the container isn't guaranteed to be in r0/REG0 anymore.
@nikic
Copy link
Member

nikic commented Jul 16, 2021

I believe the build system race condition should be fixed by 3025126.

I've tried to address the problem you mention in 8c2c5d9, by not setting the indirect_reference flag for MAY_BE_FALSE containers. That is, if we go through the slow path of fetch_dim, also bypass this optimization. Does that seem like a reasonable solution?

@shqking
Copy link
Contributor

shqking commented Jul 16, 2021

I believe the build system race condition should be fixed by 3025126.

I've tried to address the problem you mention in 8c2c5d9, by not setting the indirect_reference flag for MAY_BE_FALSE containers. That is, if we go through the slow path of fetch_dim, also bypass this optimization. Does that seem like a reasonable solution?

LGTM. Thanks.

@dstogov
Copy link
Member

dstogov commented Jul 19, 2021

I checked only the JIT part and the general approach looks fine.

@nikic nikic closed this in 052af90 Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants