Commit graph

356 commits

Author SHA1 Message Date
Nikita Popov
03f8bccaf5 Fixed bug #80404
For a division like [1..1]/[2..2] produce [0..1] as a result, which
would be the integer envelope of the floating-point result.

The implementation is pretty ugly (we're now taking min/max across
eight values...) but I couldn't come up with a more elegant way
to handle this that doesn't make things a lot more complex (the
division sign handling is the annoying issue here).
2020-11-24 11:35:44 +01:00
Dmitry Stogov
3fb1b0862c Fixed MAY_BE_INDIRECT inference 2020-11-16 18:17:05 +03:00
Nikita Popov
5958137dc5 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix SSA integrity violation for type inference in dead code
2020-10-30 15:52:46 +01:00
Nikita Popov
83738281eb Fix SSA integrity violation for type inference in dead code
The foreach body can never be executed and thus may contain empty
types. We should still uphold our SSA integrity invariants in that
case.
2020-10-30 15:52:10 +01:00
Dmitry Stogov
b7df636589 Fixed MAY_BE_INDIRECT inference. 2020-10-26 21:48:13 +03:00
Dmitry Stogov
838d8d0ba0 Fixed reference-counter inference 2020-10-22 23:15:39 +03:00
Dmitry Stogov
ee5b1dd6dc Fixed range propagation 2020-10-20 02:27:24 +03:00
Dmitry Stogov
87beb22ff8 Perform trace range propagation 2020-10-13 00:18:17 +03:00
Nikita Popov
8446e28275 Handle missing result_var in binary_op_result_type
For dim/obj compound ops we don't have a result_var. Not sure why
this never caused issues before, but this can crash with JIT.
2020-09-11 22:36:41 +02:00
Dmitry Stogov
1c59bd5caa Avoid more exception checks 2020-09-09 23:25:54 +03:00
Dmitry Stogov
ee9948bc46 Eliminate unnecessary exception checks 2020-09-09 16:15:37 +03:00
Dmitry Stogov
bd8e0a96a5 Eliminate useless EG(exception) checks aftr FE_RESET/FE_FETCH 2020-09-01 18:56:47 +03:00
Nikita Popov
a99d08b5d1 Fix type inference for FE_RESET on invalid type
FE_RESET sets the result to UNDEF in this case. We should infer
some type here, because no type generally implies unreachable
code. In this case SCCP ended up replacing the FE_RESET result
with null, including in FE_FREE.
2020-09-01 13:59:36 +02:00
Dmitry Stogov
2369f48092 Infer information about packed/hash arrays and use it for JIT 2020-08-25 18:28:23 +03:00
Nikita Popov
d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00
Nikita Popov
9dacc85251 Add type inference support for RECV_VARIADIC 2020-07-30 17:14:34 +02:00
Nikita Popov
104b7addc4 Remove unused recv_arg_info from func_info 2020-07-30 17:04:56 +02:00
Nikita Popov
ce22cf5198 Remove some dead code in RECV type inference
We must always have arg_info corresponding to RECV.
2020-07-30 16:55:21 +02:00
Ilija Tovilo
9bf119832d
Implement nullsafe ?-> operator
RFC: https://wiki.php.net/rfc/nullsafe_operator

Closes GH-5619.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-07-24 10:05:03 +02:00
Dmitry Stogov
e0af92c16e Eliminate useless exception checks 2020-07-17 10:13:23 +03:00
Dmitry Stogov
48963378c1 Improved reference-counting inference 2020-07-13 13:08:32 +03:00
Ilija Tovilo
9fa1d13301
Implement match expression
RFC: https://wiki.php.net/rfc/match_expression_v2

Closes GH-5371.
2020-07-09 23:52:17 +02:00
Dmitry Stogov
ab5f8f4baf More accurate reference-counter inference (with support for ext/intl/tests/bug72241.phpt) 2020-07-07 19:11:27 +03:00
Nikita Popov
15c265b789 Revert "More accurate reference-counter inference"
This reverts commit b35255ad21.

Temporarily revert this, because it causes a memory leak on the
ext/intl/tests/bug72241.phpt test case, because temporary arrays
are not handled correctly.
2020-07-07 16:53:00 +02:00
Dmitry Stogov
ff3c40206c More accurate reference-counter inference 2020-07-06 17:55:23 +03:00
Dmitry Stogov
b35255ad21 More accurate reference-counter inference 2020-07-06 15:53:28 +03:00
Dmitry Stogov
2068f019e3 Eliminate useless exception checks 2020-07-02 12:42:09 +03:00
Dmitry Stogov
24a8065f8b Tracing JIT support for include() and generators 2020-06-29 21:40:49 +03:00
Dmitry Stogov
6fa126e966 MAY_BE_INDIRECT inference 2020-06-18 18:54:32 +03:00
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce
`ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)`
to mark unreachable code does no longer trigger C4715[1] warnings in
debug builds.  This may be useful for other compilers as well.

[1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
2020-06-16 18:39:09 +02:00
Dmitry Stogov
1d98bd41e5 Fixed incorrect type inference 2020-05-28 17:10:05 +03:00
Dmitry Stogov
2224f63bb5 Prevent usage of uninitialized class entry 2020-05-12 23:34:07 +03:00
Nikita Popov
5bc1e224db Make numeric operations on resources, arrays and objects type errors
RFC: https://wiki.php.net/rfc/arithmetic_operator_type_checks

Closes GH-5331.
2020-05-05 16:11:13 +02:00
Nikita Popov
a447897db0 Use information about classes returned by internal functions 2020-04-27 12:50:24 +02:00
Christoph M. Becker
a1eaaa692e Fix #79475: [JIT] func_get_args() assertion violation
`func_get_args()` may return `zend_empty_array`, which has refcount 2
to enforce separation.   We have to cater to that during type inference
so that the optimization in the JIT macro `SEPARATE_ARRAY` doesn't
prevent the separation.
2020-04-17 09:53:23 +02:00
Dmitry Stogov
5a05fef2af Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
2020-03-25 17:38:08 +03:00
Dmitry Stogov
91ee85c20c Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
2020-03-25 17:31:33 +03:00
Dmitry Stogov
65120cfc09 Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script). 2020-03-25 17:31:06 +03:00
Nikita Popov
dcbdcf87c8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Handle NULL caller_call_opline
2020-03-23 17:12:55 +01:00
Nikita Popov
dd9b5c8680 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Handle NULL caller_call_opline
2020-03-23 17:12:12 +01:00
Nikita Popov
34f1266a9c Handle NULL caller_call_opline
This can happen if there is an EXIT in the call arguments, in which
case the DO_CALL opcode may be eliminated as unreachable.
2020-03-23 17:12:01 +01:00
Dmitry Stogov
7283dbba27 ZEND_MAKE_REF can't throw 2020-03-20 01:37:27 +03:00
Dmitry Stogov
8e879b9f44 JIT for ZEND_CHECK_FUNC_ARG 2020-03-18 23:56:03 +03:00
Nikita Popov
1ba6e66c46 Improve type inference
After thinking about this a bit more, the code here was too
conservative. We know that everything but an object is going to
throw, so it's sufficient to restrict the type to MAY_BE_OBJECT.

The change in the test is weird but not incorrect, because it
operates on empty inferred types, in which case the code must be
dead (which it is). We should probably add a more explicit removal
of code working on empty types.
2020-03-17 15:41:47 +01:00
Nikita Popov
41a86a72c4 Clean up a few more places 2020-03-17 15:23:52 +01:00
Nikita Popov
023039fbfc Remove object auto-vivification leftovers in type-inference
undef/null/false no longer get promoted to object in PHP 8.

In fact, we may drop the SSA var defs outside RC inference mode now.
2020-03-17 14:54:11 +01:00
Nikita Popov
3723985058 Merge EX variants of INFO macros 2020-03-16 13:02:16 +01:00
Nikita Popov
d35ce5d661 Merge EX variants of RANGE macros
Only need to create the ssa_op variable in range inference...
2020-03-16 12:36:03 +01:00
Nikita Popov
44b3971b85 Merge zend_may_throw(_ex)
Explicitly pass ssa_op in the places that don't do so yet.
2020-03-16 12:24:40 +01:00
Dmitry Stogov
9a8f735c57 Emit warning about type narrowing for tracing JIT as well 2020-03-14 01:29:46 +03:00