1818 +----------------------------------------------------------------------+
1919*/
2020
21+ #include "zend_portability.h"
2122#include "zend_types.h"
2223#define ZEND_INTENSIVE_DEBUGGING 0
2324
@@ -1098,7 +1099,7 @@ static zend_never_inline bool check_property_type_generic(
10981099}
10991100#endif
11001101
1101- static zend_type zend_resolve_generic_type (zend_class_reference * scope , uint32_t param_id ) {
1102+ static zend_always_inline zend_type zend_resolve_generic_type (zend_class_reference * scope , uint32_t param_id ) {
11021103 if (param_id >= scope -> ce -> num_bound_generic_args ) {
11031104 ZEND_ASSERT (param_id - scope -> ce -> num_bound_generic_args < scope -> args .num_types );
11041105 return scope -> args .types [param_id - scope -> ce -> num_bound_generic_args ];
@@ -1222,6 +1223,10 @@ static zend_always_inline bool zend_validate_generic_args(
12221223# define HAVE_CACHE_SLOT 1
12231224#endif
12241225
1226+ // TODO: cache_slot may not be worth it since ZSTR_CE_CACHE
1227+ #undef HAVE_CACHE_SLOT
1228+ #define HAVE_CACHE_SLOT 0
1229+
12251230#define PROGRESS_CACHE_SLOT () if (HAVE_CACHE_SLOT) {cache_slot++;}
12261231
12271232static zend_always_inline zend_class_entry * zend_fetch_ce_from_cache_slot (
@@ -1305,6 +1310,11 @@ static bool zend_check_intersection_type_from_cache_slot(zend_type_list *interse
13051310 return status ;
13061311}
13071312
1313+ // TODO
1314+ static bool zend_check_type_slow_recursive (
1315+ zend_type * type , zval * arg , zend_reference * ref , void * * cache_slot ,
1316+ zend_class_entry * scope , bool is_return_type , bool is_internal );
1317+
13081318static zend_always_inline bool zend_check_type_slow (
13091319 zend_type * type , zval * arg , zend_reference * ref , void * * cache_slot ,
13101320 zend_class_entry * scope , bool is_return_type , bool is_internal )
@@ -1342,8 +1352,14 @@ static zend_always_inline bool zend_check_type_slow(
13421352 if (ZEND_TYPE_CONTAINS_CODE (real_type , Z_TYPE_P (arg ))) {
13431353 return true;
13441354 }
1345- if (zend_check_type_slow (
1346- & real_type , arg , ref , /* cache_slot */ NULL , scope , is_return_type , is_internal )) {
1355+ if (ZEND_TYPE_HAS_PNR (real_type ) && Z_TYPE_P (arg ) == IS_OBJECT ) {
1356+ ce = zend_fetch_ce_from_cache_slot (cache_slot , & real_type );
1357+ if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1358+ return true;
1359+ }
1360+ }
1361+ if (zend_check_type_slow_recursive (
1362+ & real_type , arg , ref , cache_slot , scope , is_return_type , is_internal )) {
13471363 return true;
13481364 }
13491365 }
@@ -1368,7 +1384,13 @@ static zend_always_inline bool zend_check_type_slow(
13681384 if (ZEND_TYPE_CONTAINS_CODE (real_type , Z_TYPE_P (arg ))) {
13691385 return true;
13701386 }
1371- if (zend_check_type_slow (
1387+ if (ZEND_TYPE_HAS_PNR (real_type ) && Z_TYPE_P (arg ) == IS_OBJECT ) {
1388+ ce = zend_fetch_ce_from_cache_slot (cache_slot , & real_type );
1389+ if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1390+ return true;
1391+ }
1392+ }
1393+ if (zend_check_type_slow_recursive (
13721394 & real_type , arg , ref , /* cache_slot */ NULL , scope , is_return_type , is_internal )) {
13731395 return true;
13741396 }
@@ -1402,6 +1424,13 @@ static zend_always_inline bool zend_check_type_slow(
14021424 * because this case is already checked at compile-time. */
14031425}
14041426
1427+ static bool zend_check_type_slow_recursive (
1428+ zend_type * type , zval * arg , zend_reference * ref , void * * cache_slot ,
1429+ zend_class_entry * scope , bool is_return_type , bool is_internal )
1430+ {
1431+ return zend_check_type_slow (type , arg , ref , cache_slot , scope , is_return_type , is_internal );
1432+ }
1433+
14051434static zend_always_inline bool zend_check_type (
14061435 zend_type * type , zval * arg , void * * cache_slot , zend_class_entry * scope ,
14071436 bool is_return_type , bool is_internal )
0 commit comments