-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Switch zend_type to use MAY_BE_* mask #4727
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
So that we can place all type hints in a MAY_BE union.
|
||
#define ZEND_TYPE_ENCODE_CODE(code, allow_null) \ | ||
(((code) == _IS_BOOL ? (MAY_BE_FALSE|MAY_BE_TRUE) : (1 << (code))) \ | ||
| ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : Z_L(0x0))) |
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 would keep the old prototype and meaning for ZEND_TYPE_ENCODE() and introduce ZEND_TYPE_ENCODE_MASK().
zend_op *opline; | ||
|
||
/* `return ...;` is illegal in a void function (but `return;` isn't) */ | ||
if (ZEND_TYPE_CODE(return_info->type) == IS_VOID) { | ||
if (ZEND_TYPE_IS_CODE(type) && ZEND_TYPE_CONTAINS_CODE(type, IS_VOID)) { |
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 think, it doesn't make sense to unite "void" with anything else.
This check may be simplified to (ZEND_TYPE_MASK(type) == MAY_BE_VOID).
| EXT_CALL zend_missing_arg_error, r0 | ||
| jmp ->exception_handler | ||
|.code | ||
|
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.
Was this chunk improperly placed before?
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.@dstogov Can you please take a look at this?