-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Convert iterable into an internal alias for Traversable|array #7309
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
Looks basically okay -- one thing I'm unsure about is whether we need to try to convert this back to |
A problem here is that existing arginfo for internal functions may have MAY_BE_ITERABLE, in which case it's going to misbehave now. We'd have to either adjust that when registering internal functions, or require arginfo to be updated to not use iterable (in which case we should drop/rename MAY_BE_ITERABLE to cause a build failure). |
605a695
to
a70db6b
Compare
a70db6b
to
e2ad89c
Compare
@Girgias For gen_stub.php, you'll need something along the lines of:
This patch only deals with |
Well, I think I've got something which works, but not sure, might want to build a test suite for it. |
@nikic I'm wondering if it still makes sense to make Reflection behave properly with The fallback for internal functions using it still makes sense though, at least in the short term, but in any cases both things should be documented in their respective UPGRADING docs. |
e17d3a7
to
d9db3e0
Compare
d9db3e0
to
219908d
Compare
Looks good to me as well |
Zend/zend_compile.c
Outdated
@@ -1189,22 +1189,40 @@ static zend_string *resolve_class_name(zend_string *name, zend_class_entry *scop | |||
|
|||
zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scope) { | |||
zend_string *str = NULL; | |||
uint32_t type_mask = ZEND_TYPE_PURE_MASK(type); |
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.
Something here does not seem to work when iterable
appears first in the union.
function test(): iterable|Foo {}
test();
Fatal error: Uncaught TypeError: test(): Return value must be of type Traversable|Foo|array, none returned
The type representation looks like this:
zend_type
mask: 5505152 (ZEND_TYPE_LIST_BIT | _ZEND_TYPE_UNION_BIT | MAY_BE_ARRAY)
ptr:
zend_type_list (2):
zend_type:
mask: 16777216 (_ZEND_TYPE_NAME_BIT)
ptr: Traversable
zend_type:
mask: 16777216 (_ZEND_TYPE_NAME_BIT)
ptr: Foo
Whereas Foo|iterable
looks like this:
zend_type
mask: 5505152 (ZEND_TYPE_LIST_BIT | _ZEND_TYPE_UNION_BIT | MAY_BE_ARRAY)
ptr:
zend_type_list (2):
zend_type:
mask: 16777216 (_ZEND_TYPE_NAME_BIT)
ptr: Foo
zend_type:
mask: 19136512 (_ZEND_TYPE_NAME_BIT | _ZEND_TYPE_UNION_BIT | _ZEND_TYPE_INTERSECTION_BIT)
ptr: Traversable
So it looks like the _ZEND_TYPE_ITERABLE_BIT
flag is lost. The second one looks fishy too, as the Traversable
type has the _ZEND_TYPE_UNION_BIT
set when it's not really a union. It's unclear (to me) whether the _ZEND_TYPE_ITERABLE_BIT
should be set on the root type.
I wonder if trying to maintain BC is worthwhile at all. For type aliases, I was planning to replace the types at runtime which would also result in the resolved types when printing them. If iterable
could be made a type alias at some point the behavior would change again.
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 really don't know if it is worthwile as I didn't bother with it initially, maybe it is better to just have compatibility for Reflection when it is only iterable
(or ?iterable
) ?
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.
@Girgias IMO it should work for all cases or we should drop it altogether.
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'll go back then to how it was initially, as I would think code running for 8.2 would be adapted to handle union types, but that will need to be put in the migration guide anyway.
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.
@Girgias Maybe keep the code around, just in case we'll need the BC solution anyway. I think with a BC break this will be a bit more questionable and should at least be mentioned on the mailing list.
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'll email internals then
ca4a14d
to
1ac37d9
Compare
d217311
to
b7a616f
Compare
I would like to merge within a week. |
This segfaults and I don't know why
Clarify comment Remove unnecessary variable Use ZEND_TYPE_INIT_CLASS_CONST_MASK in zend_compile.c
Follow-up from #7309 as I didn't change the ZPP TypeError wording.
There is probably some more clean-up which can be done in
zend_execute.c
/JIT/OpCache from the handling ofiterable
, but I am wondering if this the correct way of approaching this.