Commit Graph

283 Commits

Author SHA1 Message Date
Nikita Popov
d5dd46fb09 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix copying of functions in variance obligations
2020-01-30 11:56:36 +01:00
Nikita Popov
68596ed71e Fix copying of functions in variance obligations
Only copy sizeof(zend_internal_function) for internal functions.
2020-01-30 11:55:38 +01:00
Nikita Popov
3bae1793ab Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78989
2020-01-28 10:44:37 +01:00
Nikita Popov
1146bdb9b2 Fixed bug #78989
Always operate on copies of the functions, so we don't reference
temporary trait methods that have gone out of scope.

This could be more efficient, but doing an allocated copy only when
strictly necessary turned out to be somewhat tricky.
2020-01-28 10:43:15 +01:00
Nikita Popov
e72bf63691 Allow variadic arguments to replace non-variadic ones
Any number of arguments can be replaced by a variadic one, so
long as the variadic argument is compatible (in the sense of
contravariance) with the subsumed arguments.

In particular this means that function(...$args) becomes a
near-universal signature: It is compatible with any function
signature that does not accept parameters by-reference.

This also fixes bug #70839, which describes a special case.

Closes GH-5059.
2020-01-23 15:23:31 +01:00
Nikita Popov
a3e29ba34a Prefer using declaring class rather than direct parent in error
Point to the class that actually declares the property, which is
not necessarily the same as the direct parent class.
2020-01-21 17:19:07 +01:00
Máté Kocsis
99db00b1f2
Fix #78880 Another round 2020-01-19 18:28:43 +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
655d5c8383 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78776
2019-12-18 15:56:10 +01:00
Nikita Popov
4a61d842e7 Fixed bug #78776
By using the normal inheritance check if the parent is abstract
as well.
2019-12-18 15:55:45 +01:00
Nikita Popov
33e39f088a Merge branch 'PHP-7.4'
* PHP-7.4:
  Use unmangled named in property type inheritance error
2019-12-09 08:49:42 +01:00
Nikita Popov
5fcc12f505 Use unmangled named in property type inheritance error 2019-12-09 08:48:33 +01:00
Nikita Popov
a6832caac9 Fix incorrect assertion in property type variance check
Only one of the status has to be UNRESOLVED, the other could also
be SUCCESS.

Fixes oss-fuzz #19108 and oss-fuzz #19111.
2019-12-04 11:07:22 +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
Nikita Popov
e63a44dd03 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #78226: Don't call __set() on uninitialized typed properties
2019-10-25 16:32:14 +02:00
Nikita Popov
f1848a4b3f Fix bug #78226: Don't call __set() on uninitialized typed properties
Assigning to an uninitialized typed property will no longer trigger
a call to __set(). However, calls to __set() are still triggered if
the property is explicitly unset().

This gives us both the behavior people generally expect, and still
allows ORMs to do lazy initialization by unsetting properties.

For PHP 8, we should fine a way to forbid unsetting of declared
properties entirely, and provide a different way to achieve lazy
initialization.
2019-10-25 16:31:45 +02:00
Nikita Popov
296269cfe8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove recursive check from instanceof_interface
2019-10-25 10:20:19 +02:00
Nikita Popov
184ba0c91c Remove recursive check from instanceof_interface
Parent interfaces are copied into the interface list during
inheritance, so there's no need to perform a recursive check.

Only exception are instanceof checks performed during inheritance
itself. However, we already have unlinked_instanceof for this
purpose, it just needs to be taught to handle this case.

Closes GH-4857.
2019-10-25 10:19:42 +02:00
Nikita Popov
9a634a9c6b Merge branch 'PHP-7.4'
* PHP-7.4:
  Integrate property types with variance system
2019-10-17 13:42:47 +02:00
Nikita Popov
cf85eb2468 Integrate property types with variance system
Property types are invariant, but may still have to load classes in
order to check for class aliases. This class loading should follow
the same rules as all other variance checks, rather than just
loading unconditionally.

This change integrates property type invariance checks into the
variance system as a new obligation type, and prevent early binding
if the type check cannot be performed.
2019-10-17 13:37:04 +02:00
Nikita Popov
edace5f5e0 Merge branch 'PHP-7.4' 2019-10-01 13:05:12 +02:00
Nikita Popov
f2e8851245 Remove func copy optimization for private method with static vars
Not NULLing the static_variables pointer for shadow methods during
static var shutdown would be a way to avoid this leak, but unless
there's evidence that inherited private methods with static vars are
actually a common use-case, I don't think we should keep this kind
of fragile edge-case optimization.

Fixes OSS-Fuzz #17875.
2019-10-01 13:04:06 +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
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
a97645eb0a Merge branch 'PHP-7.4' 2019-09-11 16:51:30 +02:00
Nikita Popov
fbe287a677 Fix typo in unlinked_instanceof assertion 2019-09-11 16:50:16 +02:00
Nikita Popov
403396e42c Merge branch 'PHP-7.4' 2019-09-11 16:30:59 +02:00
Nikita Popov
270e5e3c5b Only allow "nearly linked" classes for parent/interface
The requirements for parent/interface are difference than for the
variance checks in type declarations. The latter can work on fully
unlinked classes, but the former need inheritance to be essentially
finished, only variance checks may still be outstanding.

Adding a new flag for this because we have lots of space, but we
could also represent these "inheritance states" more compactly in
the future.
2019-09-11 16:27:28 +02:00
Nikita Popov
3da3b4c8f8 Merge branch 'PHP-7.4' 2019-08-29 14:47:30 +02:00
Nikita Popov
6cc53981e5 Addref static vars when not copying private method
While we don't need to give this method separate static vars, we
do still need to perform an addref, as there will be a corresponding
delref in the dtor.
2019-08-29 14:47:09 +02:00
Dmitry Stogov
c45931f69b Merge branch 'PHP-7.4'
* PHP-7.4:
  Separate common code abd eliminate useless checks
2019-06-27 13:11:37 +03:00
Dmitry Stogov
e7446c1b2d Separate common code abd eliminate useless checks 2019-06-27 13:11:08 +03:00
Dmitry Stogov
31670211e2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Inline hot path
2019-06-27 11:28:14 +03:00
Dmitry Stogov
a58964be82 Inline hot path 2019-06-27 11:27:53 +03: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
8dac19278e Merge branch 'PHP-7.4'
* PHP-7.4:
  Private methods don't have to be duplicated
2019-06-26 13:27:41 +03:00
Dmitry Stogov
36b7021e2c Private methods don't have to be duplicated 2019-06-26 13:27:13 +03:00
Dmitry Stogov
db97bbc0c5 Merge branch 'PHP-7.4'
* PHP-7.4:
  Reorder conditions to minimize number of checks on fast path
2019-06-26 01:08:43 +03:00
Dmitry Stogov
f7faa62c43 Reorder conditions to minimize number of checks on fast path 2019-06-26 01:00:31 +03:00
Dmitry Stogov
0c932e0aff Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove always true/false conditions, remove dead conde and simplify code.
2019-06-26 00:44:10 +03:00
Dmitry Stogov
6288fc19dd Remove always true/false conditions, remove dead conde and simplify code. 2019-06-26 00:32:22 +03:00
Dmitry Stogov
5ce26b4895 Merge branch 'PHP-7.4'
* PHP-7.4:
  Replace previosly checked conditions by ZEND_ASSERT()
2019-06-25 18:27:30 +03:00
Dmitry Stogov
215b5a7db8 Replace previosly checked conditions by ZEND_ASSERT() 2019-06-25 18:26:56 +03:00
Dmitry Stogov
7dc4dd4d7c Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed variance check for abstract constructor during erlay binding
2019-06-25 17:44:49 +03:00
Dmitry Stogov
f09d41ffc0 Fixed variance check for abstract constructor during erlay binding 2019-06-25 17:43:46 +03:00
Dmitry Stogov
c6ce159384 Merge branch 'PHP-7.4'
* PHP-7.4:
  Cleanup
2019-06-25 16:53:46 +03:00
Dmitry Stogov
ccbc121cb1 Cleanup 2019-06-25 16:37:42 +03:00