Commit graph

356 commits

Author SHA1 Message Date
Dmitry Stogov
29bf7902b3 Fixed RC inference for ZEND_ASSIGN_STATIC_PROP and removed useless checks during RC inference 2020-03-14 01:17:45 +03:00
Dmitry Stogov
4bf2d09ede Tracing JIT (it doesn't support register allocation yet)
Use opcache.jit=1255 to swith it on (the third digit 5 really matters)
Use opcache.jit_debug=0xff001 to see how it works and what code it generates
2020-03-13 22:11:07 +03:00
Nikita Popov
9e89f91341 Add assertions for DIM_W/RW uses
The result should be used only once and on the directly next opline,
otherwise it may not be safe. Add some assertions to that effect.
2020-03-13 13:11:42 +01:00
Nikita Popov
9ab2cb923e Also remove dead arguments 2020-03-13 12:45:02 +01:00
Nikita Popov
b979e03159 Remove dead type narrowing code
Rename handle_type_narrowing() to clarify what it does, and
remove dead code for resetting dependent vars.
2020-03-13 12:27:49 +01:00
Dmitry Stogov
63761d1133 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed incorrect overflow detection
2020-02-27 23:38:19 +03:00
Dmitry Stogov
cb88184420 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed incorrect overflow detection
2020-02-27 23:38:09 +03:00
Dmitry Stogov
5b51b633e2 Fixed incorrect overflow detection 2020-02-27 23:37:41 +03:00
Nikita Popov
43443857b7 Add static return type
RFC: https://wiki.php.net/rfc/static_return_type

The "static" type is represented as MAY_BE_STATIC, rather than
a class type like "self" and "parent", as it has special
resolution semantics, and cannot be cached in the runtime cache.

Closes GH-5062.
2020-02-17 11:51:09 +01:00
Nikita Popov
4f5f72c7af Remove ZEND_ACC_INHERITED flag
It is equivalent to checking ce->parent != NULL. Just adds more
state that needs to be kept in sync.
2020-02-06 10:42:25 +01:00
Nikita Popov
b33697d47e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79193
2020-01-30 14:56:31 +01:00
Nikita Popov
f70b552326 Fixed bug #79193 2020-01-30 14:55:58 +01:00
Tyson Andre
3c72105edb Remove leftover ZEND_CAST code for (unset) cast.
Followup for d74d3922ce

Attempting to require a file with (unset) casts results in an E_COMPILE_ERROR
that can't be caught or handled by set_exception_handler/set_error_handler.

Also remove the (bool) cast, because the ZEND_BOOL opcode handles that.

Remove inference that array -> object cast can throw.
It was added in 2a286ad599 - I don't know how creating an stdClass would throw.
(numeric keys, references, etc. don't cause it to throw)

Closes GH-5042
2020-01-18 11:06:19 -05:00
Nikita Popov
43719022ea Improve SSA representation of FE_FETCH
The op2 of FE_FETCH is only written if the loop edge is taken.
Fix up the SSA form to use the pre-assignment value if the exit
edge is taken.

This allows us to properly infer the type of the loop variable,
without letting the pre-loop type leak in.

Closes GH-5040.
2020-01-17 09:41:27 +01:00
Nikita Popov
9e403d65d8 Add DCE support for ARRAY_KEY_EXISTS 2019-12-05 14:55:22 +01:00
Tyson Andre
f7c44ef2a0 Make opcache infer array_key_exists is non-null bool
array_key_exists now throws a TypeError instead of returning null
for invalid arguments after 14bdb0cfc7
2019-11-20 00:11:51 +03:00
Nikita Popov
999e32b65a Implement union types
According to RFC: https://wiki.php.net/rfc/union_types_v2

The type representation now makes use of both the pointer payload
and the type mask at the same time. Additionall, zend_type_list is
introduced as a new kind of pointer payload, which is used to store
multiple class types. Each of the class types is a tagged pointer,
which may be either a class name or class entry. The latter is only
used for typed properties, while arguments/returns will instead use
cache slots. A type list can contain a mix of both names and CEs at
the same time, as not all classes may be resolvable.

One thing this is missing is support for union types in arginfo
and stubs, which I want to handle separately.

I've also dropped the special object code from the JIT implementation
for now -- I plan to add this back in a different form at a later time.
For now I did not want to include non-trivial JIT changes together
with large functional changes.

Another possible piece of follow-up work is to implement "iterable"
as an internal alias for "array|Traversable". I believe this will
eliminate quite a few special-cases that had to be implemented.

Closes GH-4838.
2019-11-08 15:15:48 +01:00
Nikita Popov
ac4e0f0852 Make zend_type a 2-field struct
We now store the pointer payload and the type mask separately. This
is in preparation for union types, where we will be using both at
the same time.

To avoid increasing the size of arginfo structures, the
pass_by_reference and is_variadic fields are now stored as part of
the type_mask (8-bit are reserved for custom use).

Different types of pointer payloads are distinguished based on bits
in the type_mask.
2019-11-08 15:15:48 +01:00
Dmitry Stogov
cef1960ce7 Use "const" qualifier 2019-10-14 21:49:08 +03:00
Dmitry Stogov
2068ce9adf Use RT_CONSTANT() or CT_CONSTANT() macro depending on ZEND_ACC_DONE_PASS_TWO flag 2019-10-11 12:54:07 +03:00
Nikita Popov
01fc1a3057 Remove most uses of the ERROR type
It is now only used to signal exceptions for property reads. ERROR
zvals are never returned back to the VM anymore, so there's no
need to check for them when receiving a VAR.

Also return MAY_BE_ERROR, as ERROR is now no longer relevant for
inference.
2019-09-30 11:35:07 +02:00
Nikita Popov
34e7c2daf0 Merge branch 'PHP-7.4' 2019-09-27 10:49:25 +02:00
Nikita Popov
a6c9c7c2b8 Handle resources used as array keys consistently
Resources used as array keys are generally handled by throwing a
notice and converting the resource to the resource handle. The only
exception is the [$resource => null] syntax, where this was treated
as an illegal offset type instead. However, this also only happened
for VM evaluations, the AST evaluator did handle resources correctly.
2019-09-27 10:40:41 +02:00
Nikita Popov
a66c60cce3 Throw Error when writing property of non-object
This removes object auto-vivification support.

This also means that we can remove the corresponding special
handling for typed properites: We no longer need to check that a
property is convertible to stdClass if such a conversion might
take place indirectly due to a nested property write.

Additionally OBJ_W style operations now no longer modify the
object operand, and as such we no longer need to treat op1 as a
def in SSA form.

The next step would be to actually compile the whole LHS of OBJ_W
operations in R rather than W mode, but that causes issues with
SimpleXML, whose object handlers depend on the current compilation
structure.

Part of https://wiki.php.net/rfc/engine_warnings.
2019-09-27 10:11:47 +02:00
Nikita Popov
9e8ba7891e Change representation of zend_type from type code to MAY_BE_* mask
This switches zend_type from storing a single IS_* type code to
storing a MAY_BE_* type mask. Right now most code still assumes
that there is only a single type in the mask (or two together
with MAY_BE_NULL). But this will make it a lot simpler to introduce
union types.

An additional advantage (and why I'm doing this separately), is
that a number of special cases no longer need to be handled
separately: We can do a single mask & (1 << type) check to handle
all simple types, booleans (true|false) and null.
2019-09-23 15:31:35 +02:00
Nikita Popov
cdd4e591a4 Don't make argument nullable based on AST null initializer
Closes GH-4720.
2019-09-19 11:27:00 +02:00
Nikita Popov
597a5da027 Support computing func info from ret arg info for internal funcs 2019-09-03 10:32:47 +02:00
Nikita Popov
e63093e547 Merge branch 'PHP-7.4' 2019-08-01 10:11:02 +02:00
Nikita Popov
afd96392a3 Revert "Use RW fetch for argument unpacking"
This reverts commit 6913ec3282.
This reverts commit a9e332e027.

Causes https://bugs.php.net/bug.php?id=78356, which I don't have
a good solution for.
2019-08-01 10:06:53 +02:00
Nikita Popov
a4cfbeb143 Merge branch 'PHP-7.4' 2019-07-30 10:32:26 +02:00
Nikita Popov
a9e332e027 Handle RW UNPACK in inference 2019-07-30 10:31:51 +02:00
Nikita Popov
e3c701ea38 Merge branch 'PHP-7.2' into PHP-7.3 2019-07-05 12:07:10 +02:00
Nikita Popov
5846e85283 Backport fe_reset_rw case 2019-07-05 12:06:52 +02:00
Nikita Popov
a92e6d7136 Merge branch 'PHP-7.4' 2019-07-05 12:05:10 +02:00
Nikita Popov
73fd2da754 Make sure all cases of fetch_dim_w adjustment are handled
Use EMPTY_SWITCH_DEFAULT_CASE() to trigger an assertion in case
we miss something.

Add missing FE_RESET_RW case.
2019-07-05 12:02:26 +02:00
Nikita Popov
8ae9e1b9a2 Merge branch 'PHP-7.4' 2019-07-05 11:43:26 +02:00
Nikita Popov
1086198711 Merge branch 'PHP-7.3' into PHP-7.4 2019-07-05 11:41:57 +02:00
Nikita Popov
920283ff2b Merge branch 'PHP-7.2' into PHP-7.3 2019-07-05 11:40:45 +02:00
Nikita Popov
c353f17d42 Fix inference for compound object op on dim 2019-07-05 11:39:42 +02:00
Dmitry Stogov
1b5b8175af Merge branch 'PHP-7.4'
* PHP-7.4:
  Replace ZEND_ASSIGN_ADD (and others) by ZEND_ASSIGN_OP, ZEND_ASSIGN_DIM_OP, ZEND_ASSGIN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP
2019-07-05 12:16:30 +03:00
Dmitry Stogov
48ca5a1e17 Replace ZEND_ASSIGN_ADD (and others) by ZEND_ASSIGN_OP, ZEND_ASSIGN_DIM_OP, ZEND_ASSGIN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP 2019-07-05 12:03:25 +03:00
Nikita Popov
38909b7526 Merge branch 'PHP-7.4' 2019-06-21 10:25:17 +02:00
Nikita Popov
8227e0f747 Avoid ub in shift overflow check
Also fix an off-by-one error. While 1 << 63 overflows, -1 << 63 does
not.
2019-06-21 10:24:27 +02:00
Nikita Popov
a2d0899e74 Merge branch 'PHP-7.4' 2019-06-20 10:35:38 +02:00
Nikita Popov
e162a1c02e Fix maybe uninit warning 2019-06-20 10:35:22 +02:00
Nikita Popov
681136212f Merge branch 'PHP-7.4' 2019-06-20 10:16:31 +02:00
Nikita Popov
117c7b3f65 Avoid overflow in mul range calculation
By using ZEND_SIGNED_MULTIPLY_LONG, which already implemented
efficient overflow checking logic.
2019-06-20 09:57:55 +02:00
Nikita Popov
3a97b8b4f9 Backport "Avoid UB in overflow checks"
Cherry-pick of bb940d9969 without
the JIT parts.
2019-06-20 09:51:05 +02:00
Nikita Popov
bb940d9969 Avoid UB in overflow checks
Some of the overflow checks in zend_may_overflow were optimized
away by clang, causing JIT failures on release macos.
2019-06-19 12:02:42 +02:00
Nikita Popov
e4fae9c061 Merge branch 'PHP-7.4' 2019-06-11 13:16:38 +02:00