Skip to content

Commit 5044285

Browse files
committed
Use unused type bit for flagging iterable
1 parent e1a02fc commit 5044285

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6177,8 +6177,8 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
61776177
zend_type iterable = (zend_type) ZEND_TYPE_INIT_CLASS(ZSTR_KNOWN(ZEND_STR_TRAVERSABLE), 0, 0);
61786178
ZEND_TYPE_FULL_MASK(iterable) |= _ZEND_TYPE_NAME_BIT;
61796179
ZEND_TYPE_FULL_MASK(iterable) |= MAY_BE_ARRAY;
6180-
/* Set MAY_BE_ITERABLE for BC compat during Reflection */
6181-
ZEND_TYPE_FULL_MASK(iterable) |= MAY_BE_ITERABLE;
6180+
/* Set iterable bit for BC compat during Reflection */
6181+
ZEND_TYPE_FULL_MASK(iterable) |= _ZEND_TYPE_ITERABLE_BIT;
61826182
/* Inform that the type list is a union type */
61836183
ZEND_TYPE_FULL_MASK(iterable) |= _ZEND_TYPE_UNION_BIT;
61846184
return iterable;

Zend/zend_inheritance.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ static inheritance_status zend_perform_covariant_type_check(
540540
/* Builtin types may be removed, but not added */
541541
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK(fe_type);
542542
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);
543-
/* MAY_BE_ITERABLE is only used for BC with Reflection so remove it */
544-
uint32_t added_types = fe_type_mask & ~proto_type_mask & ~MAY_BE_ITERABLE;
543+
uint32_t added_types = fe_type_mask & ~proto_type_mask;
545544
if (added_types) {
546545
if ((added_types & MAY_BE_STATIC)
547546
&& zend_type_permits_self(proto_type, proto_scope, fe_scope)) {

Zend/zend_type_info.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
/* These are used in zend_type, but not for type inference.
3939
* They are allowed to overlap with types used during inference. */
4040
#define MAY_BE_CALLABLE (1 << IS_CALLABLE)
41-
/* Kept as BC for reflection */
42-
#define MAY_BE_ITERABLE (1 << IS_ITERABLE)
4341
#define MAY_BE_VOID (1 << IS_VOID)
4442
#define MAY_BE_NEVER (1 << IS_NEVER)
4543
#define MAY_BE_STATIC (1 << IS_STATIC)

Zend/zend_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ typedef struct {
144144
#define _ZEND_TYPE_NAME_BIT (1u << 24)
145145
#define _ZEND_TYPE_LIST_BIT (1u << 22)
146146
#define _ZEND_TYPE_KIND_MASK (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_NAME_BIT)
147-
/* TODO: bit 21 is not used */
147+
#define _ZEND_TYPE_ITERABLE_BIT (1u << 21)
148148
/* Whether the type list is arena allocated */
149149
#define _ZEND_TYPE_ARENA_BIT (1u << 20)
150150
/* Whether the type list is an intersection type */
@@ -170,6 +170,9 @@ typedef struct {
170170
#define ZEND_TYPE_HAS_LIST(t) \
171171
((((t).type_mask) & _ZEND_TYPE_LIST_BIT) != 0)
172172

173+
#define ZEND_TYPE_IS_ITERABLE_FALLBACK(t) \
174+
((((t).type_mask) & _ZEND_TYPE_ITERABLE_BIT) != 0)
175+
173176
#define ZEND_TYPE_IS_INTERSECTION(t) \
174177
((((t).type_mask) & _ZEND_TYPE_INTERSECTION_BIT) != 0)
175178

ext/reflection/php_reflection.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ static reflection_type_kind get_type_kind(zend_type type) {
13301330

13311331
if (ZEND_TYPE_IS_COMPLEX(type)) {
13321332
/* BC support for 'iterable' type */
1333-
if (type_mask_without_null == (MAY_BE_ARRAY|MAY_BE_ITERABLE)) {
1333+
if (UNEXPECTED(ZEND_TYPE_IS_ITERABLE_FALLBACK(type))) {
13341334
return NAMED_TYPE;
13351335
}
13361336
if (type_mask_without_null != 0) {
@@ -1361,10 +1361,6 @@ static void reflection_type_factory(zend_type type, zval *object, bool legacy_be
13611361
reflection_instantiate(reflection_intersection_type_ptr, object);
13621362
break;
13631363
case UNION_TYPE:
1364-
/* Clear fake iterable type */
1365-
if ((ZEND_TYPE_PURE_MASK(type) & MAY_BE_ITERABLE) != 0) {
1366-
ZEND_TYPE_FULL_MASK(type) &= ~MAY_BE_ITERABLE;
1367-
}
13681364
reflection_instantiate(reflection_union_type_ptr, object);
13691365
break;
13701366
case NAMED_TYPE:
@@ -2705,6 +2701,11 @@ ZEND_METHOD(ReflectionParameter, isArray)
27052701
}
27062702
GET_REFLECTION_OBJECT_PTR(param);
27072703

2704+
/* BC For iterable */
2705+
if (ZEND_TYPE_IS_ITERABLE_FALLBACK(param->arg_info->type)) {
2706+
RETURN_FALSE;
2707+
}
2708+
27082709
type_mask = ZEND_TYPE_PURE_MASK_WITHOUT_NULL(param->arg_info->type);
27092710
RETVAL_BOOL(type_mask == MAY_BE_ARRAY);
27102711
}
@@ -2987,7 +2988,7 @@ ZEND_METHOD(ReflectionType, allowsNull)
29872988

29882989
/* BC for iterable */
29892990
static zend_string *zend_type_to_string_ex(zend_type type) {
2990-
if (UNEXPECTED((ZEND_TYPE_PURE_MASK(type) & MAY_BE_ITERABLE) != 0)) {
2991+
if (UNEXPECTED(ZEND_TYPE_IS_ITERABLE_FALLBACK(type))) {
29912992
return ZSTR_KNOWN(ZEND_STR_ITERABLE);
29922993
}
29932994
return zend_type_to_string(type);
@@ -3090,9 +3091,6 @@ ZEND_METHOD(ReflectionUnionType, getTypes)
30903091
if (type_mask & MAY_BE_CALLABLE) {
30913092
append_type_mask(return_value, MAY_BE_CALLABLE);
30923093
}
3093-
if (type_mask & MAY_BE_ITERABLE) {
3094-
append_type_mask(return_value, MAY_BE_ITERABLE);
3095-
}
30963094
if (type_mask & MAY_BE_OBJECT) {
30973095
append_type_mask(return_value, MAY_BE_OBJECT);
30983096
}

ext/reflection/tests/union_types.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ Allows null: false
6969
Name: X
7070
String: X
7171
Allows Null: false
72-
Name: Traversable
73-
String: Traversable
72+
Name: iterable
73+
String: iterable
7474
Allows Null: false
7575
Name: array
7676
String: array

0 commit comments

Comments
 (0)