Skip to content

Commit

Permalink
compile unsupported vkcom (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik authored Oct 25, 2024
1 parent 5e4b58a commit 16c5af2
Show file tree
Hide file tree
Showing 48 changed files with 671 additions and 200 deletions.
16 changes: 16 additions & 0 deletions builtin-functions/kphp-light/crypto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,19 @@ function openssl_pkey_get_public ($key ::: string) ::: string | false;
/** @kphp-extern-func-info generate-stub */
function openssl_x509_verify ($x509cert ::: string, $public_key ::: string) ::: int;


/** @kphp-extern-func-info generate-stub */
function openssl_pkcs7_sign($infile ::: string, $outfile ::: string,
$sign_cert ::: string, $priv_key ::: string,
string[] $headers, $flags ::: int = PKCS7_DETACHED, $extra_certs ::: string = "") ::: bool;

/** @kphp-extern-func-info generate-stub */
function openssl_get_cipher_methods($aliases ::: bool = false) ::: string[];
/** @kphp-extern-func-info generate-stub */
function openssl_cipher_iv_length($method ::: string) ::: int | false;

function openssl_encrypt($data ::: string, $method ::: string, $key ::: string, $options ::: int = 0, $iv ::: string = '',
string &$tag = TODO, $aad ::: string = '', $tag_length ::: int = 16) ::: string | false;
/** @kphp-extern-func-info generate-stub */
function openssl_decrypt($data ::: string, $method ::: string, $key ::: string, $options ::: int = 0, $iv ::: string = '',
$tag ::: string = '', $aad ::: string = '') ::: string | false;
49 changes: 5 additions & 44 deletions builtin-functions/kphp-light/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
require_once __DIR__ . '/array.txt';
require_once __DIR__ . '/confdata.txt';
require_once __DIR__ . '/crypto.txt';
require_once __DIR__ . '/rpc.txt';
require_once __DIR__ . '/hash.txt';
require_once __DIR__ . '/job-workers.txt';

/** defined in runtime-core.h **/
function likely ($x ::: bool) ::: bool;
function unlikely ($x ::: bool) ::: bool;

define('TODO', -1);
define('TODO_OVERLOAD', -1);

Expand Down Expand Up @@ -109,50 +114,6 @@ function sched_yield() ::: void;
/** @kphp-extern-func-info interruptible */
function sched_yield_sleep($duration ::: float) ::: void;

// === Rpc ========================================================================================

/** @kphp-tl-class */
interface RpcFunction {
public function getTLFunctionName() : string;
}

/** @kphp-tl-class */
interface RpcFunctionReturnResult {}

// type ReqResult <=> RpcResponse
/** @kphp-tl-class */
interface RpcResponse {
public function getResult() : @tl\RpcFunctionReturnResult;
public function getHeader() : @tl\_common\Types\rpcResponseHeader;
public function getError() : @tl\_common\Types\rpcResponseError;
public function isError() : bool;
}

/**
* 'KphpRpcRequestsExtraInfo' is a builtin KPHP class. It may accumulate extra information
* about RPC requests sent in both typed and untyped versions of rpc_tl_query builtins.
*/
final class KphpRpcRequestsExtraInfo {
/**
* 'get' returns an array of extra information (request size) about sent RPC requests.
*
* @return tuple(int)[]
*/
public function get ();
}

/** @kphp-extern-func-info interruptible */
function rpc_tl_query($actor ::: string, $arr ::: array, $timeout ::: float = -1.0, $ignore_answer ::: bool = false, \KphpRpcRequestsExtraInfo $requests_extra_info = null, $need_responses_extra_info ::: bool = false) ::: int[];

/** @kphp-extern-func-info interruptible */
function typed_rpc_tl_query($actor ::: string, @tl\RpcFunction[] $query_functions, $timeout ::: float = -1.0, $ignore_answer ::: bool = false, \KphpRpcRequestsExtraInfo $requests_extra_info = null, $need_responses_extra_info ::: bool = false) ::: int[];

/** @kphp-extern-func-info interruptible */
function rpc_tl_query_result($query_ids ::: array) ::: mixed[][];

/** @kphp-extern-func-info interruptible */
function typed_rpc_tl_query_result(int[] $query_ids) ::: @tl\RpcResponse[];

// === Component ==================================================================================

class ComponentQuery {
Expand Down
30 changes: 21 additions & 9 deletions builtin-functions/kphp-light/job-workers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,33 @@ class KphpJobWorkerResponseError implements KphpJobWorkerResponse {
}

/** @kphp-extern-func-info interruptible */
function kphp_job_worker_start(string $request, float $timeout): future<string> | false;

function job_worker_send_request(string $request, float $timeout): future<string> | false;
/** @kphp-extern-func-info interruptible */
function kphp_job_worker_start_no_reply(string $request, float $timeout): bool;

function job_worker_send_noreply_request(string $request, float $timeout): bool;
/** @kphp-extern-func-info interruptible */
function kphp_job_worker_start_multi(string[] $request, float $timeout): (future<string> | false)[];

function job_worker_send_multi_request(string[] $request, float $timeout): (future<string> | false)[];
/** @kphp-extern-func-info interruptible */
function kphp_job_worker_fetch_request(): string;

function job_worker_fetch_request(): string;
/** @kphp-extern-func-info interruptible */
function kphp_job_worker_store_response(string $response): int;
function job_worker_store_response(string $response): int;

function is_kphp_job_workers_enabled(): bool;

function get_job_workers_number(): int;

// === Job Worker Old API =================================================================================

/** @kphp-extern-func-info generate-stub */
function kphp_job_worker_start(KphpJobWorkerRequest $request, float $timeout): future<KphpJobWorkerResponse> | false;

/** @kphp-extern-func-info generate-stub */
function kphp_job_worker_start_no_reply(KphpJobWorkerRequest $request, float $timeout): bool;

/** @kphp-extern-func-info generate-stub */
function kphp_job_worker_start_multi(KphpJobWorkerRequest[] $request, float $timeout): (future<KphpJobWorkerResponse> | false)[];

/** @kphp-extern-func-info generate-stub */
function kphp_job_worker_fetch_request() ::: KphpJobWorkerRequest;
// returns 0 on success, < 0 - on errors. All possible error codes are constants like KphpJobWorkerResponseError::JOB_STORE_RESPONSE_*
/** @kphp-extern-func-info generate-stub */
function kphp_job_worker_store_response(KphpJobWorkerResponse $response) ::: int;
137 changes: 137 additions & 0 deletions builtin-functions/kphp-light/rpc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

// === Rpc ========================================================================================

/** @kphp-tl-class */
interface RpcFunction {
public function getTLFunctionName() : string;
}

/** @kphp-tl-class */
interface RpcFunctionReturnResult {}

// type ReqResult <=> RpcResponse
/** @kphp-tl-class */
interface RpcResponse {
public function getResult() : @tl\RpcFunctionReturnResult;
public function getHeader() : @tl\_common\Types\rpcResponseHeader;
public function getError() : @tl\_common\Types\rpcResponseError;
public function isError() : bool;
}

/**
* 'KphpRpcRequestsExtraInfo' is a builtin KPHP class. It may accumulate extra information
* about RPC requests sent in both typed and untyped versions of rpc_tl_query builtins.
*/
final class KphpRpcRequestsExtraInfo {
/**
* 'get' returns an array of extra information (request size) about sent RPC requests.
*
* @return tuple(int)[]
*/
public function get ();
}

/** @kphp-extern-func-info interruptible */
function rpc_send_request($actor ::: string, $arr ::: array, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];

/** @kphp-extern-func-info interruptible */
function rpc_send_typed_query_request($actor ::: string, @tl\RpcFunction[] $query_functions, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];

/** @kphp-extern-func-info interruptible */
function rpc_fetch_response($query_ids ::: array) ::: mixed[][];

/** @kphp-extern-func-info interruptible */
function rpc_fetch_typed_response(int[] $query_ids) ::: @tl\RpcResponse[];

/** @kphp-extern-func-info can_throw */
function fetch_int () ::: int;

/** @kphp-extern-func-info can_throw */
function fetch_long () ::: int;

/** @kphp-extern-func-info can_throw */
function fetch_double () ::: float;

/** @kphp-extern-func-info can_throw */
function fetch_string () ::: string;


// === Rpc Old API =================================================================================

/** @kphp-extern-func-info interruptible */
function rpc_tl_query (\RpcConnection $rpc_conn, $arr ::: array, $timeout ::: float = -1.0, $ignore_answer ::: bool = false, \KphpRpcRequestsExtraInfo $requests_extra_info = null, $need_responses_extra_info ::: bool = false) ::: int[];

/** @kphp-extern-func-info interruptible */
function rpc_tl_query_result ($query_ids ::: array) ::: mixed[][];

/** @kphp-extern-func-info interruptible generate-stub */
function typed_rpc_tl_query (\RpcConnection $connection, @tl\RpcFunction[] $query_functions, $timeout ::: float = -1.0, $ignore_answer ::: bool = false, \KphpRpcRequestsExtraInfo $requests_extra_info = null, $need_responses_extra_info ::: bool = false) ::: int[];

/** @kphp-extern-func-info interruptible generate-stub tl_common_h_dep */
function typed_rpc_tl_query_result (int[] $query_ids) ::: @tl\RpcResponse[];

// === Unsupported API =================================================================================

function rpc_parse ($data) ::: bool;

function rpc_clean() ::: bool;
/** @kphp-extern-func-info generate-stub */
function rpc_queue_create ($request_ids ::: mixed = TODO) ::: int;
/** @kphp-extern-func-info generate-stub */
function rpc_queue_empty ($queue_id ::: int) ::: bool;
/** @kphp-extern-func-info generate-stub */
function rpc_queue_next ($queue_id ::: int, $timeout ::: float = -1.0) ::: int | false;
/** @kphp-extern-func-info generate-stub */
function rpc_tl_pending_queries_count () ::: int;

function rpc_tl_query_result_synchronously ($query_ids ::: array) ::: mixed[][];

/** @kphp-extern-func-info generate-stub */
function store_error ($error_code ::: int, $error_text ::: string) ::: bool;
/** @kphp-extern-func-info generate-stub */
function store_int ($v ::: int) ::: bool;
/** @kphp-extern-func-info generate-stub */
function store_long ($v ::: int) ::: bool;
/** @kphp-extern-func-info generate-stub */
function store_string ($v ::: string) ::: bool;
/** @kphp-extern-func-info generate-stub */
function store_finish() ::: bool;

/** @kphp-extern-func-info generate-stub */
function set_fail_rpc_on_int32_overflow ($fail_rpc ::: bool) ::: bool;

/** @kphp-extern-func-info generate-stub */
function rpc_tl_query_one (\RpcConnection $rpc_conn, $arr ::: mixed, $timeout ::: float = -1.0) ::: int;

/** @kphp-extern-func-info can_throw generate-stub */
function rpc_server_fetch_request() ::: @tl\RpcFunction;
/** @kphp-extern-func-info can_throw generate-stub */
function rpc_server_store_response(@tl\RpcFunctionReturnResult $response) ::: void;


/** @kphp-extern-func-info tl_common_h_dep generate-stub */
function typed_rpc_tl_query_result_synchronously (int[] $query_ids) ::: @tl\RpcResponse[];


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

/** @kphp-extern-func-info generate-stub */
function new_rpc_connection ($str ::: string, $port ::: int, $actor_id ::: mixed = 0, $timeout ::: float = 0.3, $connect_timeout ::: float = 0.3, $reconnect_timeout ::: float = 17.0) ::: \RpcConnection; // TODO: make actor_id int


/**
* 'extract_kphp_rpc_response_extra_info' function takes request ID and returns:
* 1. 'null' in case there is no extra information about the request;
* 2. 'tuple(response size, response time)' in case we got a response associated with
* the request ID.
*/
/** @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();
}
1 change: 0 additions & 1 deletion builtin-functions/kphp-light/unsupported-functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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';
Expand Down
9 changes: 9 additions & 0 deletions builtin-functions/kphp-light/unsupported/curl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ define("CURLM_BAD_SOCKET", 5);
define("CURLM_UNKNOWN_OPTION", 6);
define("CURLM_ADDED_ALREADY", 7);

define('UPLOAD_ERR_OK', 0);
define('UPLOAD_ERR_INI_SIZE', 1);
define('UPLOAD_ERR_FORM_SIZE', 2);
define('UPLOAD_ERR_PARTIAL', 3);
define('UPLOAD_ERR_NO_FILE', 4);
define('UPLOAD_ERR_NO_TMP_DIR', 6);
define('UPLOAD_ERR_CANT_WRITE', 7);
define('UPLOAD_ERR_EXTENSION', 8);

/** @kphp-extern-func-info generate-stub */
function curl_init ($url ::: string = "") ::: int;
/** @kphp-extern-func-info generate-stub */
Expand Down
18 changes: 17 additions & 1 deletion builtin-functions/kphp-light/unsupported/error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,25 @@ class Error implements Throwable {
final private function __clone() ::: void;
}

define('E_ERROR', 1);
define('E_WARNING', 2);
define('E_PARSE', 4);
define('E_NOTICE', 8);
define('E_CORE_ERROR', 16);
define('E_CORE_WARNING', 32);
define('E_COMPILE_ERROR', 64);
define('E_COMPILE_WARNING', 128);
define('E_USER_ERROR', 256);
define('E_USER_WARNING', 512);
define('E_USER_NOTICE', 1024);
define('E_STRICT', 2048);
define('E_RECOVERABLE_ERROR', 4096);
define('E_DEPRECATED', 8192);
define('E_USER_DEPRECATED', 16384);
define('E_ALL', 32767);

/** @kphp-extern-func-info generate-stub */
function err ($file ::: string, $line ::: int, $code ::: string, $desc ::: string = '') ::: Exception;
/** @kphp-extern-func-info generate-stub */
function error_get_last() ::: mixed;
/** @kphp-extern-func-info generate-stub */
function error_reporting ($e ::: int = TODO) ::: int;
Expand Down
3 changes: 3 additions & 0 deletions builtin-functions/kphp-light/unsupported/file.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php


define('FILE_APPEND', 1);

/** @kphp-extern-func-info generate-stub */
function basename ($name ::: string, $suffix ::: string = '') ::: string;
/** @kphp-extern-func-info generate-stub */
Expand Down
4 changes: 1 addition & 3 deletions builtin-functions/kphp-light/unsupported/fork.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

/** @kphp-extern-func-info generate-stub */
function wait_concurrently ($id ::: future<any>) ::: bool;

/** @kphp-extern-func-info can_throw generate-stub cpp_template_call */
/** @kphp-extern-func-info can_throw cpp_template_call */
function wait_multi (future<any>[] $resumables) ::: (^1[*][*] | null)[];


function wait_queue_create (array< future<any> | false > $request_ids = []) ::: future_queue<^1[*][*]>;

function wait_queue_push (future_queue<any> &$queue_id, future<any> | false $request_ids) ::: void;
Expand Down
6 changes: 5 additions & 1 deletion builtin-functions/kphp-light/unsupported/kphp-toggles.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

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

/** @kphp-extern-func-info generate-stub */
function set_detect_incorrect_encoding_names_warning(bool $show) ::: void;
Expand All @@ -14,3 +14,7 @@ function set_json_log_demangle_stacktrace(bool $enable) ::: void;

/** @kphp-extern-func-info generate-stub */
function set_migration_php8_warning ($mask ::: int) ::: void;

/** @kphp-extern-func-info generate-stub */
function set_use_updated_gmmktime(bool $enable) ::: void;

Loading

0 comments on commit 16c5af2

Please sign in to comment.