]> granicus.if.org Git - php/commitdiff
Preloading: Don't move conditional functions to back to scripts
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 5 Jul 2019 08:41:39 +0000 (10:41 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 5 Jul 2019 08:46:41 +0000 (10:46 +0200)
Conditional function declaration may be referenced by functions or
classes that have been preloaded, so we should not move them back
to scripts.

What we probably should be doing though is to discard conditional
functions that are not used in the optimizer. This is probably
reasonably common for polyfills, where we will be able to const-eval
the conditions and drop the BBs declaring the functions, but won't
delete the function declarations themselves.

ext/opcache/ZendAccelerator.c

index 78260b9fe00af21a921ace9db88d324d08c0ae6d..d16ae9097c361df989141d228007f184b34e7a6e 100644 (file)
@@ -3596,7 +3596,6 @@ static void preload_link(void)
        zend_string *key;
        zend_bool found, changed;
        uint32_t i;
-       zend_op_array *op_array;
        dtor_func_t orig_dtor;
        zend_function *function;
 
@@ -3790,28 +3789,6 @@ static void preload_link(void)
        EG(class_table)->pDestructor = orig_dtor;
        zend_hash_rehash(EG(class_table));
 
-       /* Move run-time declared functions back to scripts */
-       orig_dtor = EG(function_table)->pDestructor;
-       EG(function_table)->pDestructor = NULL;
-       ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(function_table), key, zv) {
-               op_array = Z_PTR_P(zv);
-               if (op_array->type == ZEND_INTERNAL_FUNCTION) {
-                       break;
-               }
-               if (op_array->fn_flags & (ZEND_ACC_TOP_LEVEL|ZEND_ACC_CLOSURE)) {
-                       continue;
-               }
-               script = zend_hash_find_ptr(preload_scripts, op_array->filename);
-               ZEND_ASSERT(script);
-               zend_hash_add(&script->script.function_table, key, zv);
-               ZVAL_UNDEF(zv);
-               zend_string_release(key);
-               EG(function_table)->nNumOfElements--;
-       } ZEND_HASH_FOREACH_END();
-       EG(function_table)->pDestructor = orig_dtor;
-       zend_hash_rehash(EG(function_table));
-
-
        /* Remove DECLARE opcodes */
        ZEND_HASH_FOREACH_PTR(preload_scripts, script) {
                zend_op_array *op_array = &script->script.main_op_array;