-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Full variance support if autoloading is used #4194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@dstogov This is my implementation for full variance support with autoloading. It's similar to one of the possibilities we discussed, where we keep track of outstanding obligations and check them later. This approach should be easy to extend to the non-autoloaded case (if we want to do so). Basically we would have to increment the linking depth before declaring a "group" of classes and then decrementing afterward. |
23f6e36
to
fce9d3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, the behavior implemented by PR is not consistent.
There are possible situation when class can't be used after declaration, because of delayed variance checks.
It looks like, implementation of full variance support in PHP is not possible at all.
I would prefer not to merge inconsistent solutions, and keep only "minimal" variance support (that is restricted by simple rule - parameter classes, that need to be checked, have to be available during class linking).
zend_class_entry *ce = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname + 1)); | ||
zend_class_entry *parent_ce = zend_lookup_class_ex(Z_STR_P(parent_name), Z_STR_P(parent_name + 1), 0); | ||
zend_class_entry *parent_ce = zend_lookup_class(ce->parent_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require extra strtolower() call at run-time.
We want the class declaration to be available while compiling the parent class.
Keep track of delayed variance obligations and enforce them when class linking depth reaches zero.
fce9d3a
to
8be567c
Compare
No longer necessary
This reduces the amount of unnecessary diff to current implementation.
And drop class_order_autoload6 as no longer necessary.
@dstogov I have now implemented a new version that hopefully resolves the issues we discussed. The core approach is the same as before, with a few differences:
One very important conceptual difference is that we do not require the classes used in typehints to be fully linked in order to link a class -- we do ensure that they have correct variance, but don't require full linking. For example, the following example works as expected:
In particular the use |
Instead do an explicit recursive resolution of obligations for dependency classes.
We already looked up the obligations HT at that point, it seems potentially dangerous.
It would be a good bit more convenient if we could have |
This implementation looks better, but personally, I don't see value for this implementation complication. I also see ~5% slowdown on ZendFramework benchmark, that just loads most of the ZF classes (this is expected). |
The first commit moves the loading of the parent class into zend_do_link_class as preparation. The second commit has the main functionality, which works as follows: