Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ZEND_ASSIGN_ADD (and others) by ZEND_ASSIGN_OP, ZEND_ASSIGN_DIM_OP, ZEND_ASSGIN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP #4364

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -22,6 +22,7 @@ PHP 7.4 INTERNALS UPGRADE NOTES
s. Typed references support
t. Exceptions thrown by string conversions.
u. Removed uint and ulong typedefs
v. Compound assignment opcodes

2. Build system changes
a. Abstract
@@ -212,6 +213,13 @@ PHP 7.4 INTERNALS UPGRADE NOTES
u. The Windows typedefs uint and ulong are no longer available, and have to be
replaced with standard types.

v. Compound assignment opcodes were changed. Instead of ZEND_ASSIGN_ADD (and
others) with 0, ZEND_ASSIGN_DIM, ZEND_ASSIGN_OBJ or
ZEND_ASSIGN_STATIC_PROP in extended value, now we use ZEND_ASSIGN_OP,
ZEND_ASSIGN_DIM_OP, ZEND_ASSIGN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP with
ZEND_ADD (or other) in extended_value.


========================
2. Build system changes
========================
@@ -1713,18 +1713,18 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
case ZEND_AST_ASSIGN_REF: BINARY_OP(" =& ", 90, 91, 90);
case ZEND_AST_ASSIGN_OP:
switch (ast->attr) {
case ZEND_ASSIGN_ADD: BINARY_OP(" += ", 90, 91, 90);
case ZEND_ASSIGN_SUB: BINARY_OP(" -= ", 90, 91, 90);
case ZEND_ASSIGN_MUL: BINARY_OP(" *= ", 90, 91, 90);
case ZEND_ASSIGN_DIV: BINARY_OP(" /= ", 90, 91, 90);
case ZEND_ASSIGN_MOD: BINARY_OP(" %= ", 90, 91, 90);
case ZEND_ASSIGN_SL: BINARY_OP(" <<= ", 90, 91, 90);
case ZEND_ASSIGN_SR: BINARY_OP(" >>= ", 90, 91, 90);
case ZEND_ASSIGN_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
case ZEND_ASSIGN_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
case ZEND_ASSIGN_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
case ZEND_ASSIGN_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
case ZEND_ASSIGN_POW: BINARY_OP(" **= ", 90, 91, 90);
case ZEND_ADD: BINARY_OP(" += ", 90, 91, 90);
case ZEND_SUB: BINARY_OP(" -= ", 90, 91, 90);
case ZEND_MUL: BINARY_OP(" *= ", 90, 91, 90);
case ZEND_DIV: BINARY_OP(" /= ", 90, 91, 90);
case ZEND_MOD: BINARY_OP(" %= ", 90, 91, 90);
case ZEND_SL: BINARY_OP(" <<= ", 90, 91, 90);
case ZEND_SR: BINARY_OP(" >>= ", 90, 91, 90);
case ZEND_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
case ZEND_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
case ZEND_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
case ZEND_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
case ZEND_POW: BINARY_OP(" **= ", 90, 91, 90);
EMPTY_SWITCH_DEFAULT_CASE();
}
break;
@@ -2849,7 +2849,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
zend_delayed_compile_var(&var_node, var_ast, BP_VAR_RW, 0);
zend_compile_expr(&expr_node, expr_ast);
zend_delayed_compile_end(offset);
zend_emit_op(result, opcode, &var_node, &expr_node);
opline = zend_emit_op(result, ZEND_ASSIGN_OP, &var_node, &expr_node);
opline->extended_value = opcode;
return;
case ZEND_AST_STATIC_PROP:
offset = zend_delayed_compile_begin();
@@ -2858,8 +2859,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */

opline = zend_delayed_compile_end(offset);
cache_slot = opline->extended_value;
opline->opcode = opcode;
opline->extended_value = ZEND_ASSIGN_STATIC_PROP;
opline->opcode = ZEND_ASSIGN_STATIC_PROP_OP;
opline->extended_value = opcode;

opline = zend_emit_op_data(&expr_node);
opline->extended_value = cache_slot;
@@ -2870,8 +2871,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
zend_compile_expr(&expr_node, expr_ast);

opline = zend_delayed_compile_end(offset);
opline->opcode = opcode;
opline->extended_value = ZEND_ASSIGN_DIM;
opline->opcode = ZEND_ASSIGN_DIM_OP;
opline->extended_value = opcode;

zend_emit_op_data(&expr_node);
return;
@@ -2882,8 +2883,8 @@ void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */

opline = zend_delayed_compile_end(offset);
cache_slot = opline->extended_value;
opline->opcode = opcode;
opline->extended_value = ZEND_ASSIGN_OBJ;
opline->opcode = ZEND_ASSIGN_OBJ_OP;
opline->extended_value = opcode;

opline = zend_emit_op_data(&expr_node);
opline->extended_value = cache_slot;
@@ -1002,6 +1002,9 @@ static zend_always_inline int zend_check_arg_send_type(const zend_function *zf,
/* All increment opcodes are even (decrement are odd) */
#define ZEND_IS_INCREMENT(opcode) (((opcode) & 1) == 0)

#define ZEND_IS_BINARY_ASSIGN_OP_OPCODE(opcode) \
(((opcode) >= ZEND_ADD) && ((opcode) <= ZEND_POW))

/* Pseudo-opcodes that are used only temporarily during compilation */
#define ZEND_PARENTHESIZED_CONCAT 252 /* removed with PHP 8 */
#define ZEND_GOTO 253
@@ -1318,9 +1318,9 @@ static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPL
pow_function
};
/* size_t cast makes GCC to better optimize 64-bit PIC code */
size_t opcode = (size_t)opline->opcode;
size_t opcode = (size_t)opline->extended_value;

return zend_binary_ops[opcode - ZEND_ASSIGN_ADD](ret, op1, op2);
return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2);
}

static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *property, zval *value OPLINE_DC EXECUTE_DATA_DC)
@@ -1434,18 +1434,10 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
}

switch (opline->opcode) {
case ZEND_ASSIGN_ADD:
case ZEND_ASSIGN_SUB:
case ZEND_ASSIGN_MUL:
case ZEND_ASSIGN_DIV:
case ZEND_ASSIGN_MOD:
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
case ZEND_ASSIGN_CONCAT:
case ZEND_ASSIGN_BW_OR:
case ZEND_ASSIGN_BW_AND:
case ZEND_ASSIGN_BW_XOR:
case ZEND_ASSIGN_POW:
case ZEND_ASSIGN_OP:
case ZEND_ASSIGN_DIM_OP:
case ZEND_ASSIGN_OBJ_OP:
case ZEND_ASSIGN_STATIC_PROP_OP:
msg = "Cannot use assign-op operators with string offsets";
break;
case ZEND_FETCH_DIM_W:
@@ -1461,25 +1453,15 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
while (opline < end) {
if (opline->op1_type == IS_VAR && opline->op1.var == var) {
switch (opline->opcode) {
case ZEND_ASSIGN_ADD:
case ZEND_ASSIGN_SUB:
case ZEND_ASSIGN_MUL:
case ZEND_ASSIGN_DIV:
case ZEND_ASSIGN_MOD:
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
case ZEND_ASSIGN_CONCAT:
case ZEND_ASSIGN_BW_OR:
case ZEND_ASSIGN_BW_AND:
case ZEND_ASSIGN_BW_XOR:
case ZEND_ASSIGN_POW:
if (opline->extended_value == ZEND_ASSIGN_OBJ) {
msg = "Cannot use string offset as an object";
} else if (opline->extended_value == ZEND_ASSIGN_DIM) {
msg = "Cannot use string offset as an array";
} else {
msg = "Cannot use assign-op operators with string offsets";
}
case ZEND_ASSIGN_OBJ_OP:
msg = "Cannot use string offset as an object";
break;
case ZEND_ASSIGN_DIM_OP:
msg = "Cannot use string offset as an array";
break;
case ZEND_ASSIGN_STATIC_PROP_OP:
case ZEND_ASSIGN_OP:
msg = "Cannot use assign-op operators with string offsets";
break;
case ZEND_PRE_INC_OBJ:
case ZEND_PRE_DEC_OBJ:
@@ -886,29 +886,29 @@ expr:
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2); }
| variable T_PLUS_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_ADD, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_ADD, $1, $3); }
| variable T_MINUS_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SUB, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_SUB, $1, $3); }
| variable T_MUL_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_MUL, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_MUL, $1, $3); }
| variable T_POW_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_POW, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_POW, $1, $3); }
| variable T_DIV_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_DIV, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_DIV, $1, $3); }
| variable T_CONCAT_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_CONCAT, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_CONCAT, $1, $3); }
| variable T_MOD_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_MOD, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_MOD, $1, $3); }
| variable T_AND_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_AND, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_BW_AND, $1, $3); }
| variable T_OR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_OR, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_BW_OR, $1, $3); }
| variable T_XOR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_BW_XOR, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_BW_XOR, $1, $3); }
| variable T_SL_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SL, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_SL, $1, $3); }
| variable T_SR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SR, $1, $3); }
{ $$ = zend_ast_create_assign_op(ZEND_SR, $1, $3); }
| variable T_COALESCE_EQUAL expr
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_COALESCE, $1, $3); }
| variable T_INC { $$ = zend_ast_create(ZEND_AST_POST_INC, $1); }
@@ -1028,33 +1028,24 @@ ZEND_API binary_op_type get_binary_op(int opcode)
{
switch (opcode) {
case ZEND_ADD:
case ZEND_ASSIGN_ADD:
return (binary_op_type) add_function;
case ZEND_SUB:
case ZEND_ASSIGN_SUB:
return (binary_op_type) sub_function;
case ZEND_MUL:
case ZEND_ASSIGN_MUL:
return (binary_op_type) mul_function;
case ZEND_POW:
case ZEND_ASSIGN_POW:
return (binary_op_type) pow_function;
case ZEND_DIV:
case ZEND_ASSIGN_DIV:
return (binary_op_type) div_function;
case ZEND_MOD:
case ZEND_ASSIGN_MOD:
return (binary_op_type) mod_function;
case ZEND_SL:
case ZEND_ASSIGN_SL:
return (binary_op_type) shift_left_function;
case ZEND_SR:
case ZEND_ASSIGN_SR:
return (binary_op_type) shift_right_function;
case ZEND_PARENTHESIZED_CONCAT:
case ZEND_FAST_CONCAT:
case ZEND_CONCAT:
case ZEND_ASSIGN_CONCAT:
return (binary_op_type) concat_function;
case ZEND_IS_IDENTICAL:
return (binary_op_type) is_identical_function;
@@ -1072,17 +1063,15 @@ ZEND_API binary_op_type get_binary_op(int opcode)
case ZEND_SPACESHIP:
return (binary_op_type) compare_function;
case ZEND_BW_OR:
case ZEND_ASSIGN_BW_OR:
return (binary_op_type) bitwise_or_function;
case ZEND_BW_AND:
case ZEND_ASSIGN_BW_AND:
return (binary_op_type) bitwise_and_function;
case ZEND_BW_XOR:
case ZEND_ASSIGN_BW_XOR:
return (binary_op_type) bitwise_xor_function;
case ZEND_BOOL_XOR:
return (binary_op_type) boolean_xor_function;
default:
ZEND_ASSERT(0);
return (binary_op_type) NULL;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.