From d3c4841b180d57b5bd65171b68043504a4598aca Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 5 Jul 2019 10:41:39 +0200 Subject: [PATCH] Preloading: Don't move conditional functions to back to scripts 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 | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 78260b9fe00..d16ae9097c3 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -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;