Skip to content

Commit 3621a19

Browse files
committed
Make flag meaning more precise
Separately track the concept of "undef args" and "extra args", to make this more amenable to future optimization.
1 parent a205302 commit 3621a19

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

Zend/zend_compile.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,14 +3308,21 @@ static uint32_t zend_get_arg_num(zend_function *fn, zend_string *arg_name) {
33083308
return (uint32_t) -1;
33093309
}
33103310

3311-
uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
3311+
uint32_t zend_compile_args(
3312+
zend_ast *ast, zend_function *fbc, bool *may_have_extra_named_args) /* {{{ */
33123313
{
33133314
zend_ast_list *args = zend_ast_get_list(ast);
33143315
uint32_t i;
33153316
zend_bool uses_arg_unpack = 0;
3317+
uint32_t arg_count = 0; /* number of arguments not including unpacks */
3318+
3319+
/* Whether named arguments are used syntactically, to enforce language level limitations.
3320+
* May not actually use named argument passing. */
33163321
zend_bool uses_named_args = 0;
3322+
/* Whether there may be any undef arguments due to the use of named arguments. */
33173323
zend_bool may_have_undef = 0;
3318-
uint32_t arg_count = 0; /* number of arguments not including unpacks */
3324+
/* Whether there may be any extra named arguments collected into a variadic. */
3325+
*may_have_extra_named_args = 0;
33193326

33203327
for (i = 0; i < args->children; ++i) {
33213328
zend_ast *arg = args->child[i];
@@ -3342,6 +3349,7 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
33423349

33433350
/* Unpack may contain named arguments. */
33443351
may_have_undef = 1;
3352+
*may_have_extra_named_args = 1;
33453353
continue;
33463354
}
33473355

@@ -3367,7 +3375,9 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
33673375
}
33683376

33693377
if (arg_name) {
3378+
// TODO: These could be made more precise if fbc is known.
33703379
may_have_undef = 1;
3380+
*may_have_extra_named_args = 1;
33713381
}
33723382
} else {
33733383
if (uses_arg_unpack) {
@@ -3509,19 +3519,6 @@ static inline zend_bool zend_args_contain_unpack_or_named(zend_ast_list *args) /
35093519
}
35103520
/* }}} */
35113521

3512-
static inline zend_bool zend_args_contain_named(zend_ast_list *args) /* {{{ */
3513-
{
3514-
uint32_t i;
3515-
for (i = 0; i < args->children; ++i) {
3516-
zend_ast *arg = args->child[i];
3517-
if (arg->kind == ZEND_AST_NAMED_ARG) {
3518-
return 1;
3519-
}
3520-
}
3521-
return 0;
3522-
}
3523-
/* }}} */
3524-
35253522
ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc) /* {{{ */
35263523
{
35273524
if (fbc) {
@@ -3553,8 +3550,9 @@ void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *
35533550
zend_op *opline;
35543551
uint32_t opnum_init = get_next_op_number() - 1;
35553552
uint32_t arg_count;
3553+
bool may_have_extra_named_args;
35563554

3557-
arg_count = zend_compile_args(args_ast, fbc);
3555+
arg_count = zend_compile_args(args_ast, fbc, &may_have_extra_named_args);
35583556

35593557
zend_do_extended_fcall_begin();
35603558

@@ -3566,8 +3564,8 @@ void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *
35663564
}
35673565

35683566
opline = zend_emit_op(result, zend_get_call_op(opline, fbc), NULL, NULL);
3569-
if (zend_args_contain_named(zend_ast_get_list(args_ast))) {
3570-
opline->extended_value = ZEND_FCALL_HAS_NAMED_ARGS;
3567+
if (may_have_extra_named_args) {
3568+
opline->extended_value = ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS;
35713569
}
35723570
zend_do_extended_fcall_end();
35733571
}

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
954954

955955
#define ZEND_THROW_IS_EXPR 1u
956956

957-
#define ZEND_FCALL_HAS_NAMED_ARGS 1
957+
#define ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS 1
958958

959959
/* The send mode and is_variadic flag are stored as part of zend_type */
960960
#define _ZEND_SEND_MODE_SHIFT _ZEND_TYPE_EXTRA_FLAGS_SHIFT

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8567,14 +8567,11 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
85678567
#endif
85688568
}
85698569

8570-
// TODO: This could be more precise by checking MAY_BE_ARRAY_KEY_STRING for unpacks.
8571-
// TODO: Clean this up.
8572-
bool may_have_named_args = 0;
8570+
bool may_have_extra_named_params =
8571+
opline->extended_value == ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS;
85738572
if ((opline-1)->opcode == ZEND_SEND_UNPACK || (opline-1)->opcode == ZEND_SEND_ARRAY ||
8574-
(opline-1)->opcode == ZEND_CHECK_UNDEF_ARGS ||
8575-
opline->extended_value == ZEND_FCALL_HAS_NAMED_ARGS) {
8573+
(opline-1)->opcode == ZEND_CHECK_UNDEF_ARGS) {
85768574
unknown_num_args = 1;
8577-
may_have_named_args = 1;
85788575
}
85798576

85808577
if (info) {
@@ -9031,7 +9028,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
90319028
| mov FCARG1a, RX
90329029
| EXT_CALL zend_jit_vm_stack_free_args_helper, r0
90339030
}
9034-
if (may_have_named_args) {
9031+
if (may_have_extra_named_params) {
90359032
| test byte [RX + offsetof(zend_execute_data, This.u1.type_info) + 3], (ZEND_CALL_HAS_EXTRA_NAMED_PARAMS >> 24)
90369033
| jnz >1
90379034
|.cold_code

0 commit comments

Comments
 (0)