Skip to content

Commit 711255e

Browse files
committed
Use unused type bit for flagging iterable
1 parent 1a5d56a commit 711255e

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
@@ -6137,8 +6137,8 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
61376137
zend_type iterable = (zend_type) ZEND_TYPE_INIT_CLASS(ZSTR_KNOWN(ZEND_STR_TRAVERSABLE), 0, 0);
61386138
ZEND_TYPE_FULL_MASK(iterable) |= _ZEND_TYPE_NAME_BIT;
61396139
ZEND_TYPE_FULL_MASK(iterable) |= MAY_BE_ARRAY;
6140-
/* Set MAY_BE_ITERABLE for BC compat during Reflection */
6141-
ZEND_TYPE_FULL_MASK(iterable) |= MAY_BE_ITERABLE;
6140+
/* Set iterable bit for BC compat during Reflection */
6141+
ZEND_TYPE_FULL_MASK(iterable) |= _ZEND_TYPE_ITERABLE_BIT;
61426142
/* Inform that the type list is a union type */
61436143
ZEND_TYPE_FULL_MASK(iterable) |= _ZEND_TYPE_UNION_BIT;
61446144
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
@@ -1336,7 +1336,7 @@ static reflection_type_kind get_type_kind(zend_type type) {
13361336

13371337
if (ZEND_TYPE_IS_COMPLEX(type)) {
13381338
/* BC support for 'iterable' type */
1339-
if (type_mask_without_null == (MAY_BE_ARRAY|MAY_BE_ITERABLE)) {
1339+
if (UNEXPECTED(ZEND_TYPE_IS_ITERABLE_FALLBACK(type))) {
13401340
return NAMED_TYPE;
13411341
}
13421342
if (type_mask_without_null != 0) {
@@ -1367,10 +1367,6 @@ static void reflection_type_factory(zend_type type, zval *object, bool legacy_be
13671367
reflection_instantiate(reflection_intersection_type_ptr, object);
13681368
break;
13691369
case UNION_TYPE:
1370-
/* Clear fake iterable type */
1371-
if ((ZEND_TYPE_PURE_MASK(type) & MAY_BE_ITERABLE) != 0) {
1372-
ZEND_TYPE_FULL_MASK(type) &= ~MAY_BE_ITERABLE;
1373-
}
13741370
reflection_instantiate(reflection_union_type_ptr, object);
13751371
break;
13761372
case NAMED_TYPE:
@@ -2711,6 +2707,11 @@ ZEND_METHOD(ReflectionParameter, isArray)
27112707
}
27122708
GET_REFLECTION_OBJECT_PTR(param);
27132709

2710+
/* BC For iterable */
2711+
if (ZEND_TYPE_IS_ITERABLE_FALLBACK(param->arg_info->type)) {
2712+
RETURN_FALSE;
2713+
}
2714+
27142715
type_mask = ZEND_TYPE_PURE_MASK_WITHOUT_NULL(param->arg_info->type);
27152716
RETVAL_BOOL(type_mask == MAY_BE_ARRAY);
27162717
}
@@ -2993,7 +2994,7 @@ ZEND_METHOD(ReflectionType, allowsNull)
29932994

29942995
/* BC for iterable */
29952996
static zend_string *zend_type_to_string_ex(zend_type type) {
2996-
if (UNEXPECTED((ZEND_TYPE_PURE_MASK(type) & MAY_BE_ITERABLE) != 0)) {
2997+
if (UNEXPECTED(ZEND_TYPE_IS_ITERABLE_FALLBACK(type))) {
29972998
return ZSTR_KNOWN(ZEND_STR_ITERABLE);
29982999
}
29993000
return zend_type_to_string(type);
@@ -3096,9 +3097,6 @@ ZEND_METHOD(ReflectionUnionType, getTypes)
30963097
if (type_mask & MAY_BE_CALLABLE) {
30973098
append_type_mask(return_value, MAY_BE_CALLABLE);
30983099
}
3099-
if (type_mask & MAY_BE_ITERABLE) {
3100-
append_type_mask(return_value, MAY_BE_ITERABLE);
3101-
}
31023100
if (type_mask & MAY_BE_OBJECT) {
31033101
append_type_mask(return_value, MAY_BE_OBJECT);
31043102
}

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)