Commit Graph

264 Commits

Author SHA1 Message Date
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
Dmitry Stogov
83c2e6787d Merge branch 'PHP-7.4'
* PHP-7.4:
  Prevent useless hash lookups
  Update NEWS for 7.4.0alpha3
  Update NEWS for PHP 7.4.0alpha2
2019-06-25 12:42:36 +03:00
Dmitry Stogov
bd0cb99d8c Prevent useless hash lookups 2019-06-25 12:41:06 +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
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
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
e06ec226bc Merge branch 'PHP-7.4' 2019-05-24 09:33:58 +02:00
Nikita Popov
49a3b03e9f Implement basic variance support
This is a minimal variance implementation: It does not support any
cyclic type dependencies. Additionally the preloading requirements
are much more restrictive than necessary. Hopefully we can relax
these in the future.
2019-05-24 09:30:37 +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
Nikita Popov
c3ee12e786 Merge branch 'PHP-7.4' 2019-05-23 10:41:27 +02:00
Nikita Popov
64918c7702 Forbid use of not fully linked classes 2019-05-23 10:41:10 +02:00
Nikita Popov
6ada4db002 Merge branch 'PHP-7.4' 2019-05-08 12:13:11 +02:00
Nikita Popov
f778e1a0b2 Refactor inheritance type check implementation
Extract the self/parent name resolution code and drop unnecessary
string copies/releases. Store the fe/proto types in local variables.
2019-05-08 12:13:06 +02:00
Nikita Popov
11655d0974 Merge branch 'PHP-7.4' 2019-05-08 11:51:50 +02:00