Skip to content

Commit a79c70f

Browse files
authored
[RFC] Convert exit (and die) from language constructs to functions (#13483)
RFC: https://wiki.php.net/rfc/exit-as-function
1 parent 0217784 commit a79c70f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1839
-1342
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
868868
break;
869869

870870
case ZEND_RETURN:
871-
case ZEND_EXIT:
872871
if (opline->op1_type == IS_TMP_VAR) {
873872
src = VAR_SOURCE(opline->op1);
874873
if (src && src->opcode == ZEND_QM_ASSIGN) {
@@ -1221,8 +1220,7 @@ static void zend_jmp_optimization(zend_basic_block *block, zend_op_array *op_arr
12211220
target = op_array->opcodes + target_block->start;
12221221
if ((target->opcode == ZEND_RETURN ||
12231222
target->opcode == ZEND_RETURN_BY_REF ||
1224-
target->opcode == ZEND_GENERATOR_RETURN ||
1225-
target->opcode == ZEND_EXIT) &&
1223+
target->opcode == ZEND_GENERATOR_RETURN) &&
12261224
!(op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
12271225
/* JMP L, L: RETURN to immediate RETURN */
12281226
*last_op = *target;

Zend/Optimizer/pass1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
331331
case ZEND_RETURN:
332332
case ZEND_RETURN_BY_REF:
333333
case ZEND_GENERATOR_RETURN:
334-
case ZEND_EXIT:
335334
case ZEND_THROW:
336335
case ZEND_MATCH_ERROR:
337336
case ZEND_CATCH:

Zend/Optimizer/pass3.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ void zend_optimizer_pass3(zend_op_array *op_array, zend_optimizer_ctx *ctx)
8888
MAKE_NOP(opline);
8989
} else if ((target->opcode == ZEND_RETURN ||
9090
target->opcode == ZEND_RETURN_BY_REF ||
91-
target->opcode == ZEND_GENERATOR_RETURN ||
92-
target->opcode == ZEND_EXIT) &&
91+
target->opcode == ZEND_GENERATOR_RETURN) &&
9392
!(op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
9493
/* JMP L, L: RETURN to immediate RETURN */
9594
*opline = *target;

Zend/Optimizer/zend_call_graph.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
162162
call_info->send_unpack = 1;
163163
}
164164
break;
165-
case ZEND_EXIT:
166-
/* In this case the DO_CALL opcode may have been dropped
167-
* and caller_call_opline will be NULL. */
168-
break;
169165
}
170166
opline++;
171167
}

Zend/Optimizer/zend_cfg.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
302302
}
303303
break;
304304
case ZEND_MATCH_ERROR:
305-
case ZEND_EXIT:
306305
case ZEND_THROW:
307306
/* Don't treat THROW as terminator if it's used in expression context,
308307
* as we may lose live ranges when eliminating unreachable code. */
@@ -506,7 +505,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
506505
case ZEND_RETURN:
507506
case ZEND_RETURN_BY_REF:
508507
case ZEND_GENERATOR_RETURN:
509-
case ZEND_EXIT:
510508
case ZEND_THROW:
511509
case ZEND_MATCH_ERROR:
512510
case ZEND_VERIFY_NEVER_TYPE:

Zend/tests/arginfo_zpp_mismatch.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ function skipFunction($function): bool {
66
|| $function === 'readline'
77
|| $function === 'readline_read_history'
88
|| $function === 'readline_write_history'
9+
/* terminates script */
10+
|| $function === 'exit'
11+
|| $function === 'die'
912
/* intentionally violate invariants */
1013
|| $function === 'zend_create_unterminated_string'
1114
|| $function === 'zend_test_array_return'

Zend/tests/die_string_cast_exception.phpt

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Printing AST of die "constant" via assert
3+
--INI--
4+
zend.assertions=1
5+
--FILE--
6+
<?php
7+
8+
try {
9+
assert(0 && die);
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
14+
?>
15+
--EXPECT--
16+
AssertionError: assert(0 && \exit())
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Printing AST of die function via assert
3+
--INI--
4+
zend.assertions=1
5+
--FILE--
6+
<?php
7+
8+
try {
9+
assert(0 && die());
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
14+
?>
15+
--EXPECT--
16+
AssertionError: assert(0 && \exit())
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Printing AST of exit "constant" via assert
3+
--INI--
4+
zend.assertions=1
5+
--FILE--
6+
<?php
7+
8+
try {
9+
assert(0 && exit);
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
14+
?>
15+
--EXPECT--
16+
AssertionError: assert(0 && \exit())

0 commit comments

Comments
 (0)