Skip to content

Commit 70195c3

Browse files
committed
Don't force property type resolution for include preloading
Having all property types resolved is no longer a hard requirement for preloading, resolving the types is just an optimization. As such, drop the special logic that forced loading of property types when include-based preloading is used. Instead only keep the code that resolves types based on actually preloaded classes. Also drop the ZEND_ACC_PROPERTY_TYPES_RESOLVED flag, which is now nearly useless and takes up flag space...
1 parent 56ef117 commit 70195c3

File tree

4 files changed

+7
-52
lines changed

4 files changed

+7
-52
lines changed

Zend/zend.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,6 @@ static void zend_resolve_property_types(void) /* {{{ */
10501050
} ZEND_TYPE_FOREACH_END();
10511051
} ZEND_HASH_FOREACH_END();
10521052
}
1053-
ce->ce_flags |= ZEND_ACC_PROPERTY_TYPES_RESOLVED;
10541053
} ZEND_HASH_FOREACH_END();
10551054
}
10561055
/* }}} */

Zend/zend_compile.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ typedef struct _zend_oparray_context {
241241
/* or IS_CONSTANT_VISITED_MARK | | | */
242242
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
243243
/* | | | */
244-
/* Class Flags (unused: 30...) | | | */
244+
/* Class Flags (unused: 15,30,31) | | | */
245245
/* =========== | | | */
246246
/* | | | */
247247
/* Special class types | | | */
@@ -270,9 +270,6 @@ typedef struct _zend_oparray_context {
270270
/* User class has methods with static variables | | | */
271271
#define ZEND_HAS_STATIC_IN_METHODS (1 << 14) /* X | | | */
272272
/* | | | */
273-
/* Whether all property types are resolved to CEs | | | */
274-
#define ZEND_ACC_PROPERTY_TYPES_RESOLVED (1 << 15) /* X | | | */
275-
/* | | | */
276273
/* Children must reuse parent get_iterator() | | | */
277274
#define ZEND_ACC_REUSE_GET_ITERATOR (1 << 16) /* X | | | */
278275
/* | | | */

ext/opcache/ZendAccelerator.c

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,9 +3787,8 @@ static zend_class_entry *preload_fetch_resolved_ce(zend_string *name) {
37873787
return ce;
37883788
}
37893789

3790-
static bool preload_try_resolve_property_types(zend_class_entry *ce)
3790+
static void preload_try_resolve_property_types(zend_class_entry *ce)
37913791
{
3792-
bool ok = 1;
37933792
if (ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) {
37943793
zend_property_info *prop;
37953794
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) {
@@ -3798,20 +3797,13 @@ static bool preload_try_resolve_property_types(zend_class_entry *ce)
37983797
if (ZEND_TYPE_HAS_NAME(*single_type)) {
37993798
zend_class_entry *p =
38003799
preload_fetch_resolved_ce(ZEND_TYPE_NAME(*single_type));
3801-
if (!p) {
3802-
ok = 0;
3803-
continue;
3800+
if (p) {
3801+
ZEND_TYPE_SET_CE(*single_type, p);
38043802
}
3805-
ZEND_TYPE_SET_CE(*single_type, p);
38063803
}
38073804
} ZEND_TYPE_FOREACH_END();
38083805
} ZEND_HASH_FOREACH_END();
3809-
if (ok) {
3810-
ce->ce_flags |= ZEND_ACC_PROPERTY_TYPES_RESOLVED;
3811-
}
38123806
}
3813-
3814-
return ok;
38153807
}
38163808

38173809
static bool preload_is_class_type_known(zend_class_entry *ce, zend_string *name) {
@@ -4009,10 +4001,8 @@ static void preload_link(void)
40094001
if (ce->type == ZEND_INTERNAL_CLASS) {
40104002
break;
40114003
}
4012-
if (!(ce->ce_flags & ZEND_ACC_PROPERTY_TYPES_RESOLVED)) {
4013-
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) {
4014-
preload_try_resolve_property_types(ce);
4015-
}
4004+
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) {
4005+
preload_try_resolve_property_types(ce);
40164006
}
40174007
} ZEND_HASH_FOREACH_END();
40184008

@@ -4156,18 +4146,6 @@ static inline int preload_update_class_constants(zend_class_entry *ce) {
41564146
return result;
41574147
}
41584148

4159-
static zend_class_entry *preload_load_prop_type(zend_property_info *prop, zend_string *name) {
4160-
zend_class_entry *ce;
4161-
if (zend_string_equals_literal_ci(name, "self")) {
4162-
ce = prop->ce;
4163-
} else if (zend_string_equals_literal_ci(name, "parent")) {
4164-
ce = prop->ce->parent;
4165-
} else {
4166-
ce = zend_lookup_class(name);
4167-
}
4168-
return ce;
4169-
}
4170-
41714149
static void preload_ensure_classes_loadable(void) {
41724150
/* Run this in a loop, because additional classes may be loaded while updating constants etc. */
41734151
uint32_t checked_classes_idx = 0;
@@ -4192,25 +4170,6 @@ static void preload_ensure_classes_loadable(void) {
41924170
if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
41934171
preload_update_class_constants(ce);
41944172
}
4195-
4196-
if (!(ce->ce_flags & ZEND_ACC_PROPERTY_TYPES_RESOLVED)) {
4197-
if (ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) {
4198-
zend_property_info *prop;
4199-
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) {
4200-
zend_type *single_type;
4201-
ZEND_TYPE_FOREACH(prop->type, single_type) {
4202-
if (ZEND_TYPE_HAS_NAME(*single_type)) {
4203-
zend_class_entry *ce = preload_load_prop_type(
4204-
prop, ZEND_TYPE_NAME(*single_type));
4205-
if (ce) {
4206-
ZEND_TYPE_SET_CE(*single_type, ce);
4207-
}
4208-
}
4209-
} ZEND_TYPE_FOREACH_END();
4210-
} ZEND_HASH_FOREACH_END();
4211-
}
4212-
ce->ce_flags |= ZEND_ACC_PROPERTY_TYPES_RESOLVED;
4213-
}
42144173
} ZEND_HASH_FOREACH_END();
42154174
checked_classes_idx = num_classes;
42164175
}

ext/opcache/tests/preload_loadable_classes_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ var_dump(class_exists('Foo'));
2020
--EXPECT--
2121
bool(true)
2222
bool(true)
23-
bool(true)
23+
bool(false)

0 commit comments

Comments
 (0)