Commit graph

61 commits

Author SHA1 Message Date
Niels Dossche
6b795f64a5
Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
The trait handling for property hooks in preloading did not exist, we
add a check to skip trait clones and we add the necessary code to update
the op arrays.

Closes GH-18586.
2025-05-19 19:21:53 +02:00
Ilija Tovilo
901ce61105
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix ZEND_MATCH_ERROR misoptimization
2024-12-12 13:11:29 +01:00
Ilija Tovilo
cdfd960150
Fix ZEND_MATCH_ERROR misoptimization
op1 of ZEND_MATCH_ERROR, which refers to the match expression, is not freed by
MATCH_ERROR itself. Instead, it is freed by ZEND_HANDLE_EXCEPTION. For normal
control flow, a FREE is placed at the end of the match expression.

Since FREE may appear after MATCH_ERROR in the opcode sequence, we need to
correctly handle op1 of MATCH_ERROR as alive.

Fixes GH-17106
Closes GH-17108
2024-12-12 13:10:34 +01:00
Ilija Tovilo
2e9cc9bc30
Allow optimizer to depend on preloaded symbols (#15021)
* Allow optimizer to depend on preloaded symbols

It is safe for the optimizer to rely on preloaded symbols. This can occur when
compiling non-preloaded files, referencing preloaded ones.

* Disable inline pass for observer test

* Move duplicated code into functions

* Add comment to specific optimization value

* Optimizer should only rely on preloaded symbols in the symbol table

* Fix skipif for windows
2024-08-02 17:35:27 +02:00
Bob Weinand
e406ec81f4 Merge branch 'PHP-8.3' 2024-07-22 18:32:04 +02:00
Bob Weinand
61b455b59c Merge branch 'PHP-8.2' into PHP-8.3 2024-07-22 18:30:10 +02:00
Bob Weinand
a18df90a8b Fix GH-13817: Segmentation fault for enabled observers after pass 4
Instead of fixing up temporaries count in between observer steps, just apply the additional temporary in the two affected observer steps.

Closes GH-14018.
2024-07-22 18:28:03 +02:00
Ilija Tovilo
780a8280d2
[RFC] Property hooks (#13455)
RFC: https://wiki.php.net/rfc/property-hooks

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2024-07-14 11:55:03 +02:00
Máté Kocsis
56cf09f23a
Improve optimizer support for class constants (#13438)
The following optimizations are added:

- Constant folding of final class constants
- Type inference of typed class constants
2024-03-18 07:30:44 +01:00
Ilija Tovilo
631bc81607
Implement stackless internal function calls
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12461
2024-02-06 17:42:28 +01:00
Ilija Tovilo
95f7335251
Improve static inference in final class (#13298)
static may be treated like self if the class is final.
2024-02-01 11:49:08 +01:00
Ilija Tovilo
ffc250d245
Add runtime type inference verification
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12930
2024-01-19 09:29:14 +01:00
Dmitry Stogov
555e8f82e8 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed type inference
2023-12-18 12:28:25 +03:00
Dmitry Stogov
731734dacb Fixed type inference
Fixes oss-fuzz #65150
2023-12-18 12:27:35 +03:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Max Kellermann
d5c649b36b
zend_compiler, ...: use uint8_t instead of zend_uchar (#10621)
`zend_uchar` suggests that the value is an ASCII character, but here,
it's about very small integers.  This is misleading, so let's use a
C99 integer instead.

On all architectures currently supported by PHP, `zend_uchar` and
`uint8_t` are identical.  This change is only about code readability.
2023-02-23 14:56:54 +00:00
Niels Dossche
821fc55a68
Implement GH-9826: Make class_alias() work with internal classes (#10483)
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
2023-02-22 11:47:32 +01:00
Niels Dossche
2e78c080c6
Improve the optimizer's check if a function is a prototype or not (#10467)
Currently, a function is considered a prototype if the function is not
marked as final. However, a class marked as final also make it
impossible for a function to be overridden. Therefore, we know in this
case too that the function is not a prototype.
This allows the type inference algorithm to determine some types more
precisely, and can allow for more optimizations of the instructions.
Additionally, place some computation of the flags in their respective
blocks as a micro-optimization.

Note: anonymous classes *can* be extended (see test
Zend/tests/anon/011.phpt). Therefore we don't optimize this case.
2023-02-21 00:34:47 +03:00
Max Kellermann
49c1e6eb33
Make various pointers const in Zend/ (#10608)
* Zend/zend_operators: pass const pointers to zend_is_identical()

* Zend/zend_operators: pass const pointers to zend_get_{long,double}()

* Zend/Optimizer/sccp: make pointers const

* Zend/Optimizer/scdf: make pointers const

* Zend/Optimizer/zend_worklist: make pointers const

* Zend/Optimizer/zend_optimizer: make pointers const

* Zend/zend_compile: make pointers const
2023-02-20 14:00:59 +00:00
Christoph M. Becker
2f4973fd88
Revert GH-10279
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit 45a128c9de.
This reverts commit 1eb71c3f15.
This reverts commit 492523a779.
This reverts commit c7a4633891.
This reverts commit 308adb915c.
This reverts commit cd27d5e07f.
This reverts commit c5933409b4.
This reverts commit 46371f4eb3.
This reverts commit 623e2e9fc6.
This reverts commit e7434c1247.
This reverts commit d28d323ca2.
This reverts commit 1a067b84ee.
This reverts commit a55c0c5fc3.
This reverts commit b5aeb3a4d4.
This reverts commit f061a035e4.
This reverts commit b088575119.
This reverts commit b1d48774a7.
This reverts commit 94f9a20ce6.
This reverts commit 4831e48708.
This reverts commit cd985de190.
This reverts commit 9521d21681.
This reverts commit d6136151e9.
2023-01-16 12:25:59 +01:00
Max Kellermann
1a067b84ee Zend/Optimizer/zend_optimizer: include cleanup 2023-01-12 15:12:45 +00:00
Bob Weinand
dc5475c191 Save previous observer on the VM stack
This avoids a possible significant performance penalty, when some leaf function was observed, deep in the stack.
As a side effect, we are not iterating over prev_execute_data anymore and thus, non-observed fake frames, possibly on stack, cannot have any impact on the observer anymore (especially within zend_observer_fcall_end_all).

Saving the previous observer happens now directly on the VM stack. If there is any observer, function frames are allocated an extra zval (the last temporary), which will, on observed frames, contain the previous observed frame address.
2022-08-04 17:16:27 +02:00
Arnaud Le Blanc
298c1ab92e Merge branch 'PHP-8.1' 2022-05-13 12:48:51 +02:00
Dmitry Stogov
27efd125ed Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix ISSET_ISEMPTY_VAR missoptimization
2022-04-25 13:31:40 +03:00
Dmitry Stogov
948ef10dd0 Fix ISSET_ISEMPTY_VAR missoptimization
This fixes oss-fuzz #46909
2022-04-25 13:31:01 +03:00
Dmitry Stogov
73514d6e4f Merge branch 'PHP-8.1'
* PHP-8.1:
  Reorder optimization passes to avoid miss-optimization
2022-04-25 13:12:03 +03:00
Dmitry Stogov
1aa5e9392d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Reorder optimization passes to avoid miss-optimization
2022-04-25 13:09:31 +03:00
Nikita Popov
4543cd32ae Remove JMPZNZ opcode
While JMPZNZ can avoid execution of a separate JMP opcode in some
cases, it also prevents smart branch optimization, so creating
JMPZNZ may actually have a negative effect. It also adds additional
complexity for optimizations.

Drop JMPZNZ in favor of JMPZ+JMP or JMPNZ+JMP.

Closes GH-7857.
2022-01-10 22:07:10 +01:00
Nikita Popov
0698bf794f Add helper for convertion to CHECK_VAR/FREE/NOP
This is a recurring pattern whenever an instruction with an
operand is deleted.
2021-12-30 12:44:57 +01:00
Dmitry Stogov
a066b809de Skip abstract methods 2021-12-27 15:28:46 +03:00
Nikita Popov
e45653c089 Make sure SCCP can evaluate all functions pass1 can
Move evaluation of ini_get() into eval_special_func_call() and
use this helper both in pass1 and sccp.
2021-12-26 15:40:35 +01:00
Nikita Popov
1050edaef8 Extract special function evaluation from pass1
Pass1 handles a number of special functions that can be evaluated
under some circumstances. Move the core logic into a separate
helper, as I believe that SCCP should reuse this.
2021-12-26 15:40:35 +01:00
Nikita Popov
206d80e11a Reuse get_class_entry_from_op1() helper
Export and reuse this helper in places that fetch a class entry
from op1.
2021-12-25 22:18:50 +01:00
Nikita Popov
2cf93032ee Sink op_array scope case into get_class_entry()
This handles references to the current class through its name
rather than self (and for cases where is is not linked yet and
thus not covered by the context lookup). Rather than handling this
only for FETCH_CLASS_CONSTANT optimization, integrate this into
the generic get_class_entry() utility.
2021-12-25 21:51:29 +01:00
Nikita Popov
52676f2b7e Remove unnecessary wrapper function
This seems to date back to a time where zval_ptr_dtor was a macro
implicitly passing additional parameters.
2021-12-25 17:39:05 +01:00
Nikita Popov
0884048401 Don't exclude arrays from constant collection
These are supported as constants nowadays, so we can drop the
string check.

Also fix a potential leak, though I believe this doesn't matter in
current usage, as it will effectively be suppressed during persist.
2021-12-25 17:32:18 +01:00
Nikita Popov
92e7cf5962 Move FETCH_CLASS+INSTANCEOF special case out of update_op1_const()
The generic code was rejecting this to go into a special code path
in SCCP. We should directly do that in SCCP instead, to still allow
the generic (and valid) replacement.
2021-12-25 16:32:02 +01:00
Nikita Popov
4ad9dbbac9 Don't replace SEND opcodes with different by-ref behavior
update_op1_const() implements the right logic here -- these cannot
be replaced by different opcodes, as the by-ref passing behavior
is not the same.
2021-12-25 12:34:02 +01:00
Nikita Popov
46d1e503dd Remove redundant code in zend_optimizer_replace_by_const()
zend_optimizer_update_op1_const() already handles these cases.
2021-12-25 12:18:12 +01:00
Dmitry Stogov
e1c561508d Merge branch 'PHP-8.1'
* PHP-8.1:
  Optimize closures nested in other closures
2021-11-15 13:33:23 +03:00
Dmitry Stogov
f313b65acb Optimize closures nested in other closures 2021-11-15 13:32:42 +03:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
e7a5ec5fd9 Merge branch 'PHP-8.1'
* PHP-8.1:
  Handle operand replacement in JMP_NULL
2021-10-19 15:19:39 +02:00
Nikita Popov
1f19401ffa Handle operand replacement in JMP_NULL
In this case it's not sufficient to replace the JMP_NULL operand,
as it keeps the temporary alive and there may be more uses later.
Fix this by generalizing existing handling for other similar opcodes
like CASE/SWITCH and LIST_R.

Fixes oss-fuzz 5820123475214336.
2021-10-19 15:19:02 +02:00
Nikita Popov
6858ad123e Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix cache slot assignment for ASSIGN_OBJ_OP
2021-09-30 14:35:07 +02:00
Nikita Popov
5cdbfa897c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix cache slot assignment for ASSIGN_OBJ_OP
2021-09-30 14:34:50 +02:00
George Peter Banyard
f345f6d529 Voidify zend_optimize_script()
It always returned 1

As a consequence voidify preload_optimize()
2021-09-21 11:35:53 +01:00
George Peter Banyard
278efe3b64 Voidify zend_build_call_graph()
It always returned SUCCESS
2021-09-21 11:35:53 +01:00
George Peter Banyard
53d5420d49 Use more appropriate types in Optimizer
Mainly using zend_result and bool instead of int
2021-09-21 11:35:53 +01:00
Nikita Popov
fb4405d357 Avoid accessing literal operand on nop
This would have create a NOP with a CONST operand ... probably
harmless in practice, but we should avoid it.
2021-09-15 14:44:54 +02:00