Skip to content

Allow CTE on basic type/math functions #10842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 114 additions & 12 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1722,14 +1722,14 @@ function array_pad(array $array, int $length, mixed $value): array {}

/**
* @return array<int|string, int|string>
* @refcount 1
* @compile-time-eval
* @refcount 1
*/
function array_flip(array $array): array {}

/**
* @refcount 1
* @compile-time-eval
* @refcount 1
*/
function array_change_key_case(array $array, int $case = CASE_LOWER): array {}

Expand All @@ -1738,7 +1738,10 @@ function array_change_key_case(array $array, int $case = CASE_LOWER): array {}
*/
function array_unique(array $array, int $flags = SORT_STRING): array {}

/** @refcount 1 */
/**
* @compile-time-eval
* @refcount 1
*/
function array_intersect_key(array $array, array ...$arrays): array {}

/**
Expand All @@ -1747,7 +1750,10 @@ function array_intersect_key(array $array, array ...$arrays): array {}
*/
function array_intersect_ukey(array $array, ...$rest): array {}

/** @refcount 1 */
/**
* @compile-time-eval
* @refcount 1
*/
function array_intersect(array $array, array ...$arrays): array {}

/**
Expand All @@ -1756,7 +1762,10 @@ function array_intersect(array $array, array ...$arrays): array {}
*/
function array_uintersect(array $array, ...$rest): array {}

/** @refcount 1 */
/**
* @compile-time-eval
* @refcount 1
*/
function array_intersect_assoc(array $array, array ...$arrays): array {}

/**
Expand All @@ -1778,8 +1787,8 @@ function array_intersect_uassoc(array $array, ...$rest): array {}
function array_uintersect_uassoc(array $array, ...$rest): array {}

/**
* @refcount 1
* @compile-time-eval
* @refcount 1
*/
function array_diff_key(array $array, array ...$arrays): array {}

Expand All @@ -1801,8 +1810,8 @@ function array_diff(array $array, array ...$arrays): array {}
function array_udiff(array $array, ...$rest): array {}

/**
* @refcount 1
* @compile-time-eval
* @refcount 1
*/
function array_diff_assoc(array $array, array ...$arrays): array {}

Expand Down Expand Up @@ -1867,8 +1876,8 @@ function array_is_list(array $array): bool {}
/* base64.c */

/**
* @refcount 1
* @compile-time-eval
* @refcount 1
*/
function base64_encode(string $string): string {}

Expand Down Expand Up @@ -2280,8 +2289,8 @@ function wordwrap(string $string, int $width = 75, string $break = "\n", bool $c

/**
* @return array<int, string>
* @refcount 1
* @compile-time-eval
* @refcount 1
*/
function explode(string $separator, string $string, int $limit = PHP_INT_MAX): array {}

Expand Down Expand Up @@ -2958,42 +2967,61 @@ function mail(string $to, string $subject, string $message, array|string $additi

/* math.c */

/** @compile-time-eval */
function abs(int|float $num): int|float {}

/** @compile-time-eval */
function ceil(int|float $num): float {}

/** @compile-time-eval */
function floor(int|float $num): float {}

/** @compile-time-eval */
function round(int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): float {}

/** @compile-time-eval */
function sin(float $num): float {}

/** @compile-time-eval */
function cos(float $num): float {}

/** @compile-time-eval */
function tan(float $num): float {}

/** @compile-time-eval */
function asin(float $num): float {}

/** @compile-time-eval */
function acos(float $num): float {}

/** @compile-time-eval */
function atan(float $num): float {}

/** @compile-time-eval */
function atanh(float $num): float {}

/** @compile-time-eval */
function atan2(float $y, float $x): float {}

/** @compile-time-eval */
function sinh(float $num): float {}

/** @compile-time-eval */
function cosh(float $num): float {}

/** @compile-time-eval */
function tanh(float $num): float {}

/** @compile-time-eval */
function asinh(float $num): float {}

/** @compile-time-eval */
function acosh(float $num): float {}

/** @compile-time-eval */
function expm1(float $num): float {}

/** @compile-time-eval */
function log1p(float $num): float {}

/** @compile-time-eval */
Expand All @@ -3014,18 +3042,25 @@ function is_infinite(float $num): bool {}
/** @compile-time-eval */
function pow(mixed $num, mixed $exponent): int|float|object {}

/** @compile-time-eval */
function exp(float $num): float {}

/** @compile-time-eval */
function log(float $num, float $base = M_E): float {}

/** @compile-time-eval */
function log10(float $num): float {}

/** @compile-time-eval */
function sqrt(float $num): float {}

/** @compile-time-eval */
function hypot(float $x, float $y): float {}

/** @compile-time-eval */
function deg2rad(float $num): float {}

/** @compile-time-eval */
function rad2deg(float $num): float {}

/** @compile-time-eval */
Expand Down Expand Up @@ -3055,14 +3090,26 @@ function decoct(int $num): string {}
*/
function dechex(int $num): string {}

/** @refcount 1 */
/**
* @compile-time-eval
* @refcount 1
*/
function base_convert(string $num, int $from_base, int $to_base): string {}

/** @refcount 1 */
/**
* @compile-time-eval
* @refcount 1
*/
function number_format(float $num, int $decimals = 0, ?string $decimal_separator = ".", ?string $thousands_separator = ","): string {}

/**
* @compile-time-eval
*/
function fmod(float $num1, float $num2): float {}

/**
* @compile-time-eval
*/
function fdiv(float $num1, float $num2): float {}

/* microtime.c */
Expand All @@ -3088,11 +3135,15 @@ function getrusage(int $mode = 0): array|false {}

/* pack.c */

/** @refcount 1 */
/**
* @compile-time-eval
* @refcount 1
*/
function pack(string $format, mixed ...$values): string {}

/**
* @return array<int|string, mixed>|false
* @compile-time-eval
* @refcount 1
*/
function unpack(string $format, string $string, int $offset = 0): array|false {}
Expand Down Expand Up @@ -3358,29 +3409,56 @@ function socket_set_timeout($stream, int $seconds, int $microseconds = 0): bool

/* type.c */

/**
* @compile-time-eval
*/
function gettype(mixed $value): string {}

/**
* @compile-time-eval
*/
function get_debug_type(mixed $value): string {}

function settype(mixed &$var, string $type): bool {}

/**
* @compile-time-eval
*/
function intval(mixed $value, int $base = 10): int {}

/**
* @compile-time-eval
*/
function floatval(mixed $value): float {}

/** @alias floatval */
function doubleval(mixed $value): float {}

/**
* @compile-time-eval
*/
function boolval(mixed $value): bool {}

/**
* @compile-time-eval
*/
function strval(mixed $value): string {}

/**
* @compile-time-eval
*/
function is_null(mixed $value): bool {}

function is_resource(mixed $value): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can is_resource cause issues when called at compile time? Otherwise, it could still eliminate calls when elements are not resources.

Copy link
Contributor Author

@mvorisek mvorisek Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong, but can resource be even observed on CT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it could eliminate calls like is_resource(42).

Copy link
Contributor Author

@mvorisek mvorisek Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added is_resource, tests pass, the 1 ASAN failure is unrelated.


/**
* @compile-time-eval
*/
function is_bool(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_int(mixed $value): bool {}

/** @alias is_int */
Expand All @@ -3389,26 +3467,50 @@ function is_integer(mixed $value): bool {}
/** @alias is_int */
function is_long(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_float(mixed $value): bool {}

/** @alias is_float */
function is_double(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_numeric(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_string(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_array(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_object(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_scalar(mixed $value): bool {}

/** @param string $callable_name */
function is_callable(mixed $value, bool $syntax_only = false, &$callable_name = null): bool {}

/**
* @compile-time-eval
*/
function is_iterable(mixed $value): bool {}

/**
* @compile-time-eval
*/
function is_countable(mixed $value): bool {}

/* uniqid.c */
Expand Down
Loading