Commit Graph

2668 Commits

Author SHA1 Message Date
Nikita Popov
2eb33818b6 Fixed bug #79155
Make sure we only unset the NULLABLE flag temporarily for class
resolution, as the same type may be compiled multiple types.
2020-01-23 12:54:14 +01:00
Nikita Popov
9ec1ee5976 Add support for deprecating constants
Internal constants can be marked as CONST_DEPRECATED, in which
case accessing them will throw a deprecation warning.

For now this is only supported on global constants, not class
constants. Complain to me if you need to deprecate a class
constant...

Closes GH-5072.
2020-01-17 10:05:06 +01: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
Nikita Popov
d2110e9880 Use helper in one more place 2020-01-13 12:44:16 +01:00
Nikita Popov
5d869df753 Make class name references use the class_name production
Throw a compile error for "static" references instead, where it
isn't already the case.

Also extract the code that does that -- we have quite a few places
where we get a const class ref and require it to be default.
2020-01-13 11:51:09 +01:00
Dmitry Stogov
621842e3f5 RECV opcode optimization 2019-12-20 06:46:25 +03:00
Dmitry Stogov
b1f08079b5 Merge branch 'PHP-7.4'
* PHP-7.4:
  Property names of internal classes from temporary extensins, loaded by dl(), may be emalloc-ed strings.
2019-12-17 10:13:13 +03:00
Dmitry Stogov
d89cd0bb22 Property names of internal classes from temporary extensins, loaded by dl(), may be emalloc-ed strings. 2019-12-17 10:10:11 +03:00
Nikita Popov
a40a69fdd0 Merge branch 'PHP-7.4'
* PHP-7.4:
  Introduce extra counter to avoid RTD key collisions
2019-12-13 11:05:41 +01:00
Nikita Popov
0f2cdbf214 Introduce extra counter to avoid RTD key collisions
Also generate a fatal error if a collision occurs in zend_compile.

This is not perfect, because collisions might still be introduced
via opcache, if one file is included multiple times during a request,
invalidate in the meantime and recompiled by different processes.

This still needs to be addressed, but this patch fixes the much
more common case of collisions occuring when opcache is not used.

Fixes bug #78903.
2019-12-13 11:04:44 +01:00
Nikita Popov
d56768817b Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78950: Preloading trait method with static variables
2019-12-12 11:52:51 +01:00
Nikita Popov
be89a5c7f1 Fixed bug #78950: Preloading trait method with static variables
We need to make sure that trait methods with static variables
allocate a separate MAP slot for the static variables pointer,
rather than working in-place.
2019-12-12 11:52:43 +01:00
Nikita Popov
231bc7c8be Merge branch 'PHP-7.4'
* PHP-7.4:
  Revert "Fixed bug #78903: Conflict in RTD key for closures results in crash"
2019-12-11 14:40:02 +01:00
Nikita Popov
502cd7b1f1 Revert "Fixed bug #78903: Conflict in RTD key for closures results in crash"
This reverts commit b55033fa18.

This breaks ext/opcache/tests/bug65915.phpt.
2019-12-11 14:38:48 +01:00
Nikita Popov
33648585d6 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78903: Conflict in RTD key for closures results in crash
2019-12-11 13:08:12 +01:00
Nikita Popov
b55033fa18 Fixed bug #78903: Conflict in RTD key for closures results in crash
I wasn't able to create a simple reproducer for this. General approach
is the same as for anonymous classes: If the key is already used, reuse
the old definition.
2019-12-11 13:07:45 +01:00
Dmitry Stogov
8fb3ef6e37 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78937 (Preloading unlinkable anonymous class can segfault)
2019-12-11 00:47:15 +03:00
Dmitry Stogov
20ef51db22 Fixed bug #78937 (Preloading unlinkable anonymous class can segfault) 2019-12-11 00:46:30 +03:00
Nikita Popov
5cdea8d5e8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Add support for class_alias to preloading
  Fixed bug #78935: Check that all linked classes can be preloaded
2019-12-10 13:12:29 +01:00
Nikita Popov
3f86adb0ef Fixed bug #78935: Check that all linked classes can be preloaded
During preloading, check that all classes that have been included
as part of the preload script itself (rather than through opcache_compile_file)
can actually be preloaded, i.e. satisfy Windows restrictions, have
resolved initializers and resolved property types. When resolving
initializers and property types, also autoload additional classes.
Because of this, the resolution runs in a loop.
2019-12-10 13:05:48 +01:00
Nikita Popov
8b1b68d3ba Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78926: Handle class table reallocation on failed link
2019-12-09 09:16:48 +01:00
Nikita Popov
32c1f37574 Fixed bug #78926: Handle class table reallocation on failed link
When we change back the bucket key on a class linking failure,
make sure to reload the bucket pointer, as the class table may
have been reallocated in the meantime.

Also remove a bogus bucket key change in anon class registration:
We don't actually rename the class in this case anymore, the RTD
key is already the final name.
2019-12-09 09:15:27 +01:00
Nikita Popov
9554fb3498 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix constant evaluation of && and ||
2019-12-06 11:11:12 +01:00
Nikita Popov
07fc0764d1 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix constant evaluation of && and ||
2019-12-06 11:10:31 +01:00
Nikita Popov
249e49092d Fix constant evaluation of && and ||
The "return" in the for loop should have been a break on the switch,
otherwise the result is just ignored... but because it prevents
evaluation of the other operand, it also violates the invariant that
everything has been constant evaluated, resulting in an assertion
failure.

The for loop isn't correct in any case though, because it's not legal
to determine the result based on just the second operand, as the
first one may have a side-effect that cannot be optimized away.
2019-12-06 11:07:57 +01:00
Tyson Andre
67adcc5132 Remove no-op check for 'use strict;'
This should be checking for ZEND_SYMBOL_CLASS, not T_CLASS.

This was first added in 37ac1b96ed
2019-11-28 09:16:15 -05:00
Dmitry Stogov
36afe4e39e Optimize $x === null into is_null($x) 2019-11-12 13:49:55 +03:00
Dmitry Stogov
32274d81a1 Merge branch 'PHP-7.4'
* PHP-7.4:
  ws
2019-11-12 10:52:09 +03:00
Dmitry Stogov
c3f23642da ws 2019-11-12 10:51:55 +03:00
Tyson Andre
937fa6d9e2 Optimize is_scalar($x) into a TYPE_CHECK opcode
Optimizations such as specializations for is_resource were first added in
dfb4f6b38d9efedafab7d2d98b9333715561256

I don't see any mention of is_scalar (and optimizing it) in the commit history,
or in prior PRs on github, or searching for is_scalar in externals.io
2019-11-12 10:17:10 +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
Nikita Popov
e710862f8c Add compile warning for "confusable" types
We have a number of "types" like integer which are not actually
supported as builtin types -- instead they are silently interpreted
as class types.

I've seen this cause confusion a few types already. This change adds
a warning in this case. In the unlikely case that someone legitimately
wants to type against an integer class, the warning can be suppressed
by writing \integer or "use integer", or using Integer (this warning
will only trigger for lowercase spellings).

Closes GH-4815.
2019-11-07 15:05:08 +01:00
Nikita Popov
aef8836110 Don't check $this existence in object opcodes
We are now guaranteed that $this always exists inside methods, as
well as insides closures (if they use $this at all).

This removes checks for $this existence from the individual object
opcodes. Instead ZEND_FETCH_THIS is used in the cases where $this
is not guaranteed to exist, which is mainly the pseudo-main scope.

Closes GH-3822.
2019-10-30 09:30:13 +01:00
Nikita Popov
5c24f8042d Promote "Cannot use parent" to fatal error 2019-10-15 11:46:48 +02:00
Dmitry Stogov
d37f5da75e typo and cleanup 2019-10-09 17:58:35 +03:00
Dmitry Stogov
f6f32f2cf0 SAMRT BRANCH improvement.
Avoid need of insertion NOP opcoes between unrelated SMART BRANCH instruction and following JMPZ/JMPNZ.
Now instead of checking the opcode of following instruction, the same information is encoded into SMART BRANH result_type.
2019-10-09 13:48:39 +03:00
Nikita Popov
a32f130f94 Merge branch 'PHP-7.4' 2019-10-08 17:34:25 +02:00
Nikita Popov
bea832cbf6 Don't check type of simple parameter default values
After fixing the int->double coercion case, this is already verified
at compile-time, so there is no need to redo this type check on
every call.

Only perform the type check every time for the case of AST default
values.
2019-10-08 17:29:41 +02:00
Nikita Popov
cffa81e438 Merge branch 'PHP-7.4' 2019-10-08 15:52:18 +02:00
Dmitry Stogov
56ae3f6c4a Added "const" qualifier 2019-10-08 16:50:04 +03:00
Nikita Popov
9004102b99 Fixed bug #78648 2019-10-08 15:39:22 +02:00
Nikita Popov
5050507282 Merge branch 'PHP-7.4' 2019-10-04 22:47:10 +02:00
Nikita Popov
b078ae6c01 Merge branch 'PHP-7.3' into PHP-7.4 2019-10-04 22:46:53 +02:00
Nikita Popov
239e2dda64 Make sure T_ERROR is returned for all lexer exceptions
This originally manifested as a leak in oss-fuzz #18000. The following
is a reduced test case:

    <?php
    [
        5 => 1,
        "foo" > 1,
        "      " => "" == 0
    ];
    <<<BAR
    $x
     BAR;

Because this particular error condition did not return T_ERROR,
EG(exception) was set while performing binary operation constant
evaluation, which checks exceptions for cast failures.

Instead of adding this indirect test case, I'm adding an assertion
that the lexer has to return T_ERROR if EG(exception) is set.
2019-10-04 22:42:14 +02:00
Nikita Popov
11d139625f Merge branch 'PHP-7.4' 2019-10-04 10:39:32 +02:00
Nikita Popov
9659562cb5 Fix use-after-free with delayed interned memoized const operand
We should addref CONST operands during memoization, as they might
be destroyed by later compilation, e.g. through interning.
2019-10-04 10:38:11 +02:00
Nikita Popov
c10cd739a7 Merge branch 'PHP-7.4' 2019-10-04 10:12:16 +02:00
Nikita Popov
f26b60a583 Fix crash when unpacking into array literal with string keys 2019-10-04 10:11:30 +02:00
Dmitry Stogov
de3c1eb85e Move obvious optimization patterns from pass1 directly to compiler 2019-10-03 14:57:20 +03:00
Nikita Popov
d882795d78 Merge branch 'PHP-7.4' 2019-10-02 12:08:12 +02:00
Nikita Popov
171d6c3ca7 Merge branch 'PHP-7.3' into PHP-7.4 2019-10-02 12:07:33 +02:00
Nikita Popov
3c42471ef8 Merge branch 'PHP-7.2' into PHP-7.3 2019-10-02 12:07:19 +02:00
Nikita Popov
a5d3620d93 Fix segfault with __COMPILER_HALT_OFFSET__ and trailing {}
Fixes OSS-Fuzz #17895.
2019-10-02 12:07:15 +02:00
Nikita Popov
8145da0d82 Remove unused zend_del_literal() function 2019-09-27 23:58:48 +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
Dmitry Stogov
6e226c188c Change ZEND_RECV and ZEND_RECV_VARIADIC to use extended_value for cache slot (instead of op2), to be consistent with ZEND_RECV_INIT. 2019-09-23 22:28:56 +03:00
Nikita Popov
3012d006ff Don't set nullability flag for parameters without type
Use value 0 instead. To compensate we check in ReflectionParameter
allowsNull() whether the type is set at all: If it isn't, it always
allows null.

This removes a discrepancy between internal&userland functions:
For userland functions allowsNull() on untyped parameters returned
true, but for internal functions it returned false.
2019-09-23 16:39:52 +02:00
Nikita Popov
5dcbc65a53 Canonicalize typed prop/param default value errors
Use shared logic to determine what values are valid, and a single
error message format.
2019-09-23 16:20:26 +02:00
Nikita Popov
b7745d6eeb Check for nullable void type earlier 2019-09-23 15:59: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
b6d138fba1 Merge branch 'PHP-7.4' 2019-09-13 18:23:47 +02:00
Nikita Popov
4226c8247f Fix use-after-free in assign-ref compilation
zend_emit_op_data may reallocate the op_array, so the assignment
of the RETURNS_FUNCTION flag may happen on an outdated opline.

Restructure the code a bit to set the flag before calling
zend_emit_op_data().
2019-09-13 18:22:14 +02:00
Dmitry Stogov
8a673e9380 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed incorrect usage of QM_ASSIGN instruction
2019-09-13 12:13:25 +03:00
Dmitry Stogov
e45a757bc2 Fixed incorrect usage of QM_ASSIGN instruction 2019-09-13 12:08:59 +03:00
Nikita Popov
f61f122b9a Merge branch 'PHP-7.4' 2019-09-12 16:41:45 +02:00
Nikita Popov
4b9ebd837b Allow throwing exception while loading parent class
This is a fix for symfony/symfony#32995.

The behavior is:

* Throwing exception when loading parent/interface is allowed
  (and we will also throw one if the class is simply not found).
* If this happens, the bucket key for the class is reset, so
  it's possibly to try registering the same class again.
* However, if the class has already been used due to a variance
  obligation, the exception is upgraded to a fatal error, as we
  cannot safely unregister the class stub anymore.
2019-09-12 16:41:18 +02:00
Nikita Popov
a09da43888 Merge branch 'PHP-7.4' 2019-09-11 17:05:07 +02:00
Nikita Popov
d88b212ea6 Improve "already declared" error message
If this error is missing because the rtd_key was renamed to lcname,
fetch the class based on lcname and use the class type and cased
name from there.
2019-09-11 17:04:13 +02:00
Nikita Popov
e530a89c00 Merge branch 'PHP-7.4' 2019-09-06 11:33:36 +02:00
Nikita Popov
e81751ceac Fixed bug #78502
We need to make sure that the function is fully compiled before we
calculate the stack size. There already was a check for directly
recursive calls, but the same issue exists with indirectly recursive
calls.

I'm using DONE_PASS_TWO as the indication that the function is
fully compiled.
2019-09-06 11:33:28 +02:00
Dmitry Stogov
a5597312e4 Fixed performance degradation caused by arg_info of internal function 2019-09-02 12:11:18 +03:00
Nikita Popov
4e4cc9b480 Merge branch 'PHP-7.4' 2019-08-23 17:23:31 +02:00
Nikita Popov
d1157cbce1 Relax closure $this unbinding deprecation
Only deprecate unbinding of $this from a closure if $this is
syntactically used within the closure.

This is desired to support Laravel's macro system, see laravel/framework#29482.

This should still allow us to implement the performance improvements
we're interested in for PHP 8, without breaking existing use-cases.
2019-08-23 17:21:23 +02:00
Nikita Popov
f0d4c48c7e Merge branch 'PHP-7.4' 2019-08-12 17:18:14 +02:00
Nikita Popov
b6f1b61f8f Merge branch 'PHP-7.3' into PHP-7.4 2019-08-12 17:17:42 +02:00
Nikita Popov
4cd563d07e Merge branch 'PHP-7.2' into PHP-7.3 2019-08-12 17:17:30 +02:00
Nikita Popov
f3fdf570b3 Intern alias old_name early
This is likely going to end up interned lateron at some point
when the new_name is referenced somewhere. However, it may be
that there are some uses that do not get interned before that.
In this case we will intern a string that already have zval
users, without updating the refcounted flag on those zvals.

In particular this can happen with something like [Foo::class],
where Foo is an imported symbol. The string it resolves to won't
get interned right away, but may be interned later.

    use Foo as Bar;
    $x = [Bar::class];
    var_dump(Bar::X);
    debug_zval_dump($x); // Will show negative refcount
    class Foo {
        const X = 1;
    }

However, this doesn't really fix the root cause, there are probably
other situations where something similar can occur.
2019-08-12 17:12:28 +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
14f99ede42 Merge branch 'PHP-7.4' 2019-07-30 10:07:25 +02:00
Nikita Popov
6913ec3282 Use RW fetch for argument unpacking
Argument unpacking may need to create references inside the array
that is being unpacked. However, it currently can only do this
if a plain variable is unpacked, not for any nested accesses,
because the value is fetched for read. Resolve this by fetching
the operands for RW.
2019-07-30 10:07:08 +02:00
Nikita Popov
cd1c651af1 Merge branch 'PHP-7.4' 2019-07-29 11:13:33 +02:00
Nikita Popov
4ae807e84e Fixed bug #78344
When performing a constant visibility check during compilation we
might be dealing with unlinked classes and as such should account
for the possibility of unresolved parents.
2019-07-29 11:12:00 +02:00
Nikita Popov
36db71df47 Merge branch 'PHP-7.4' 2019-07-22 12:28:40 +02:00
Nikita Popov
4e190691e2 Deprecate is_real() function 2019-07-22 11:39:52 +02:00
Dmitry Stogov
97912023bb Merge branch 'PHP-7.4'
* PHP-7.4:
  Use run-time cache to avoid repeatable hash lookups in ZEND_DECLARE_CLASS_DELAYED
2019-07-19 11:46:35 +03:00
Dmitry Stogov
445d51347d Use run-time cache to avoid repeatable hash lookups in ZEND_DECLARE_CLASS_DELAYED 2019-07-19 11:46:03 +03:00
Nikita Popov
eb766751dc Merge branch 'PHP-7.4' 2019-07-19 10:06:30 +02:00
rjhdby
d574df63dc Deprecate alternative array access syntax
RFC: https://wiki.php.net/rfc/deprecate_curly_braces_array_access
2019-07-19 10:06:10 +02:00
Dmitry Stogov
a837b80a48 Merge branch 'PHP-7.4'
* PHP-7.4:
  Use run-time cache to avoid repeatable hash lookups when creating anonymous functions and classes
2019-07-19 10:45:00 +03:00
Dmitry Stogov
d5943f5a11 Use run-time cache to avoid repeatable hash lookups when creating anonymous functions and classes 2019-07-19 10:43:49 +03:00
Dmitry Stogov
5ac3580b9b Merge branch 'PHP-7.4'
* PHP-7.4:
  ZEND_DECLARE_ANON_CLASS doesn't need to skip anything now. It's immediatelly followed by ZEND_NEW.
2019-07-19 10:10:50 +03:00
Dmitry Stogov
b065fbde19 ZEND_DECLARE_ANON_CLASS doesn't need to skip anything now. It's immediatelly followed by ZEND_NEW. 2019-07-19 10:09:26 +03:00
Nikita Popov
9207aef60c Merge branch 'PHP-7.4' 2019-07-15 16:26:25 +02:00
Nikita Popov
c5f1b384b5 Move shebang handling into the lexer
Instead of handling shebang lines by adjusting the file pointer in
individual SAPIs, move the handling into the lexer, where this is
both a lot simpler and more robust. Whether the shebang should be
skipped is controlled by CG(skip_shebang) -- we might want to do
that in more cases.

This fixed bugs #60677 and #78066.
2019-07-15 16:25:49 +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
b4121f4930 Merge branch 'PHP-7.4' 2019-06-28 12:45:26 +02:00
Nikita Popov
9f81c56e42 Fix out-of-bounds read in array compilation
UNPACK elements only have one child. Don't access the second one
until we have excluded this case.
2019-06-28 12:44:46 +02:00
Dmitry Stogov
e2effc96b4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Avoid double checks on early binding
2019-06-27 02:25:57 +03:00
Dmitry Stogov
83b99527df Avoid double checks on early binding 2019-06-27 02:13:06 +03:00
Dmitry Stogov
0655598280 Merge branch 'PHP-7.4'
* PHP-7.4:
  Set ZEND_ACC_LINKED flag after early binding (for consistency)
2019-06-25 15:06:19 +03:00
Dmitry Stogov
1d534b9da5 Set ZEND_ACC_LINKED flag after early binding (for consistency) 2019-06-25 15:05:27 +03:00
Dmitry Stogov
e4f4be1a05 Merge branch 'PHP-7.4'
* PHP-7.4:
  Reduce overhead of delayed early binding
2019-06-25 14:21:23 +03:00
Dmitry Stogov
e8f1f70101 Reduce overhead of delayed early binding 2019-06-25 14:20:41 +03:00
Dmitry Stogov
ca22c456ca Merge branch 'PHP-7.4'
* PHP-7.4:
  Keep lowercased parent class name as second argument of DECLARE_CLASS to avoid extra work at run-time
2019-06-25 11:32:03 +03:00
Dmitry Stogov
759f4ecd8b Keep lowercased parent class name as second argument of DECLARE_CLASS to avoid extra work at run-time 2019-06-25 11:30:58 +03:00
Dmitry Stogov
e18c60cd8d Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug 78175 (Preloading must store default values of static variables and properties)
2019-06-24 20:34:05 +03:00
Dmitry Stogov
0f29fb5cd8 Fixed bug 78175 (Preloading must store default values of static variables and properties) 2019-06-24 20:32:27 +03:00
twosee
61f78de486 Constify some char* arguments or return values of ZEND_API
Closes GH-4247.
2019-06-12 16:49:32 +02:00
Nikita Popov
477d1e02ae Merge branch 'PHP-7.4' 2019-06-12 11:54:21 +02:00
Nikita Popov
f601eb15e6 Fix -Wmissing-braces warnings
Unfortunate that = {} is a GNU extension.
2019-06-12 11:54:12 +02:00
Nikita Popov
e4fae9c061 Merge branch 'PHP-7.4' 2019-06-11 13:16:38 +02:00
Nikita Popov
8f8fcbbd39 Support full variance if autoloading is used
Keep track of delayed variance obligations and check them after
linking a class is otherwise finished. Obligations may either be
unresolved method compatibility (because the necessecary classes
aren't available yet) or open parent/interface dependencies. The
latter occur because we allow the use of not fully linked classes
as parents/interfaces now.

An important aspect of the implementation is we do not require
classes involved in variance checks to be fully linked in order for
the class to be fully linked. Because the involved types do have to
exist in the class table (as partially linked classes) and we do
check these for correct variance, we have the guarantee that either
those classes will successfully link lateron or generate an error,
but there is no way to actually use them until that point and as
such no possibility of violating the variance contract. This is
important because it ensures that a class declaration always either
errors or will produce an immediately usable class afterwards --
there are no cases where the finalization of the class declaration
has to be delayed until a later time, as earlier variants of this
patch did.

Because variance checks deal with classes in various stages of
linking, we need to use a special instanceof implementation that
supports this, and also introduce finer-grained flags that tell us
which parts have been linked already and which haven't.

Class autoloading for variance checks is delayed into a separate
stage after the class is otherwise linked and before delayed
variance obligations are processed. This separation is needed to
handle cases like A extends B extends C, where B is the autoload
root, but C is required to check variance. This could end up
loading C while the class structure of B is in an inconsistent
state.
2019-06-11 13:09:33 +02:00
Nikita Popov
89b2d88659 Register class before fetching parent
We want the class declaration to be available while compiling the
parent class.
2019-06-11 13:09:33 +02:00
Joe Watkins
1b9ffcb21b
Merge branch 'PHP-7.4'
* PHP-7.4:
  BIND_LEXICAL has a meaningless line number
2019-06-10 14:19:58 +02:00
Joe Watkins
42d60addef
BIND_LEXICAL has a meaningless line number 2019-06-10 14:19:39 +02:00
Joe Watkins
a583241704
Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #78132 wrong line number on ZEND_BIND_STATIC for lexical vars
2019-06-08 21:48:00 +02:00
Joe Watkins
006b191126
Fix #78132 wrong line number on ZEND_BIND_STATIC for lexical vars 2019-06-08 21:47:07 +02:00
Nikita Popov
775e86344f Merge branch 'PHP-7.4' 2019-05-31 12:56:51 +02:00
Nikita Popov
67b84e4548 Fixed uninitialized var warning
Causes build failure on release+zts azure build. I'm rewriting this
code to separate the if/else handling, because they don't really
have anything in common anyway...
2019-05-31 12:55:13 +02:00
Nikita Popov
45c663a9d3 Merge branch 'PHP-7.4' 2019-05-27 17:13:00 +02:00
Nikita Popov
fd23f9104a BIND_STATIC of implicit binding may be undef
Even though we don't need it at runtime, add the BIND_IMPLICIT
flag to BIND_STATIC as well, so we can distinguish this case in
type inference.

This fixes a JIT miscompile in arrow_functions/002.phpt.
2019-05-27 17:12:20 +02:00
Nikita Popov
13f675b858 Merge branch 'PHP-7.4' 2019-05-27 09:38:33 +02:00
Nikita Popov
e6fac86dc3 Accept flags argument in zend_lookup_class_ex()
Instead of a single boolean, so we have space for extension here.
2019-05-27 09:36:25 +02:00
Nikita Popov
038db18496 Merge branch 'PHP-7.4' 2019-05-24 11:02:03 +02:00
Nikita Popov
d7f3844c87 Deprecate use of parent where no parent exists
This deprecation is part of the covariance RFC.
2019-05-24 10:58:46 +02:00
Nikita Popov
e06ec226bc Merge branch 'PHP-7.4' 2019-05-24 09:33:58 +02:00
Nikita Popov
afec3a9208 Avoid early-binding on unresolved types
Fixes bug #76451, and more importantly lays necessary groundwork for
covariant/contravariant types. Bug #76451 is just an edge case, but
once covariance is introduced this will become a common problem instead.
2019-05-24 09:30:13 +02:00
Dmitry Stogov
1e10c06f20 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78014 (Preloaded classes may depend on non-preloaded classes due to unresolved consts)
2019-05-20 18:16:01 +03:00
Dmitry Stogov
f53b9939fe Fixed bug #78014 (Preloaded classes may depend on non-preloaded classes due to unresolved consts) 2019-05-20 18:15:38 +03:00
Bob Weinand
cbc90b1f6e Merge branch 'deprecate_concat_add_sub' into PHP-8.4 2019-05-16 18:31:28 +02:00
Nikita Popov
f106f57164 Merge branch 'PHP-7.4' 2019-05-13 14:43:10 +02:00
CHU Zhaowei
e829d08729 Implement spread operator in arrays
RFC: https://wiki.php.net/rfc/spread_operator_for_array

Closes GH-3640.
2019-05-13 14:42:43 +02:00
Nikita Popov
b8c2b43778 Merge branch 'PHP-7.4' 2019-05-09 14:35:25 +02:00
Nikita Popov
d0a56f707f Fixed bug #71030
Make sure to always fetch the RHS of a list assignment first, instead
of special casing known self-assignments, which will not detect cases
using references correctly.

As a side-effect, it is no longer possible to do something like
byRef(list($x) = $y). This worked by accident previously, but only
if $y was a CV and the self-assignment case did not trigger.
However it shouldn't work for the same reason that byRef($x = $y)
doesn't. Conversely byRef(list(&$x) = $y) and byRef($x =& $y)
continue to be legal.
2019-05-09 14:31:39 +02:00
Nikita Popov
3619cc78a8 Merge branch 'PHP-7.4' 2019-05-07 14:07:30 +02:00
Nikita Popov
09ea55cb4e Deprecate left-associative ternary
Deprecate nesting ternary operators without explicit parentheses.

RFC: https://wiki.php.net/rfc/ternary_associativity
2019-05-07 14:06:29 +02:00
Nikita Popov
79f41944ba Merge branch 'PHP-7.4' 2019-05-02 15:07:04 +02:00
Nikita Popov
f3e5bbe6f3 Implement arrow functions
Per RFC: https://wiki.php.net/rfc/arrow_functions_v2

Co-authored-by: Levi Morrison <levim@php.net>
Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
2019-05-02 15:04:03 +02:00
Dmitry Stogov
c78fc4971e Fixed access to uninitialized vaiable. 2019-04-18 10:48:04 +03:00
Nikita Popov
3fab73e24e Avoid misc uninitialized variable warnings 2019-04-12 15:12:45 +02:00
Nikita Popov
339b0af429 Avoid misc uninitialized variable warnings 2019-04-12 15:12:39 +02:00
Dmitry Stogov
39505764ad Merge branch 'PHP-7.4'
* PHP-7.4:
  Replace "ZEND_CALL_CTOR" hack by additional live-range
2019-04-12 01:01:47 +03:00
Dmitry Stogov
88a2268d6b Replace "ZEND_CALL_CTOR" hack by additional live-range 2019-04-12 00:49:45 +03:00
Nikita Popov
8f441c90ca Merge branch 'PHP-7.4' 2019-04-11 10:49:38 +02:00
Nikita Popov
30df87f77d Generate ZEND_COUNT for sizeof()
sizeof() is an alias of count(), so we should generate the same
code for them.
2019-04-11 10:48:52 +02:00
Bob Weinand
3b23694aac Deprecate unparenthesized concatenation and addition/subtraction
Implementing RFC https://wiki.php.net/rfc/concatenation_precedence
2019-03-28 23:54:38 +01:00
Nikita Popov
0720313bd4 Merge branch 'PHP-7.4' 2019-03-28 09:31:18 +01:00
Nikita Popov
7f72d771e8 Revert "Switch to bison location tracking"
This reverts commit e528762c1c.

Dmitry reports that this has a non-trivial impact on parsing
overhead, especially on 32-bit systems. As we don't have a strong
need for this change right now, I'm reverting it.

See also comments on
e528762c1c.
2019-03-28 09:29:08 +01:00
Nikita Popov
6b7545c225 Merge branch 'PHP-7.4' 2019-03-21 16:28:19 +01:00
Nikita Popov
e528762c1c Switch to bison location tracking
Locations for AST nodes are now tracked with the help of bison
location tracking. This is more accurate than what we currently do
and easier to extend with more information.

A zend_ast_loc structure is introduced, which is used for the location
stack. Currently it only holds the start lineno, but can be extended
to also hold end lineno and offset/column information in the future.

All AST constructors now accept a zend_ast_loc* as first argument, and
will use it to determine their lineno. Previously this used either the
CG(zend_lineno), or the smallest AST lineno of child nodes.

On the parser side, the location structure for a whole rule can be
obtained using the &@$ character salad.
2019-03-21 16:27:48 +01:00
Nikita Popov
8bb5582751 Merge branch 'PHP-7.3' into PHP-7.4 2019-03-14 17:26:17 +01:00
Xinchen Hui
cc16781e9e Merge branch 'PHP-7.3'
* PHP-7.3:
  updated NEWS
  Fixed bug #77738 (Nullptr deref in zend_compile_expr)
2019-03-14 16:47:30 +08:00
Xinchen Hui
e3965913c4 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fixed bug #77738 (Nullptr deref in zend_compile_expr)
2019-03-14 16:46:46 +08:00
Xinchen Hui
c7920aba3e Fixed bug #77738 (Nullptr deref in zend_compile_expr) 2019-03-14 16:46:04 +08:00
Stanislav Malyshev
7803cb32af Oops, forgot error parameter 2019-03-06 22:44:16 -08:00
Stanislav Malyshev
0ef6c62685 Fix broken memcmp
We can't really do memcmp("_call", "__callStatic", sizeof("__callStatic") -1),
neither should we memcmp constants at all.
2019-03-06 22:22:58 -08:00
rjhdby
1be120f681 Cleanup some checks in zend_compile.c 2019-03-06 10:42:02 +01:00
Nikita Popov
b90730c762 Merge branch 'PHP-7.4' 2019-03-04 12:24:09 +01:00
Nikita Popov
deb44d405e Revert "Detect invalid uses of parent:: during compilation"
This reverts commit a9e6667817.

Breakage found in the wild: Mockery uses a parent:: call in the
implementation regardless of whether the class has a parent or not:
4324afeaf9/library/Mockery/Mock.php (L600)

This change is not worth the compat break in 7.4.
2019-03-04 12:24:02 +01:00
Bob Weinand
76e3828978 Merge branch 'PHP-7.4' 2019-02-27 18:47:03 +01:00
Bob Weinand
94d3e40102 Delay array to string conversion notice until runtime 2019-02-27 18:46:31 +01:00
Nikita Popov
a8daef51e1 Merge branch 'PHP-7.3' into PHP-7.4 2019-02-25 13:02:58 +01:00
Xinchen Hui
761b0639bb Merge branch 'PHP-7.3'
* PHP-7.3:
  Fixed compiler warning
2019-02-25 15:04:13 +08:00
Xinchen Hui
4ac954ac3e Fixed compiler warning 2019-02-25 15:04:04 +08:00
Xinchen Hui
249f7df221 Merge branch 'PHP-7.3'
* PHP-7.3:
  Update NEWS
  Fixed bug #77660 (Segmentation fault on break 2147483648)
2019-02-25 15:00:44 +08:00
Xinchen Hui
e8768b338c Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fixed bug #77660 (Segmentation fault on break 2147483648)
2019-02-25 15:00:23 +08:00
Xinchen Hui
1c22ace058 Fixed bug #77660 (Segmentation fault on break 2147483648) 2019-02-25 15:00:14 +08:00
Peter Kokot
20addf88e4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove unused PHP_AC_BROKEN_SPRINTF and AC_ZEND_BROKEN_SPRINTF
2019-02-23 22:29:16 +01:00
Peter Kokot
b33fa18eab Remove unused PHP_AC_BROKEN_SPRINTF and AC_ZEND_BROKEN_SPRINTF
The sprintf function has been normalized to php_sprintf via
61364b5bb1.

This patch removes the checks to make a custom sprintf function

The ZEND_BROKEN_SPRINTF has been removed and the
hardcoded #define zend_sprintf sprintf is used.

The php_sprintf and zend_sprintf are now symbols to sprintf.

This patch now removes the custom PHP definitions of the php_sprintf and
zend_sprintf functions in favor of the C99 sprintf which is also
standardized in C89 already. Once, on some systems sprintf didn't behave
in same way.
2019-02-23 22:26:47 +01:00
Nikita Popov
276de41014 Merge branch 'PHP-7.4' 2019-02-22 15:44:13 +01:00
Nikita Popov
52605aafc5 Fix anon class handling in ext mode
Opcode order changes in 7.4 and the EXT_STMT is now declare the
DECLARE_ANON. Fix this by returning the opline from compile_class_decl
to avoid any fragile opcode searching.
2019-02-22 15:43:08 +01:00
Nikita Popov
bd2a00acdf Merge branch 'PHP-7.2' into PHP-7.3 2019-02-22 10:13:21 +01:00
Nikita Popov
5388143855 Fixed bug #77652 2019-02-22 10:11:54 +01:00
Joe Watkins
97e09049e2
Merge branch 'PHP-7.4'
* PHP-7.4:
  While the compiler does not have the FBC set for zend_get_call_op, optimizer does, and so incorrectly results in ignoring these flags.
2019-02-21 23:55:54 +01:00
Joe Watkins
4d3415636d
While the compiler does not have the FBC set for zend_get_call_op, optimizer does, and so incorrectly results in ignoring these flags.
If someone has a better patch, please merge it ASAP, this appears to be correct as I and Nikita originally thought.

Revert "Revert "zend_get_call_op ignoring compiler flags zend_get_call_op will ignore ZEND_COMPILE_IGNORE_USER_FUNCTIONS and ZEND_COMPILE_IGNORE_USER_FUNCTIONS, breaking the intention of these flags""

This reverts commit 0bbbd0f9e7.
2019-02-21 23:54:26 +01:00
Joe Watkins
75ef3eac21
Merge branch 'PHP-7.4'
* PHP-7.4:
  Revert "zend_get_call_op ignoring compiler flags zend_get_call_op will ignore ZEND_COMPILE_IGNORE_USER_FUNCTIONS and ZEND_COMPILE_IGNORE_USER_FUNCTIONS, breaking the intention of these flags"
2019-02-21 22:41:13 +01:00
Joe Watkins
0bbbd0f9e7
Revert "zend_get_call_op ignoring compiler flags zend_get_call_op will ignore ZEND_COMPILE_IGNORE_USER_FUNCTIONS and ZEND_COMPILE_IGNORE_USER_FUNCTIONS, breaking the intention of these flags"
This reverts commit 46807ec5da.
2019-02-21 22:40:02 +01:00
Joe Watkins
7a9d638302
Merge branch 'PHP-7.4'
* PHP-7.4:
  zend_get_call_op ignoring compiler flags zend_get_call_op will ignore ZEND_COMPILE_IGNORE_USER_FUNCTIONS and ZEND_COMPILE_IGNORE_USER_FUNCTIONS, breaking the intention of these flags
2019-02-21 11:22:43 +01:00
Joe Watkins
46807ec5da
zend_get_call_op ignoring compiler flags zend_get_call_op will ignore ZEND_COMPILE_IGNORE_USER_FUNCTIONS and ZEND_COMPILE_IGNORE_USER_FUNCTIONS, breaking the intention of these flags 2019-02-21 11:22:30 +01:00
Christoph M. Becker
44ebbf0de1 Merge branch 'PHP-7.4'
* PHP-7.4:
  fix #77642: typo "incompatibe" in Zend/zend_compile.c [ci skip]
2019-02-20 19:41:25 +01:00
divinity76
876369bea2 fix #77642: typo "incompatibe" in Zend/zend_compile.c [ci skip]
the word "incompatible" was accidentally written as "incompatibe"

guilty commit: 7e597f48e9
2019-02-20 19:41:09 +01:00
Joe Watkins
b7a442ed7b
Merge branch 'PHP-7.4'
* PHP-7.4:
  begin handlers are currently invoked without access to the arguments being sent, this moves the opcode after SEND
2019-02-19 18:21:49 +01:00
Joe Watkins
a3994a9e16
begin handlers are currently invoked without access to the arguments being sent, this moves the opcode after SEND 2019-02-19 18:21:32 +01:00
Nikita Popov
f37c70c7fb Merge branch 'PHP-7.4' 2019-02-19 10:12:01 +01:00
Joe Watkins
f8cd8eb740
ZEND_COMPILE_EXTENDED_INFO split Currently a tool may not decide between debugging and profiling behaviour: We split ZEND_COMPILE_EXTENDED_INFO into ZEND_COMPILE_EXTENDED_FCALL and ZEND_COMPILE_EXTENDED_STMT We define ZEND_COMPILE_EXTENDED_INFO as ZEND_COMPILE_EXTENDED_STMT|ZEND_COMPILE_EXTENDED_FCALL 2019-02-19 10:07:02 +01:00
Peter Kokot
18295b396f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix typos in code comments in Zend/ [skip ci]
2019-02-18 17:56:38 +01:00
Tyson Andre
da3316ff0f Fix typos in code comments in Zend/ [skip ci] 2019-02-18 17:56:28 +01:00
Christoph M. Becker
47bcc02823 Merge branch 'PHP-7.4'
* PHP-7.4:
  Unify clone method error message
2019-02-15 15:08:41 +01:00
rjhdby
d6a53ed5e0 Unify clone method error message 2019-02-15 15:08:02 +01:00
Nikita Popov
903821b1c7 Merge branch 'PHP-7.4' 2019-02-15 11:28:14 +01:00
Nikita Popov
3cafa7f4df Assign (un)serialize_func during compilation
This avoids writing this cache at runtime, which is illegal if
preloading is used.

Not every serialize/unserialize function actually belongs to the
Serializable interface, but I think it's not a problem to assign
these anyway -- whether they are used ultimately depends on whether
Serializable is implemented.

Alternatively it might make sense to just drop these entirely. I
don't think this is performance critical functionality.
2019-02-15 11:20:28 +01:00
Dmitry Stogov
4474cf43e6 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #77613 (method visibility change) (reverted ZEND_ACC_CTOR and ZEND_ACC_DTOR flags removal)
2019-02-14 13:18:45 +03:00
Dmitry Stogov
43a7d95016 Fixed bug #77613 (method visibility change) (reverted ZEND_ACC_CTOR and ZEND_ACC_DTOR flags removal) 2019-02-14 13:12:50 +03:00
Nikita Popov
8afa2c632b Merge branch 'PHP-7.4' 2019-02-12 17:37:34 +01:00
Nikita Popov
9364153942 Fixed bug #76430
It's somewhat ambiguous what exactly the correct behavior is
supposed to be, I'm just picking something more or less reasonable
here.
2019-02-12 17:36:07 +01:00
Peter Kokot
623911f993 Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove local variables
2019-02-03 21:23:18 +01:00
Peter Kokot
92ac598aab Remove local variables
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.

A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.

This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.

With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.

Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files.  All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
2019-02-03 21:03:00 +01:00