Skip to content

Commit

Permalink
[k2] add stubs for some builtins (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov authored Dec 12, 2024
1 parent 87cd922 commit 02cdacf
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

// === SUPPORTED ===

function kphp_set_context_on_error(mixed[] $tags, mixed $extra_info, string $env = "") ::: void;

// === UNSUPPORTED ===

/** @kphp-generate-stub-class */
interface Throwable {
public function getMessage () ::: string;
Expand Down Expand Up @@ -92,6 +98,3 @@ function error_get_last() ::: mixed;
function error_reporting ($e ::: int = TODO) ::: int;
/** @kphp-extern-func-info generate-stub */
function kphp_backtrace($pretty ::: bool = true) ::: string[];
/** @kphp-extern-func-info generate-stub */
function kphp_set_context_on_error(mixed[] $tags, mixed $extra_info, string $env = "") ::: void;

1 change: 1 addition & 0 deletions builtin-functions/kphp-light/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once __DIR__ . '/array.txt';
require_once __DIR__ . '/confdata.txt';
require_once __DIR__ . '/crypto.txt';
require_once __DIR__ . '/error.txt';
require_once __DIR__ . '/file.txt';
require_once __DIR__ . '/hash.txt';
require_once __DIR__ . '/job-workers.txt';
Expand Down
14 changes: 7 additions & 7 deletions builtin-functions/kphp-light/rpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ final class KphpRpcRequestsExtraInfo {
/** @kphp-extern-func-info interruptible */
function rpc_send_requests($actor ::: string, $arr ::: array, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];

/** @kphp-extern-func-info interruptible */
/** @kphp-extern-func-info tl_common_h_dep interruptible */
function rpc_send_typed_query_requests($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_responses($query_ids ::: array) ::: mixed[][];

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

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

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

Expand All @@ -62,7 +65,6 @@ function store_string ($v ::: string) ::: bool;
function store_double ($v ::: float) ::: bool;
function store_float ($v ::: float) ::: bool;


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

/** @kphp-extern-func-info interruptible */
Expand Down Expand Up @@ -108,24 +110,22 @@ function rpc_tl_query_one (\RpcConnection $rpc_conn, $arr ::: mixed, $timeout ::

/** @kphp-extern-func-info can_throw interruptible generate-stub */
function rpc_server_fetch_request() ::: @tl\RpcFunction;

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


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

/** @kphp-extern-func-info tl_common_h_dep interruptible generate-stub */
function typed_rpc_tl_query_result_one (int $query_id) ::: @tl\RpcResponse;


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

/** @kphp-extern-func-info interruptible 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;
Expand Down
4 changes: 3 additions & 1 deletion builtin-functions/kphp-light/server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ function base64_encode ($str ::: string): string;

function parse_url ($str ::: string, $component ::: int = -1): mixed;

function header ($str ::: string, $replace ::: bool = true, $http_response_code ::: int = 0) ::: void;
function header ($str ::: string, $replace ::: bool = true, $http_response_code ::: int = 0): void;

function numa_get_bound_node(): int;
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 @@ -2,7 +2,6 @@

require_once __DIR__ . '/unsupported/arrays.txt';
require_once __DIR__ . '/unsupported/curl.txt';
require_once __DIR__ . '/unsupported/error.txt';
require_once __DIR__ . '/unsupported/fork.txt';
require_once __DIR__ . '/unsupported/kml.txt';
require_once __DIR__ . '/unsupported/kphp-tracing.txt';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ function get_engine_version() ::: string;
function get_kphp_cluster_name(): string;
/** @kphp-extern-func-info generate-stub */
function get_webserver_stats() ::: tuple(int, int, int, int);
/** @kphp-extern-func-info generate-stub */
function numa_get_bound_node(): int;

/** @kphp-extern-func-info generate-stub */
function iconv ($input_encoding ::: string, $output_encoding ::: string, $input_str ::: string) ::: string | false;
Expand Down
12 changes: 12 additions & 0 deletions runtime-light/stdlib/rpc/rpc-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ f$rpc_fetch_typed_responses(array<query_id_t> query_ids) noexcept {
co_return res;
}

template<std::same_as<int64_t> query_id_t = int64_t, std::same_as<RpcResponseErrorFactory> error_factory_t = RpcResponseErrorFactory>
requires std::default_initializable<error_factory_t> task_t<array<class_instance<C$VK$TL$RpcResponse>>>
f$rpc_fetch_typed_responses_synchronously(array<query_id_t> query_ids) noexcept {
co_return co_await f$rpc_fetch_typed_responses(std::move(query_ids));
}

template<std::same_as<int64_t> query_id_t = int64_t, std::same_as<RpcResponseErrorFactory> error_factory_t = RpcResponseErrorFactory>
requires std::default_initializable<error_factory_t> task_t<array<class_instance<C$VK$TL$RpcResponse>>>
f$typed_rpc_tl_query_result_synchronously(array<query_id_t> query_ids) noexcept {
co_return co_await f$rpc_fetch_typed_responses_synchronously(std::move(query_ids));
}

template<class T>
task_t<array<array<mixed>>> f$rpc_tl_query_result(const array<T> &) {
php_critical_error("call to unsupported function");
Expand Down
7 changes: 7 additions & 0 deletions runtime-light/stdlib/system/system-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ inline Optional<array<mixed>> f$getopt(const string &options, array<string> long
Optional<int64_t> &rest_index = SystemInstanceState::get().rest_index_dummy) {
php_critical_error("call to unsupported function");
}

inline int64_t f$numa_get_bound_node() noexcept {
return -1;
}

inline void f$kphp_set_context_on_error([[maybe_unused]] const array<mixed> &tags, [[maybe_unused]] const array<mixed> &extra_info,
[[maybe_unused]] const string &env = {}) noexcept {}

0 comments on commit 02cdacf

Please sign in to comment.