Skip to content

Commit

Permalink
compile unsupported phpt tests (#1098)
Browse files Browse the repository at this point in the history
Compile unsupported phpt test in k2 mode. Continuation of #1093
  • Loading branch information
astrophysik authored Sep 17, 2024
1 parent 3b0a9d6 commit 755b06b
Show file tree
Hide file tree
Showing 43 changed files with 554 additions and 112 deletions.
13 changes: 11 additions & 2 deletions builtin-functions/kphp-light/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ define('PHP_INT_MIN', -9223372036854775808);
define('PHP_INT_SIZE', 8);
define('PHP_EOL', "\n");

if (0) {
define('PHP_SAPI', php_sapi_name());//"Defined in source code"
}

/** @var mixed $_SERVER */
global $_SERVER;
Expand All @@ -36,10 +39,16 @@ function intval ($v ::: mixed) ::: int;
function floatval ($v ::: mixed) ::: float;
function strval ($v ::: mixed) ::: string;

/** @kphp-extern-func-info interruptible */
/**
* @kphp-no-return
* @kphp-extern-func-info interruptible
*/
function exit($code = 0) ::: void;

/** @kphp-extern-func-info interruptible */
/**
* @kphp-no-return
* @kphp-extern-func-info interruptible
*/
function die($code = 0) ::: void;

function ob_clean() ::: void;
Expand Down
2 changes: 2 additions & 0 deletions builtin-functions/kphp-light/unsupported-functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ require_once __DIR__ . '/unsupported/kphp-toggles.txt';
require_once __DIR__ . '/unsupported/kphp-tracing.txt';
require_once __DIR__ . '/unsupported/kphp_internal.txt';
require_once __DIR__ . '/unsupported/math.txt';
require_once __DIR__ . '/unsupported/memcache.txt';
require_once __DIR__ . '/unsupported/misc.txt';
require_once __DIR__ . '/unsupported/regex.txt';
require_once __DIR__ . '/unsupported/rpc.txt';
require_once __DIR__ . '/unsupported/serialize.txt';
require_once __DIR__ . '/unsupported/server.txt';
require_once __DIR__ . '/unsupported/spl.txt';
require_once __DIR__ . '/unsupported/string.txt';
require_once __DIR__ . '/unsupported/time.txt';
require_once __DIR__ . '/unsupported/uberh3.txt';
Expand Down
10 changes: 10 additions & 0 deletions builtin-functions/kphp-light/unsupported/crypto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ define('OPENSSL_RAW_DATA', 1);
define('OPENSSL_ZERO_PADDING', 2);
define('OPENSSL_DONT_ZERO_PAD_KEY', 4);

define('PKCS7_TEXT', 0x1);
define('PKCS7_NOCERTS', 0x2);
define('PKCS7_NOSIGS', 0x4);
define('PKCS7_NOCHAIN', 0x8);
define('PKCS7_NOINTERN', 0x10);
define('PKCS7_NOVERIFY', 0x20);
define('PKCS7_BINARY', 0x80);
define('PKCS7_DETACHED', 0x40);
define('PKCS7_NOATTR', 0x100);

/** @kphp-extern-func-info generate-stub */
function openssl_public_encrypt ($data ::: string, &$result ::: mixed, $key ::: string) ::: bool;
/** @kphp-extern-func-info generate-stub */
Expand Down
30 changes: 18 additions & 12 deletions builtin-functions/kphp-light/unsupported/file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function unlink ($name ::: string) ::: bool;


/** @kphp-extern-func-info generate-stub */
function fgetcsv ($stream, $length = 0, $delimiter = ",", $enclosure = "\"", $escape = "\\") ::: mixed[] | false;
function fgetcsv ($stream ::: mixed, $length ::: int = 0, $delimiter ::: string = ",", $enclosure ::: string = "\"", $escape ::: string = "\\") ::: mixed[] | false;

define('STDIN', 'php://stdin');
define('STDOUT', 'php://stdout');
Expand All @@ -59,29 +59,35 @@ define('SEEK_CUR', 2);
/** @kphp-extern-func-info generate-stub */
function fopen ($filename ::: string, $mode ::: string) ::: mixed;
/** @kphp-extern-func-info generate-stub */
function fwrite ($stream, $text ::: string) ::: int | false;
function fwrite ($stream ::: mixed, $text ::: string) ::: int | false;
/** @kphp-extern-func-info generate-stub */
function fseek ($stream, $offset ::: int, $whence ::: int = SEEK_SET) ::: int;
function fseek ($stream ::: mixed, $offset ::: int, $whence ::: int = SEEK_SET) ::: int;
/** @kphp-extern-func-info generate-stub */
function rewind ($stream) ::: bool;
function rewind ($stream ::: mixed) ::: bool;
/** @kphp-extern-func-info generate-stub */
function ftell ($stream) ::: int | false;
function ftell ($stream ::: mixed) ::: int | false;
/** @kphp-extern-func-info generate-stub */
function fread ($stream, $length ::: int) ::: string | false;
function fread ($stream ::: mixed, $length ::: int) ::: string | false;
/** @kphp-extern-func-info generate-stub */
function fgetc ($stream) ::: string | false;
function fgetc ($stream ::: mixed) ::: string | false;
/** @kphp-extern-func-info generate-stub */
function fpassthru ($stream) ::: int | false;
function fpassthru ($stream ::: mixed) ::: int | false;
/** @kphp-extern-func-info generate-stub */
function fgets ($stream, $length ::: int = -1) ::: string | false;
function fgets ($stream ::: mixed, $length ::: int = -1) ::: string | false;
/** @kphp-extern-func-info generate-stub */
function fflush ($stream) ::: bool;
function fflush ($stream ::: mixed) ::: bool;
/** @kphp-extern-func-info generate-stub */
function feof ($stream) ::: bool;
function feof ($stream ::: mixed) ::: bool;
/** @kphp-extern-func-info generate-stub */
function fclose ($stream) ::: bool;
function fclose ($stream ::: mixed) ::: bool;

define('STREAM_CLIENT_CONNECT', 1);
define('DEFAULT_SOCKET_TIMEOUT', 60);

/** @kphp-extern-func-info generate-stub */
function stream_context_create ($options ::: mixed = array()) ::: mixed;

function stream_socket_client ($url ::: string, &$error_number ::: mixed = TODO, &$error_description ::: mixed = TODO, $timeout ::: float = DEFAULT_SOCKET_TIMEOUT, $flags ::: int = STREAM_CLIENT_CONNECT, $context ::: mixed = null) ::: mixed;

function fprintf ($stream, $format ::: string, ...$args) ::: int;
function fputcsv ($stream, $fields ::: array, $delimiter = ",", $enclosure = "\"", $escape = "\\") ::: int | false;
Expand Down
8 changes: 4 additions & 4 deletions builtin-functions/kphp-light/unsupported/fork.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ function wait_concurrently ($id ::: future<any>) ::: bool;
/** @kphp-extern-func-info can_throw generate-stub cpp_template_call */
function wait_multi (future<any>[] $resumables) ::: (^1[*][*] | null)[];

/** @kphp-extern-func-info generate-stub */

function wait_queue_create (array< future<any> | false > $request_ids = []) ::: future_queue<^1[*][*]>;
/** @kphp-extern-func-info generate-stub */

function wait_queue_push (future_queue<any> &$queue_id, future<any> | false $request_ids) ::: void;
/** @kphp-extern-func-info generate-stub */

function wait_queue_empty (future_queue<any> $queue_id) ::: bool;
/** @kphp-extern-func-info generate-stub */

function wait_queue_next (future_queue<any> $queue_id, $timeout ::: float = -1.0) ::: future<^1[*]> | false;
24 changes: 23 additions & 1 deletion builtin-functions/kphp-light/unsupported/hash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,32 @@ function md5_file ($s ::: string, $raw_output ::: bool = false) ::: string | fal
function sha1 ($s ::: string, $raw_output ::: bool = false) ::: string;


define('ZLIB_ENCODING_RAW', -0x0f);
define('ZLIB_ENCODING_DEFLATE', 0x0f);
define('ZLIB_ENCODING_GZIP', 0x1f);

define('ZLIB_NO_FLUSH', 0);
define('ZLIB_PARTIAL_FLUSH', 1);
define('ZLIB_SYNC_FLUSH', 2);
define('ZLIB_FULL_FLUSH', 3);
define('ZLIB_FINISH', 4);
define('ZLIB_BLOCK', 5);
define('ZLIB_TREES', 6);

define('ZLIB_FILTERED', 1);
define('ZLIB_HUFFMAN_ONLY', 2);
define('ZLIB_RLE', 3);
define('ZLIB_FIXED', 4);
define('ZLIB_DEFAULT_STRATEGY', 0);

/** @kphp-generate-stub-class */
final class DeflateContext {
private function __construct() ::: DeflateContext;
}

// todo: deflate_init php signature has type array instead mixed
/** @kphp-extern-func-info generate-stub */
function deflate_init(int $encoding, array $options = []) ::: ?DeflateContext;
function deflate_init(int $encoding, mixed $options = []) ::: ?DeflateContext;
/** @kphp-extern-func-info generate-stub */
function deflate_add(DeflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH) ::: string | false;
/** @kphp-extern-func-info generate-stub */
Expand Down
23 changes: 23 additions & 0 deletions builtin-functions/kphp-light/unsupported/kphp_internal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

function _exception_set_location($e, string $filename, int $line): ^1;

// microtime(false) specialization
/** @kphp-extern-func-info generate-stub */
function _microtime_string(): string;
// microtime(true) specialization
/** @kphp-extern-func-info generate-stub */
function _microtime_float(): float;

// hrtime(true) specialization
/** @kphp-extern-func-info generate-stub */
function _hrtime_int(): int;
// hrtime(false) specialization
/** @kphp-extern-func-info generate-stub */
function _hrtime_array(): int[];

// `new $c(...)` => `_by_name_construct($c, ...)`
function _by_name_construct(string $class_name, ...$args) ::: instance<^1>;
// `$c::method()` => `_by_name_call_method($c, 'method')`
function _by_name_call_method(string $class_name, string $method_name, ...$args);
// `$c::CONST` => `_by_name_get_const($c, 'CONST')`
function _by_name_get_const(string $class_name, string $constant);
// `$c::$field` => `_by_name_get_field($c, 'field')`
function _by_name_get_field(string $class_name, string $field);


/**
* @kphp-extern-func-info generate-stub
Expand Down
46 changes: 46 additions & 0 deletions builtin-functions/kphp-light/unsupported/memcache.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/** @kphp-generate-stub-class */
interface Memcache {
public function get (string|string[] $key) ::: mixed;
public function delete (string $key) ::: bool;
public function add (string $key, mixed $value, int $flags = 0, int $expire = 0) ::: bool;
public function set (string $key, mixed $value, int $flags = 0, int $expire = 0) ::: bool;
public function replace (string $key, mixed $value, int $flags = 0, int $expire = 0) ::: bool;
public function decrement (string $key, int $v = 1) ::: mixed;
public function increment (string $key, int $v = 1) ::: mixed;
public function getVersion () ::: mixed;

// this two functions shouldn't be there, but we need it to rewrite code
public function addServer (string $host, int $port = 11211, bool $persistent = true, int $weight = 1, float $timeout = 1, int $retry_interval = 15, bool $status = true, mixed $failure_callback = null, int $timeoutms = 0) ::: bool;
public function rpc_connect (string $host, int $port, mixed $default_actor_id = 0, float $timeout = 0.3, float $connect_timeout = 0.3, float $reconnect_timeout = 17.0) ::: bool;
}


/** @kphp-generate-stub-class */
final class McMemcache implements Memcache {
/** @kphp-extern-func-info generate-stub */
public function __construct() ::: McMemcache;

/** @kphp-extern-func-info generate-stub */
public function get (string|string[] $key) ::: mixed;
/** @kphp-extern-func-info generate-stub */
public function delete (string $key) ::: bool;
/** @kphp-extern-func-info generate-stub */
public function add (string $key, mixed $value, int $flags = 0, int $expire = 0) ::: bool;
/** @kphp-extern-func-info generate-stub */
public function set (string $key, mixed $value, int $flags = 0, int $expire = 0) ::: bool;
/** @kphp-extern-func-info generate-stub */
public function replace (string $key, mixed $value, int $flags = 0, int $expire = 0) ::: bool;
/** @kphp-extern-func-info generate-stub */
public function decrement (string $key, int $v = 1) ::: mixed;
/** @kphp-extern-func-info generate-stub */
public function increment (string $key, int $v = 1) ::: mixed;
/** @kphp-extern-func-info generate-stub */
public function getVersion () ::: mixed;
/** @kphp-extern-func-info generate-stub */
public function addServer (string $host, int $port = 11211, bool $persistent = true, int $weight = 1, float $timeout = 1, int $retry_interval = 15, bool $status = true, mixed $failure_callback = null, int $timeoutms = 0) ::: bool;

/** @kphp-extern-func-info generate-stub */
public function rpc_connect (string $host, int $port, mixed $default_actor_id = 0, float $timeout = 0.3, float $connect_timeout = 0.3, float $reconnect_timeout = 17.0) ::: bool;
}
2 changes: 1 addition & 1 deletion builtin-functions/kphp-light/unsupported/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function htmlspecialchars_decode ($str ::: string, $flags ::: int = ENT_COMPAT)
/** @kphp-extern-func-info generate-stub */
function nl2br ($str ::: string, $is_xhtml ::: bool = true) ::: string;
/** @kphp-extern-func-info generate-stub */
function number_format ($number ::: float, $decimals ::: int = 0, $dec_point = '.', $thousands_sep = ',') ::: string;
function number_format ($number ::: float, $decimals ::: int = 0, $dec_point ::: string = '.', $thousands_sep ::: string = ',') ::: string;
/** @kphp-extern-func-info generate-stub */
function ord ($c ::: string) ::: int;

Expand Down
6 changes: 5 additions & 1 deletion builtin-functions/kphp-light/unsupported/rpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ function new_rpc_connection ($str ::: string, $port ::: int, $actor_id ::: mixed
/** @kphp-extern-func-info generate-stub */
function extract_kphp_rpc_response_extra_info ($resumable_id ::: int) ::: ?tuple(int, float);


/** @kphp-generate-stub-class */
final class RpcConnection {
/** @kphp-extern-func-info generate-stub */
private function __construct();
}
8 changes: 8 additions & 0 deletions builtin-functions/kphp-light/unsupported/server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ function getopt ($options ::: string, $longopt ::: array = array(), ?int &$rest_
/** @kphp-extern-func-info generate-stub */
function profiler_set_function_label($label ::: string) ::: void;

define('LC_ALL', 6);
define('LC_COLLATE', 3);
define('LC_CTYPE', 0);
define('LC_MONETARY', 4);
define('LC_NUMERIC', 1);
define('LC_TIME', 2);
define('LC_MESSAGES', 5);

/** @kphp-extern-func-info generate-stub */
function setlocale ($category ::: int, $locale ::: string) ::: string | false;

Expand Down
75 changes: 75 additions & 0 deletions builtin-functions/kphp-light/unsupported/spl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/** @kphp-generate-stub-class */
class ArithmeticError extends Error {}
/** @kphp-generate-stub-class */
class DivisionByZeroError extends ArithmeticError {}
/** @kphp-generate-stub-class */
class AssertionError extends Error {}
/** @kphp-generate-stub-class */
class CompileError extends Error {}
/** @kphp-generate-stub-class */
class ParseError extends CompileError {}
/** @kphp-generate-stub-class */
class TypeError extends Error {}
/** @kphp-generate-stub-class */
class ArgumentCountError extends TypeError {}
/** @kphp-generate-stub-class */
class ValueError extends Error {}
/** @kphp-generate-stub-class */
class UnhandledMatchError extends Error {}

/** @kphp-generate-stub-class */
class LogicException extends Exception {}
/** @kphp-generate-stub-class */
class BadFunctionCallException extends LogicException {}
/** @kphp-generate-stub-class */
class BadMethodCallException extends BadFunctionCallException {}
/** @kphp-generate-stub-class */
class DomainException extends LogicException {}
/** @kphp-generate-stub-class */
class InvalidArgumentException extends LogicException {}
/** @kphp-generate-stub-class */
class LengthException extends LogicException {}
/** @kphp-generate-stub-class */
class OutOfRangeException extends LogicException {}

/** @kphp-generate-stub-class */
class RuntimeException extends Exception {}
/** @kphp-generate-stub-class */
class OutOfBoundsException extends RuntimeException {}
/** @kphp-generate-stub-class */
class OverflowException extends RuntimeException {}
/** @kphp-generate-stub-class */
class RangeException extends RuntimeException {}
/** @kphp-generate-stub-class */
class UnderflowException extends RuntimeException {}
/** @kphp-generate-stub-class */
class UnexpectedValueException extends RuntimeException {}

/** @kphp-generate-stub-class */
class Random\RandomException extends Exception {}

// https://www.php.net/manual/en/class.arrayiterator.php
// TODO: make it work with T[] arrays when generic classes are available.
// For now, it only supports mixed[].
/** @kphp-generate-stub-class */
final class ArrayIterator {
/** @kphp-extern-func-info generate-stub */
public function __construct($arr ::: mixed[]);

/** @kphp-extern-func-info generate-stub */
public function count(): int;

/** @kphp-extern-func-info generate-stub */
public function current(): mixed;

/** @kphp-extern-func-info generate-stub */
public function key(): mixed;

/** @kphp-extern-func-info generate-stub */
public function next(): void;

/** @kphp-extern-func-info generate-stub */
public function valid(): bool;
}
Loading

0 comments on commit 755b06b

Please sign in to comment.