com php-src: Don't check type of simple parameter default values: Zend/zend_compile.c Zend/zend_vm_def.h Zend/zend _vm_execute.h
| From: | Nikita Popov | Date: | Tue, 08 Oct 2019 15:29:41 +0000 |
| Subject: | com php-src: Don't check type of simple parameter default values: Zend/zend_compile.c Zend/zend_vm_def.h Zend/zend _vm_execute.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108814@lists.php.net to get a copy of this message | ||
Commit: bea832cbf6b7a06ee65b93902233864c1ac9ec98
Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 8 Oct 2019 17:29:41 +0200
Parents: 21148679d1dfb614404c09a918d9d2b74f120640
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bea832cbf6b7a06ee65b93902233864c1ac9ec98
Log:
Don't check type of simple parameter default values
After fixing the int->double coercion case, this is already verified
at compile-time, so there is no need to redo this type check on
every call.
Only perform the type check every time for the case of AST default
values.
Changed paths:
M Zend/zend_compile.c
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 255b89d95f0..ce37710dd09 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5392,10 +5392,6 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
op_array->required_num_args = i + 1;
}
- opline = zend_emit_op(NULL, opcode, NULL, &default_node);
- SET_NODE(opline->result, &var_node);
- opline->op1.num = i + 1;
-
arg_info = &arg_infos[i];
arg_info->name = zend_string_copy(name);
arg_info->pass_by_reference = is_ref;
@@ -5443,6 +5439,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
"with a float type can only be float, integer, or NULL");
}
+ convert_to_double(&default_node.u.constant);
break;
case IS_ITERABLE:
@@ -5467,7 +5464,13 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
}
}
}
+ }
+ opline = zend_emit_op(NULL, opcode, NULL, &default_node);
+ SET_NODE(opline->result, &var_node);
+ opline->op1.num = i + 1;
+
+ if (type_ast) {
/* Allocate cache slot to speed-up run-time class resolution */
if (opline->opcode == ZEND_RECV_INIT) {
if (ZEND_TYPE_IS_CLASS(arg_info->type)) {
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 649b07d36eb..0c1ab106b3e 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -5248,17 +5248,19 @@ ZEND_VM_HOT_HANDLER(64, ZEND_RECV_INIT, NUM, CONST, CACHE_SLOT)
ZVAL_COPY_VALUE(cache_val, param);
}
}
+ ZEND_VM_C_GOTO(recv_init_check_type);
} else {
ZVAL_COPY(param, default_value);
}
- }
-
- if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) {
- zval *default_value = RT_CONSTANT(opline, opline->op2);
+ } else {
+ZEND_VM_C_LABEL(recv_init_check_type):
+ if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) {
+ zval *default_value = RT_CONSTANT(opline, opline->op2);
- SAVE_OPLINE();
- if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, default_value,
CACHE_ADDR(opline->extended_value)))) {
- HANDLE_EXCEPTION();
+ SAVE_OPLINE();
+ if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, default_value,
CACHE_ADDR(opline->extended_value)))) {
+ HANDLE_EXCEPTION();
+ }
}
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index b4a59dff0e7..f1b46fbd97d 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -3051,17 +3051,19 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL
ZEND_RECV_INIT_SPEC_CON
ZVAL_COPY_VALUE(cache_val, param);
}
}
+ goto recv_init_check_type;
} else {
ZVAL_COPY(param, default_value);
}
- }
-
- if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) {
- zval *default_value = RT_CONSTANT(opline, opline->op2);
+ } else {
+recv_init_check_type:
+ if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) {
+ zval *default_value = RT_CONSTANT(opline, opline->op2);
- SAVE_OPLINE();
- if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, default_value,
CACHE_ADDR(opline->extended_value)))) {
- HANDLE_EXCEPTION();
+ SAVE_OPLINE();
+ if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, default_value,
CACHE_ADDR(opline->extended_value)))) {
+ HANDLE_EXCEPTION();
+ }
}
}