1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

VAR|TMP overhaul (GH-20628)

The aim of this PR is twofold:

- Reduce the number of highly similar TMP|VAR handlers
- Avoid ZVAL_DEREF in most of these cases

This is achieved by guaranteeing that all zend_compile_expr() calls, as well as
all other compile calls with BP_VAR_{R,IS}, will result in a TMP variable. This
implies that the result will not contain an IS_INDIRECT or IS_REFERENCE value,
which was mostly already the case, with two exceptions:

- Calls to return-by-reference functions. Because return-by-reference functions
  are quite rare, this is solved by delegating the DEREF to the RETURN_BY_REF
  handler, which will examine the stack to check whether the caller expects a
  VAR or TMP to understand whether the DEREF is needed. Internal functions will
  also need to adjust by calling the zend_return_unwrap_ref() function.

- By-reference assignments, including both $a = &$b, as well as $a = [&$b]. When
  the result of these expressions is used in a BP_VAR_R context, the reference
  is unwrapped via a ZEND_QM_ASSIGN opcode beforehand. This is exceptionally
  rare.

Closes GH-20628
This commit is contained in:
Ilija Tovilo
2026-01-31 19:44:56 +01:00
committed by GitHub
parent 927b9eecb6
commit 6173a9a109
48 changed files with 13984 additions and 20472 deletions

View File

@@ -19,8 +19,8 @@ L0014 0000 CV0($baz) = RECV 1
L0015 0001 INIT_FCALL %d %d string("var_dump")
L0015 0002 INIT_FCALL %d %d string("strrev")
L0015 0003 SEND_VAR CV0($baz) 1
L0015 0004 V1 = DO_ICALL
L0015 0005 SEND_VAR V1 1
L0015 0004 T1 = DO_ICALL
L0015 0005 SEND_VAL T1 1
L0015 0006 DO_ICALL
L0016 0007 RETURN null
prompt> [User Class: Foo\Bar (2 methods)]
@@ -44,9 +44,9 @@ prompt> [Context %s (9 ops)]
$_main:
; (lines=9, args=0, vars=0, tmps=%d)
; %s:1-21
L0018 0000 V0 = NEW 0 string("Foo\\Bar")
L0018 0000 T0 = NEW 0 string("Foo\\Bar")
L0018 0001 DO_FCALL
L0018 0002 INIT_METHOD_CALL 1 V0 string("Foo")
L0018 0002 INIT_METHOD_CALL 1 T0 string("Foo")
L0018 0003 SEND_VAL_EX string("test \"quotes\"") 1
L0018 0004 DO_FCALL
L0019 0005 INIT_FCALL %d %d string("foo")

View File

@@ -25,8 +25,8 @@ L0014 0000 CV0($baz) = RECV 1
L0015 0001 INIT_FCALL %d %d string("var_dump")
L0015 0002 INIT_FCALL %d %d string("strrev")
L0015 0003 SEND_VAR CV0($baz) 1
L0015 0004 V1 = DO_ICALL
L0015 0005 SEND_VAR V1 1
L0015 0004 T1 = DO_ICALL
L0015 0005 SEND_VAL T1 1
L0015 0006 DO_ICALL
L0016 0007 RETURN null
prompt> L0015 0001 INIT_FCALL %d %d string("var_dump")