Commit graph

2044 commits

Author SHA1 Message Date
Dmitry Stogov
77bf144d52 Inline hot parts of bitwise instructions into hybrid VM 2020-01-14 13:47:10 +03:00
Nikita Popov
d0d1654a34 Fix #49555: Improve "function must be a string" error message
Be more specific for the individual cases and provide relevant
type information.
2020-01-08 14:32:11 +01:00
Nikita Popov
33476ec301 Refer to method rather than function name in error message 2020-01-08 14:26:27 +01:00
Nikita Popov
ae5d7604f6 Fix #65274: Add class name to undef class constant error 2020-01-08 14:18:14 +01:00
Tyson Andre
dea62d4b0c Speed up ZEND_IS_IDENTICAL when it can't throw
Add a specialized opcode handler to use for `===`/`!==` when:

1. At least one side is a $cv, and the other is a $cv or CONST
   (avoids the need to free operands)
2. Neither operand can be undefined or a reference
   (avoids the need for error handling and dereferencing)

```
// Elapsed time decreased from 0.275 seconds to 0.243 seconds in combination
// with PR #4982
function count_same(array $values) {
    $same = 0;
    foreach ($values as $x) {
        foreach ($values as $y) {
            if ($y === $x) {
                $same++;
            }
        }
    }
    return $same;
}
$values = range(0, 5000);
$values[] = new stdClass();
$values[] = null;
$values[] = 3;
$start = microtime(true);
$total = count_same($values);
```
2019-12-23 15:42:42 -05:00
Nikita Popov
0d8ebbaa73 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix early free of assign_obj op_data
2019-12-20 10:35:50 +01:00
Nikita Popov
885b3451f4 Fix early free of assign_obj op_data
We need to make sure that op_data is only freed after populating
result, as op_data may be the only thing holding the value in the
case of an overloaded assignment.

This reverts the code to how it looked like in 7.3.
2019-12-20 10:35:34 +01:00
Dmitry Stogov
621842e3f5 RECV opcode optimization 2019-12-20 06:46:25 +03:00
Dmitry Stogov
a31b5eca68 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78999 (Cycle leak when using function result as temporary)
2019-12-19 23:19:31 +03:00
Dmitry Stogov
66d5b0608a Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #78999 (Cycle leak when using function result as temporary)
2019-12-19 23:17:39 +03:00
Dmitry Stogov
eb846939b1 Fixed bug #78999 (Cycle leak when using function result as temporary) 2019-12-19 23:11:08 +03:00
Nikita Popov
e0a31cee32 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix freeing of dynamic call name
2019-12-18 10:11:40 +01:00
Nikita Popov
ee89e73312 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix freeing of dynamic call name
2019-12-18 10:11:23 +01:00
Nikita Popov
189f625e2b Fix freeing of dynamic call name
We need to free op2 if the call construction fails.

Also remove a redundant check for !call.
2019-12-18 10:11:09 +01:00
Nikita Popov
98527d7d4c Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78973
2019-12-16 18:53:32 +01:00
Nikita Popov
11b041d3c6 Fixed bug #78973
Save opline in leave helper to correctly handle destructor calls
during CV freeing (or other leave freeing).
2019-12-16 18:52:30 +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
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
0bac785477 Optimize return type checking
Split off the fast-path case and avoid redundant checks.
2019-12-06 14:17:03 +01:00
Tyson Andre
7901913b83 Speed up foreach/FE_FREE (optimize for arrays without gc)
In the case where there are still references to an array being iterated
over when the iterator is freed (or the array is not reference counted):

- There's need to save the opline.
- There's no need to check for exceptions.

```
// Before: 0.404 seconds
// After:  0.362 seconds
// loop_iter_empty(1000, 5000);
function loop_iter_empty(int $a, int $b) {
  $values = array_fill(0, $b, []);
  $total = 0;
  for ($i = 0; $i < $b; $i++) {
      foreach ($values as $v) {
          foreach ($v as $x) {
              $total += $x;
          }
      }
  }
  return $total;
}
```
2019-11-18 11:54:35 +03:00
Dmitry Stogov
8bf663d3b2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix $x = (bool)$x; for undefined with opcache
2019-11-18 11:29:38 +03:00
Dmitry Stogov
be6fb13873 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix $x = (bool)$x; for undefined with opcache
2019-11-18 11:27:43 +03:00
Dmitry Stogov
e72e3370c6 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix $x = (bool)$x; for undefined with opcache
2019-11-18 11:26:30 +03:00
Tyson Andre
a2c41c0ea6 Fix $x = (bool)$x; for undefined with opcache
And `$x = !$x`

Noticed while working on GH-4912

The included test would not emit undefined variable errors in php 8.0
with opcache enabled. The command used:

```
php -d zend_extension=opcache.so --no-php-ini -d error_reporting=E_ALL \
    -d opcache.file_cache= -d opcache.enable_cli=1  test.php
```
2019-11-18 11:24:03 +03:00
Tyson Andre
a7580899f3 Support the same handler for multiple opcodes 2019-11-15 17:37:01 +03:00
Tyson Andre
e8525c2f68 Optimize int === int/double === double
Do this by reusing the implementation used for `==`
when both arguments are ints (IS_LONG) or both are floats (IS_DOUBLE)

```php
// Before: nestedloop_ni took 0.442 seconds
// After: nestedloop_ni takes 0.401 seconds (same as nestedloop_ne)
function nestedloop_ni(int $k) {
  $x = 0;
  for ($i=0; $i < 50000000; $i++) {
    if ($i === $k) {
      $x++;
    }
  }
  print "$x\n";
}
function nestedloop_ne(int $k) {
  $x = 0;
  for ($i=0; $i < 50000000; $i++) {
    if ($i == $k) {
        $x++;
    }
  }
  print "$x\n";
}
```
2019-11-15 17:37:01 +03:00
Dmitry Stogov
36afe4e39e Optimize $x === null into is_null($x) 2019-11-12 13:49:55 +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
c46b2ed677 Remove support for array_key_exists() with objects 2019-11-04 13:10:03 +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
c858d17f06 Optimize instanceof_function
Split out the simple equality check into an inline function --
this is one of the common cases.

Replace instanceof_function_ex with zend_class_implements_interface.
There are a few more places where it may be used.
2019-10-25 10:51:17 +02:00
Nikita Popov
1ab489e99a Merge branch 'PHP-7.4' 2019-10-10 11:42:05 +02:00
Nikita Popov
b02cf8b66e Merge branch 'PHP-7.3' into PHP-7.4 2019-10-10 11:41:51 +02:00
Nikita Popov
4ba8d78100 Merge branch 'PHP-7.2' into PHP-7.3 2019-10-10 11:41:29 +02:00
Nikita Popov
96c84b7bc1 Fix leak on static method call on non-existent class 2019-10-10 11:40:49 +02:00
Nikita Popov
b093abcde3 Fix exception handling for call_user_func_array() with invalid type
Now that this throws an exception, the call frame cleanup will be
handled by exception handling -- remove it here to avoid double
frees.
2019-10-10 09:55:19 +02:00
Nikita Popov
9c9a833f9c Actually remove the YIELD key specialization
I only adjusted the code before, without switching to TMPVAR.
2019-10-09 14:11:07 +02:00
Nikita Popov
165a065a12 Reduce YIELD key specialization
Keeping the value specialization for now, which is more commonly
applicable.
2019-10-09 13:59:07 +02:00
Nikita Popov
da3b245715 Reduce YIELD_FROM specialization
Generator delegation is a complex compound operation, it does not
make a lot of sense to optimize refcounting here to this degree.
2019-10-09 13:53:07 +02:00
Nikita Popov
2aba10be4a Reduce ZEND_THROW specialization
Throwing is very expensive due to the need of gathering the backtrace,
so it makes little sense to optimize refcounting to this degree.
2019-10-09 13:17:25 +02: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
7c1bc91e52 Merge branch 'PHP-7.4' 2019-10-08 17:19:52 +02:00
Nikita Popov
21148679d1 Handle "non well formed" exception during ZPP
Previously if the "non well formed" notice was converted into an
exception we'd still end up executing the function.

Also drop the now unnecessary EG(exception) checks in the engine.

Additionally remote a bogus exception in zend_is_callable: It
should only be writing to error, but not directly throwing.
2019-10-08 17:17:49 +02:00
Dmitry Stogov
eec04f6b56 Encapsulate all SMART BRANCH related logic inside macros. Result of SMART BRANCH may be uninitialized (on exception). 2019-10-08 16:37:21 +03:00
Dmitry Stogov
b02b81299c Comparison cleanup:
- introduce zend_compare() that returns -1,0,1 dirctly (without intermediate zval)
- remove compare_objects() object handler, and keep only compare() handler
2019-10-07 17:57:49 +03:00