Skip to content

Commit 94599a6

Browse files
committed
Support resolving arg/return intersection types in the JIT
1 parent 19724b4 commit 94599a6

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,29 +1345,58 @@ static zend_always_inline bool zend_jit_verify_type_common(zval *arg, zend_arg_i
13451345
zend_class_entry *ce;
13461346
if (ZEND_TYPE_HAS_LIST(arg_info->type)) {
13471347
zend_type *list_type;
1348-
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(arg_info->type), list_type) {
1349-
if (*cache_slot) {
1350-
ce = *cache_slot;
1351-
} else if (ZEND_TYPE_HAS_CE_CACHE(*list_type) && ZEND_TYPE_CE_CACHE(*list_type)) {
1352-
ce = ZEND_TYPE_CE_CACHE(*list_type);
1353-
*cache_slot = ce;
1354-
} else {
1355-
ce = zend_fetch_class(ZEND_TYPE_NAME(*list_type),
1356-
ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT);
1357-
if (!ce) {
1358-
cache_slot++;
1359-
continue;
1348+
if (ZEND_TYPE_HAS_INTERSECTION(arg_info->type)) {
1349+
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(arg_info->type), list_type) {
1350+
/* Fetch class_entry */
1351+
if (*cache_slot) {
1352+
ce = *cache_slot;
1353+
} else if (ZEND_TYPE_HAS_CE_CACHE(*list_type) && ZEND_TYPE_CE_CACHE(*list_type)) {
1354+
ce = ZEND_TYPE_CE_CACHE(*list_type);
1355+
*cache_slot = ce;
1356+
} else {
1357+
ce = zend_fetch_class(ZEND_TYPE_NAME(*list_type),
1358+
ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT);
1359+
if (!ce) {
1360+
/* Cannot resolve */
1361+
return false;
1362+
}
1363+
*cache_slot = ce;
1364+
if (ZEND_TYPE_HAS_CE_CACHE(*list_type)) {
1365+
ZEND_TYPE_SET_CE_CACHE(*list_type, ce);
1366+
}
13601367
}
1361-
*cache_slot = ce;
1362-
if (ZEND_TYPE_HAS_CE_CACHE(*list_type)) {
1363-
ZEND_TYPE_SET_CE_CACHE(*list_type, ce);
1368+
1369+
if (!instanceof_function(Z_OBJCE_P(arg), ce)) {
1370+
return false;
13641371
}
1365-
}
1366-
if (instanceof_function(Z_OBJCE_P(arg), ce)) {
1367-
return 1;
1368-
}
1369-
cache_slot++;
1370-
} ZEND_TYPE_LIST_FOREACH_END();
1372+
cache_slot++;
1373+
} ZEND_TYPE_LIST_FOREACH_END();
1374+
return true;
1375+
} else {
1376+
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(arg_info->type), list_type) {
1377+
if (*cache_slot) {
1378+
ce = *cache_slot;
1379+
} else if (ZEND_TYPE_HAS_CE_CACHE(*list_type) && ZEND_TYPE_CE_CACHE(*list_type)) {
1380+
ce = ZEND_TYPE_CE_CACHE(*list_type);
1381+
*cache_slot = ce;
1382+
} else {
1383+
ce = zend_fetch_class(ZEND_TYPE_NAME(*list_type),
1384+
ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT);
1385+
if (!ce) {
1386+
cache_slot++;
1387+
continue;
1388+
}
1389+
*cache_slot = ce;
1390+
if (ZEND_TYPE_HAS_CE_CACHE(*list_type)) {
1391+
ZEND_TYPE_SET_CE_CACHE(*list_type, ce);
1392+
}
1393+
}
1394+
if (instanceof_function(Z_OBJCE_P(arg), ce)) {
1395+
return 1;
1396+
}
1397+
cache_slot++;
1398+
} ZEND_TYPE_LIST_FOREACH_END();
1399+
}
13711400
} else {
13721401
if (EXPECTED(*cache_slot)) {
13731402
ce = (zend_class_entry *) *cache_slot;

0 commit comments

Comments
 (0)