Skip to content

Commit d514c3b

Browse files
committed
Add support for generating MAY_BE_ARRAY_OF_REF func info flag
1 parent 3565d02 commit d514c3b

11 files changed

+46
-26
lines changed

Zend/Optimizer/zend_func_info.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
8888
}
8989

9090
static const func_info_t old_func_infos[] = {
91-
/* zend */
92-
F1("get_class_vars", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
93-
F1("get_defined_vars", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
94-
9591
/* ext/standard */
9692
F1("parse_ini_file", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_FALSE | MAY_BE_ARRAY_OF_TRUE | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_DOUBLE | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
9793
F1("parse_ini_string", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_FALSE | MAY_BE_ARRAY_OF_TRUE | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_DOUBLE | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
@@ -165,18 +161,8 @@ static const func_info_t old_func_infos[] = {
165161
F1("stream_bucket_new", MAY_BE_OBJECT),
166162
F1("sys_get_temp_dir", MAY_BE_STRING),
167163

168-
/* ext/preg */
169-
F1("preg_grep", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY),
170-
171164
F1("utf8_encode", MAY_BE_STRING),
172165
F1("utf8_decode", MAY_BE_STRING),
173-
174-
/* ext/filter */
175-
F1("filter_var_array", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
176-
177-
/* ext/spl */
178-
F1("iterator_to_array", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY),
179-
180166
};
181167

182168
static HashTable func_info;

Zend/Optimizer/zend_func_infos.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
static const func_info_t func_infos[] = {
44
F1("zend_version", MAY_BE_STRING),
55
FN("func_get_args", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY),
6+
F1("get_class_vars", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
67
F1("get_class_methods", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
78
F1("get_included_files", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
89
FN("set_error_handler", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_OBJECT|MAY_BE_NULL),
@@ -13,6 +14,7 @@ static const func_info_t func_infos[] = {
1314
F1("get_declared_traits", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1415
F1("get_declared_interfaces", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1516
F1("get_defined_functions", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ARRAY),
17+
F1("get_defined_vars", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
1618
F1("get_resource_type", MAY_BE_STRING),
1719
F1("get_loaded_extensions", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1820
F1("get_defined_constants", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
@@ -81,6 +83,7 @@ static const func_info_t func_infos[] = {
8183
F1("finfo_buffer", MAY_BE_STRING|MAY_BE_FALSE),
8284
F1("mime_content_type", MAY_BE_STRING|MAY_BE_FALSE),
8385
F1("filter_input_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_FALSE|MAY_BE_NULL),
86+
F1("filter_var_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_FALSE|MAY_BE_NULL),
8487
F1("filter_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
8588
F1("gd_info", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE),
8689
F1("imagecreatetruecolor", MAY_BE_OBJECT|MAY_BE_FALSE),
@@ -328,6 +331,7 @@ static const func_info_t func_infos[] = {
328331
FN("preg_filter", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_NULL),
329332
FN("preg_replace_callback", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_NULL),
330333
F1("preg_split", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),
334+
F1("preg_grep", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_FALSE),
331335
F1("pg_dbname", MAY_BE_STRING),
332336
F1("pg_options", MAY_BE_STRING),
333337
F1("pg_port", MAY_BE_STRING),
@@ -387,6 +391,7 @@ static const func_info_t func_infos[] = {
387391
F1("class_uses", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
388392
F1("spl_classes", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING),
389393
F1("spl_object_hash", MAY_BE_STRING),
394+
F1("iterator_to_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
390395
F1("base64_encode", MAY_BE_STRING),
391396
F1("base64_decode", MAY_BE_STRING|MAY_BE_FALSE),
392397
F1("long2ip", MAY_BE_STRING|MAY_BE_FALSE),

Zend/zend_builtin_functions.stub.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ function is_subclass_of(mixed $object_or_class, string $class, bool $allow_strin
4444
/** @param object|string $object_or_class */
4545
function is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool {}
4646

47+
/**
48+
* @return array-ref<string, mixed>
49+
* @refcount 1
50+
*/
4751
function get_class_vars(string $class): array {}
4852

4953
function get_object_vars(object $object): array {}
@@ -127,6 +131,10 @@ function get_declared_interfaces(): array {}
127131
*/
128132
function get_defined_functions(bool $exclude_disabled = true): array {}
129133

134+
/**
135+
* @return array-ref<string, mixed>
136+
* @refcount 1
137+
*/
130138
function get_defined_vars(): array {}
131139

132140
/**

Zend/zend_builtin_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 830eee0780adba8fc87cd5aed7f755d4d85ed82b */
2+
* Stub hash: b2ad660f538e2d5c2c432bb58b037ae5160f8833 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()

build/gen_stub.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,21 @@ class ArrayType extends SimpleType {
120120
/** @var Type */
121121
public $valueType;
122122

123+
/** @var bool */
124+
public $supportsReferences;
125+
123126
public static function createGenericArray(): self
124127
{
125-
return new ArrayType(Type::fromString("int|string"), Type::fromString("mixed"));
128+
return new ArrayType(Type::fromString("int|string"), Type::fromString("mixed"), false);
126129
}
127130

128-
public function __construct(Type $keyType, Type $valueType)
131+
public function __construct(Type $keyType, Type $valueType, bool $supportsReferences)
129132
{
130133
parent::__construct("array", true);
131134

132135
$this->keyType = $keyType;
133136
$this->valueType = $valueType;
137+
$this->supportsReferences = $supportsReferences;
134138
}
135139

136140
public function toOptimizerTypeMask(): string {
@@ -140,6 +144,10 @@ public function toOptimizerTypeMask(): string {
140144
$this->valueType->toOptimizerTypeMaskForArrayValue(),
141145
];
142146

147+
if ($this->supportsReferences) {
148+
$typeMasks[] = "MAY_BE_ARRAY_OF_REF";
149+
}
150+
143151
return implode("|", $typeMasks);
144152
}
145153

@@ -151,7 +159,8 @@ public function equals(SimpleType $other): bool {
151159
assert(get_class($other) === self::class);
152160

153161
return Type::equals($this->keyType, $other->keyType) &&
154-
Type::equals($this->valueType, $other->valueType);
162+
Type::equals($this->valueType, $other->valueType) &&
163+
$this->supportsReferences === $other->supportsReferences;
155164
}
156165
}
157166

@@ -215,13 +224,13 @@ public static function fromString(string $typeString): SimpleType
215224
$matches = [];
216225
$isArray = preg_match("/(.*)\s*\[\s*\]/", $typeString, $matches);
217226
if ($isArray) {
218-
return new ArrayType(Type::fromString("int"), Type::fromString($matches[1]));
227+
return new ArrayType(Type::fromString("int"), Type::fromString($matches[1]), false);
219228
}
220229

221230
$matches = [];
222-
$isArray = preg_match("/array\s*<\s*([A-Za-z0-9_-|]+)\s*,\s*([A-Za-z0-9_-|]+)\s*>/i", $typeString, $matches);
231+
$isArray = preg_match("/array(-ref)?\s*<\s*([A-Za-z0-9_-|]+)\s*,\s*([A-Za-z0-9_-|]+)\s*>/i", $typeString, $matches);
223232
if ($isArray) {
224-
return new ArrayType(Type::fromString($matches[1]), Type::fromString($matches[2]));
233+
return new ArrayType(Type::fromString($matches[2]), Type::fromString($matches[3]), !empty($matches[1]));
225234
}
226235

227236
return new SimpleType($typeString, false);
@@ -2032,9 +2041,9 @@ public function getType(): string {
20322041
$matches = [];
20332042

20342043
if ($this->name === "param") {
2035-
preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*\$\w+.*$/', $value, $matches);
2044+
preg_match('/^\s*([\w\|\\\\\[\]<>,\- ]+)\s*\$\w+.*$/', $value, $matches);
20362045
} elseif ($this->name === "return") {
2037-
preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)(\s+|$)/', $value, $matches);
2046+
preg_match('/^\s*([\w\|\\\\\[\]<>,\- ]+)(\s+|$)/', $value, $matches);
20382047
}
20392048

20402049
if (!isset($matches[1])) {

ext/filter/filter.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $optio
1111
/** @refcount 1 */
1212
function filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null {}
1313

14+
/**
15+
* @return array-ref<int|string, mixed>|false|null
16+
* @refcount 1
17+
*/
1418
function filter_var_array(array $array, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null {}
1519

1620
/**

ext/filter/filter_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 28ff4549a3e25c103a172624b8e25c6cd1912379 */
2+
* Stub hash: a5db1b691947245e9b3458e7a5a1ffe62a802d8b */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_has_var, 0, 2, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, input_type, IS_LONG, 0)

ext/pcre/php_pcre.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function preg_split(string $pattern, string $subject, int $limit = -1, int $flag
3737

3838
function preg_quote(string $str, ?string $delimiter = null): string {}
3939

40+
/**
41+
* @return array-ref<int|string, mixed>|false
42+
* @refcount 1
43+
*/
4044
function preg_grep(string $pattern, array $array, int $flags = 0): array|false {}
4145

4246
function preg_last_error(): int {}

ext/pcre/php_pcre_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 5d7958a9f83b19eef0bffdf631ddb47cae28733f */
2+
* Stub hash: d0eeb138b997db89537baf129ee6146303dae63d */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_preg_match, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)

ext/spl/php_spl.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ function iterator_apply(Traversable $iterator, callable $callback, ?array $args
5050

5151
function iterator_count(Traversable $iterator): int {}
5252

53+
/**
54+
* @return array-ref<int|string, mixed>
55+
* @refcount 1
56+
*/
5357
function iterator_to_array(Traversable $iterator, bool $preserve_keys = true): array {}

ext/spl/php_spl_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 20188120387b006ea0e5833ad20241b73d2e2327 */
2+
* Stub hash: a200c26a76a814b4ac8ab238e884f2d823097b2b */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_implements, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
55
ZEND_ARG_INFO(0, object_or_class)

0 commit comments

Comments
 (0)