Commit graph

249 commits

Author SHA1 Message Date
Dmitry Stogov
1434983ad1 Cheaper exception checks 2020-06-25 13:23:43 +03:00
Dmitry Stogov
8b12ea04ee Improved JIT for RECV and RECV_INIT instructions 2020-06-23 23:21:56 +03:00
Dmitry Stogov
6ac16882d4 Reduce amount of "cold" code generated for FETCH_OBJ_* instructions 2020-06-23 17:16:44 +03:00
Dmitry Stogov
bdac60d2c0 Improve JIT for SEPARATE_ARRAY 2020-06-23 13:46:56 +03:00
Dmitry Stogov
b4b5734d80 JIT for FETCH_OBJ_W 2020-06-19 14:36:38 +03:00
Dmitry Stogov
18347758d7 Improved JIT for SEPARATE_ARRAY 2020-06-17 14:45:25 +03:00
Dmitry Stogov
a459799910 Improved JIT for ZVAL_COPY_DEREF 2020-06-16 13:24:28 +03:00
Dmitry Stogov
217f6e16d6 Use cheaper variant of zend_hash_index_find() 2020-06-11 01:34:55 +03:00
twosee
83a77015ad Add helper APIs for maybe-interned string creation
Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using
ZVAL_INTERNED_STRING and ZSTR_CHAR.

Add zend_string_init_fast() as a helper for the empty string /
one char interned string / zend_string_init() pattern.

Also add corresponding ZVAL_STRINGL_FAST etc macros.

Closes GH-5684.
2020-06-08 15:31:52 +02:00
Dmitry Stogov
e18f631abe Use light version of zend_array_destroy() to free arrays without refcounted elements and string indexes. 2020-05-20 00:12:24 +03:00
Máté Kocsis
1179686f62
Improve error messages for invalid property access
Closes GH-5446
Co-authored-by:  Nikita Popov <nikita.ppv@gmail.com>
2020-05-18 08:27:00 +02:00
Máté Kocsis
36935e42ea
Improve undefined variable error messages
Closes GH-5312
2020-03-31 13:02:32 +02:00
Dmitry Stogov
3715475381 JIT for INIT_NS_FCALL_BY_NAME 2020-03-20 15:36:40 +03:00
Dmitry Stogov
12cdab2d76 Improved JIT for BIND_GLOBAL 2020-03-18 17:20:40 +03:00
Nikita Popov
941a3b6ccd Remove unnecessary uses of CHECK_SILENT
If no error is passed, it is always silent.
2020-03-06 16:36:45 +01: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
bc6bab6cb4 Basic JIT support for verify return 2020-02-07 12:59:48 +03:00
Dmitry Stogov
170cc10519 Fixed JIT for PTR_INC instruction to return de-referenced value of reference 2020-02-06 21:29:43 +03:00
Dmitry Stogov
daee985709 Fixed JIT for BIND_GLOBAL 2020-02-04 15:56:55 +03:00
Nikita Popov
bd1977282c Use zend_type inside type lists
Instead of having a completely independent encoding for type list
entries. This is going to use more memory, but I'm not particularly
concerned about that, as type unions that contain multiple classes
should be uncommon. On the other hand, this allows us to treat
top-level types and types inside lists mostly the same.

A new ZEND_TYPE_FOREACH macros allows to transparently treat list
and non-list types the same way. I'm not using it everywhere it could be
used for now, just the places that seemed most obvious.

Of course, this will make any future type system changes much simpler,
as it will not be necessary to duplicate all logic two times.
2020-01-17 09:37:54 +01:00
George Peter Banyard
bfe3f934a3 Add warning and convert to exception in string offset assignment:
Convert the empty string assignment to an Error as per RFC [1]
Add a warning that only the first byte will be assigned to the offset if provided
a needle that is longer than one byte.

[1] https://wiki.php.net/rfc/engine_warnings
2020-01-07 21:54:42 +01:00
Nikita Popov
2bc0a6e97f Fix string offset signed int UB in jit as well 2019-12-20 12:11:07 +01: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
Máté Kocsis
14bdb0cfc7 Fix consistency issues with array accesses warnings/exceptions
* Change a number of "resource used as offset" notices to warnings,
   which were previously missed.
 * Throw the "resource used as offset" warning for isset() as well.
 * Make array_key_exists() behavior with regard to different key
   types consistent with isset() and normal array accesses. All key
   types now use the usual coercions and array/object keys throw
   TypeError.

Closes GH-4887.
2019-11-06 12:56:47 +01:00
Nikita Popov
fe6c420b02 JIT: Handle typed refs in assign dim 2019-10-23 11:25:10 +02:00
Nikita Popov
2f80fbe3ae JIT: Fix handling of typed ref in assign op 2019-10-23 10:08:09 +02:00
Nikita Popov
097184cae7 JIT: UNDEF result on "Illegal offset type" exception 2019-10-23 10:07:48 +02:00
Nikita Popov
e80934d747 Pass cache slot when printing type errors
Instead of using a separate ce.
2019-10-17 17:06:48 +02:00
Dmitry Stogov
51da02375a Fixed exception handling 2019-10-16 02:36:06 +03:00
Dmitry Stogov
0d55456d73 Use "const" qualifier 2019-10-15 11:06:11 +03:00
Nikita Popov
2f92957fd3 Convert some notices to warnings
Part of https://wiki.php.net/rfc/engine_warnings.
2019-10-02 10:34:08 +02: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
e8b0163e0b Promote write "use scalar as array" warning to Error 2019-09-27 15:49:18 +02:00
Nikita Popov
0ebf2bdba0 Convert "Illegal offset type" warnings to exceptions 2019-09-27 13:00:07 +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
26431d1995 Implement array access notice in JIT 2019-07-10 12:20:16 +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
Nikita Popov
4d90848d68 Don't verify arginfo types for internal functions
To avoid duplicate type checks. In debug builds arginfo is still
checked and will generate an assertions if the function doesn't
subsequently throw an exception.

Some test results change due to differences in zpp and arginfo
error messages.
2019-06-17 11:46:28 +02:00
Nikita Popov
792e38d863 Fix bug #78154 with JIT 2019-06-13 11:53:31 +02:00
Nikita Popov
45a0656e95 Remove get() object handler
Now that set() is gone, there is little point in keeping get(), as
it is essentially just a different way of writing cast_object()
now.

Closes GH-4202.
2019-05-29 17:15:19 +02:00
Dmitry Stogov
cc900edd77 Simplify call frame initialization 2019-04-11 02:08:32 +03:00
David Carlier
914b27acb7 Fix few compiler warnings. 2019-04-08 00:00:09 +02:00
Christoph M. Becker
ba67d44e07 Fix misplacement of calling convention declaration
MSVC is particularly picky about this, and won't compile as it is.
2019-04-02 14:10:10 +02:00
Dmitry Stogov
4e1d545d47 Fixed edge cases in ZEND_ASSIGN_OP+ASSIGN_DIM and replaced specialized helpers with single one 2019-04-01 23:17:45 +03:00
Dmitry Stogov
8bf2de045b Removed checks for required object handlers 2019-04-01 21:50:20 +03:00
Dmitry Stogov
d196ec9b93 Eliminate hash lookup for immutable op_arrays 2019-04-01 21:20:52 +03:00
Dmitry Stogov
9a06876072 Added JIT compiler for x86 and x86_64 2019-04-01 10:27:11 +03:00