Skip to content

Commit 8276f9d

Browse files
ndosscheiluuu1994
andcommitted
Switch approach to blocking the optimization
Co-authored-by: Ilija Tovilo <[email protected]>
1 parent 2ae4846 commit 8276f9d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Zend/zend_compile.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,10 +4356,7 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
43564356
}
43574357
opline->result.num = zend_alloc_cache_slot();
43584358

4359-
/* Skip adding a message on piped assert(...) calls, hence the ZEND_AST_ZNODE check.
4360-
* We don't have access to the original AST anyway, so we would either need to duplicate
4361-
* this logic in pipe compilation or store the AST. Neither seems worth the complexity. */
4362-
if (args->children == 1 && args->child[0]->kind != ZEND_AST_ZNODE) {
4359+
if (args->children == 1) {
43634360
/* add "assert(condition) as assertion message */
43644361
zend_ast *arg = zend_ast_create_zval_from_str(
43654362
zend_ast_export("assert(", args->child[0], ")"));
@@ -6429,6 +6426,20 @@ static bool can_match_use_jumptable(zend_ast_list *arms) {
64296426
return 1;
64306427
}
64316428

6429+
static bool zend_is_deopt_pipe_name(zend_ast *ast)
6430+
{
6431+
if (ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(ast)) != IS_STRING) {
6432+
return false;
6433+
}
6434+
6435+
/* Assert compilation adds a message operand, but this is incompatible with the
6436+
* pipe optimization that uses a temporary znode for the reference elimination.
6437+
* Therefore, disable the optimization for assert.
6438+
* Note that "assert" as a name is always treated as fully qualified. */
6439+
zend_string *str = zend_ast_get_str(ast);
6440+
return zend_string_equals_literal_ci(str, "assert");
6441+
}
6442+
64326443
static void zend_compile_pipe(znode *result, zend_ast *ast)
64336444
{
64346445
zend_ast *operand_ast = ast->child[0];
@@ -6456,7 +6467,8 @@ static void zend_compile_pipe(znode *result, zend_ast *ast)
64566467

64576468
/* Turn $foo |> bar(...) into bar($foo). */
64586469
if (callable_ast->kind == ZEND_AST_CALL
6459-
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) {
6470+
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT
6471+
&& !zend_is_deopt_pipe_name(callable_ast->child[0])) {
64606472
fcall_ast = zend_ast_create(ZEND_AST_CALL,
64616473
callable_ast->child[0], arg_list_ast);
64626474
/* Turn $foo |> bar::baz(...) into bar::baz($foo). */

0 commit comments

Comments
 (0)