Skip to content

Commit 643c4ba

Browse files
committedSep 29, 2023
Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
Although it passes CI on 8.1, it causes CI failures in the JIT on 8.2 and higher. See https://github.com/php/php-src/actions/runs/6357716718/job/17269225001 This reverts commit e72fc12.
1 parent e72fc12 commit 643c4ba

File tree

3 files changed

+9
-53
lines changed

3 files changed

+9
-53
lines changed
 

‎NEWS

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ PHP NEWS
88
. Fixed bug GH-12215 (Module entry being overwritten causes type errors in
99
ext/dom). (nielsdos)
1010
. Fixed bug GH-12273 (__builtin_cpu_init check). (Freaky)
11-
. Fixed bug GH-10008 (Narrowing occurred during type inference of
12-
ZEND_ADD_ARRAY_ELEMENT). (nielsdos, arnaud-lb)
1311

1412
- CType:
1513
. Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater).

‎Zend/Optimizer/zend_inference.c

+9-21
Original file line numberDiff line numberDiff line change
@@ -1926,21 +1926,6 @@ ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int w
19261926
return tmp;
19271927
}
19281928

1929-
static zend_always_inline uint32_t assign_long_dim_array_result_type(uint32_t arr_type)
1930-
{
1931-
/* Rules:
1932-
* HASH_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH
1933-
* PACKED_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
1934-
* HASH || PACKED -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
1935-
* 0 -> MAY_BE_ARRAY_NUMERIC_HASH
1936-
*/
1937-
if (MAY_BE_PACKED(arr_type)) {
1938-
return MAY_BE_ARRAY_KEY_LONG;
1939-
} else {
1940-
return MAY_BE_ARRAY_NUMERIC_HASH;
1941-
}
1942-
}
1943-
19441929
static uint32_t assign_dim_array_result_type(
19451930
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, zend_uchar dim_op_type) {
19461931
uint32_t tmp = 0;
@@ -1954,13 +1939,13 @@ static uint32_t assign_dim_array_result_type(
19541939
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19551940
tmp |= MAY_BE_ARRAY_PACKED;
19561941
}
1957-
tmp |= assign_long_dim_array_result_type(arr_type);
1942+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19581943
} else {
19591944
if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
19601945
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19611946
tmp |= MAY_BE_ARRAY_PACKED;
19621947
}
1963-
tmp |= assign_long_dim_array_result_type(arr_type);
1948+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19641949
}
19651950
if (dim_type & MAY_BE_STRING) {
19661951
tmp |= MAY_BE_ARRAY_KEY_STRING;
@@ -1969,7 +1954,7 @@ static uint32_t assign_dim_array_result_type(
19691954
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19701955
tmp |= MAY_BE_ARRAY_PACKED;
19711956
}
1972-
tmp |= assign_long_dim_array_result_type(arr_type);
1957+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19731958
}
19741959
}
19751960
if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) {
@@ -3269,15 +3254,17 @@ static zend_always_inline int _zend_update_type_info(
32693254
key_type |= MAY_BE_ARRAY_PACKED;
32703255
}
32713256
if (t1 & MAY_BE_ARRAY) {
3272-
key_type |= assign_long_dim_array_result_type(t1);
3257+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3258+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
32733259
}
32743260
} else {
32753261
if (t2 & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
32763262
if (t1 & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
32773263
key_type |= MAY_BE_ARRAY_PACKED;
32783264
}
32793265
if (t1 & MAY_BE_ARRAY) {
3280-
key_type |= assign_long_dim_array_result_type(t1);
3266+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3267+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
32813268
}
32823269
}
32833270
if (t2 & MAY_BE_STRING) {
@@ -3288,7 +3275,8 @@ static zend_always_inline int _zend_update_type_info(
32883275
key_type |= MAY_BE_ARRAY_PACKED;
32893276
}
32903277
if (t1 & MAY_BE_ARRAY) {
3291-
key_type |= assign_long_dim_array_result_type(t1);
3278+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3279+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
32923280
}
32933281
}
32943282
}

‎ext/opcache/tests/opt/gh10008.phpt

-30
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.