-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve ZEND_NEW RC inference #13239
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
That's only true for create_object == NULL and the handler being zend_std_get_constructor, I think. For anything else we cannot do such guarantees (extension code...). |
@bwoebi I forgot about It's worth noting that we already make some assumptions here. E.g. we're assuming that assigning to a declared, untyped property does not throw, even though an overwritten php-src/Zend/Optimizer/zend_inference.c Lines 5092 to 5093 in e2c3c48
|
I think it should be good enough to check default_object_handlers. Yes, at runtime it may change theoretically, but at that point I think it should be the extensions responsibility to be a good citizen and either notify at minit-time by changing these. But be aware that this is Optimizer code of which one does not necessarily see the effects when developing extensions... |
:-/ I think that's not a great check. I just checked the code of the extension I maintain (dd-trace-php), we do throw on < PHP 8 in the write handler to emulate a readonly. We don't do further validity checks in our code, but as long as we don't have proper virtual properties, I guess extensions will use it to validate. |
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.
I don't object. Just select a good enough condition.
Does this cause any improvements in the JIT generated code?
e788202
to
e3d7c69
Compare
ZEND_NEW returns RC1 if the instanciated class has no constructor.
e3d7c69
to
e7f4860
Compare
if (ce | ||
&& !ce->constructor | ||
&& !ce->create_object | ||
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor) { |
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.
The last line is not necessary. If create_object
is NULL then ce->default_object_handlers->get_constructor == zend_std_get_constructor
is true.
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.
As discussed in the other issue, the default handlers may be changed without specifying create_object
. create_object
may still be used to swap the handlers. Support for this could be dropped in the future, essentially making zend_object->handlers
and implementation detail, i.e. a cached pointer to object->ce->default_object_handlers
to avoid a pointer indirection.
ZEND_NEW returns RC1 if the instanciated class has no constructor.