Skip to content

Commit 2336613

Browse files
committed
Fix optimizer support for first-class callables
1 parent 3fcece3 commit 2336613

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Zend/Optimizer/optimize_func_calls.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
188188
case ZEND_DO_ICALL:
189189
case ZEND_DO_UCALL:
190190
case ZEND_DO_FCALL_BY_NAME:
191+
case ZEND_CALLABLE_CONVERT:
191192
call--;
192193
if (call_stack[call].func && call_stack[call].opline) {
193194
zend_op *fcall = call_stack[call].opline;
@@ -216,7 +217,8 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
216217
}
217218

218219
if ((ZEND_OPTIMIZER_PASS_16 & ctx->optimization_level)
219-
&& call_stack[call].try_inline) {
220+
&& call_stack[call].try_inline
221+
&& opline->opcode != ZEND_CALLABLE_CONVERT) {
220222
zend_try_inline_call(op_array, fcall, opline, call_stack[call].func);
221223
}
222224
}

Zend/Optimizer/zend_inference.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "zend_inference.h"
2222
#include "zend_func_info.h"
2323
#include "zend_call_graph.h"
24+
#include "zend_closures.h"
2425
#include "zend_worklist.h"
2526
#include "zend_optimizer_internal.h"
2627

@@ -3504,6 +3505,10 @@ static zend_always_inline int _zend_update_type_info(
35043505
}
35053506
}
35063507
break;
3508+
case ZEND_CALLABLE_CONVERT:
3509+
UPDATE_SSA_TYPE(MAY_BE_OBJECT, ssa_op->result_def);
3510+
UPDATE_SSA_OBJ_TYPE(zend_ce_closure, /* is_instanceof */ false, ssa_op->result_def);
3511+
break;
35073512
case ZEND_FETCH_CONSTANT:
35083513
case ZEND_FETCH_CLASS_CONSTANT:
35093514
UPDATE_SSA_TYPE(MAY_BE_RC1|MAY_BE_RCN|MAY_BE_ANY|MAY_BE_ARRAY_KEY_ANY|MAY_BE_ARRAY_OF_ANY, ssa_op->result_def);

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3691,7 +3691,7 @@ bool zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *
36913691
opline->op1.num = zend_vm_calc_used_stack(0, fbc);
36923692
}
36933693

3694-
zend_emit_op(result, ZEND_CALLABLE_CONVERT, NULL, NULL);
3694+
zend_emit_op_tmp(result, ZEND_CALLABLE_CONVERT, NULL, NULL);
36953695
return true;
36963696
}
36973697

0 commit comments

Comments
 (0)