Skip to content
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

add few stubs in runtime-light #1227

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion builtin-functions/kphp-light/error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ define('E_ALL', 32767);
/** @kphp-extern-func-info generate-stub */
function err ($file ::: string, $line ::: int, $code ::: string, $desc ::: string = '') ::: Exception;
function error_get_last() ::: mixed;
/** @kphp-extern-func-info generate-stub */

function error_reporting ($e ::: int = TODO) ::: int;
/** @kphp-extern-func-info generate-stub */
function kphp_backtrace($pretty ::: bool = true) ::: string[];
17 changes: 8 additions & 9 deletions builtin-functions/kphp-light/rpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ function store_float ($v ::: float) ::: bool;
function rpc_tl_pending_queries_count (): int;
function set_fail_rpc_on_int32_overflow ($fail_rpc ::: bool): bool;

/**
* '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.
*/
function extract_kphp_rpc_response_extra_info ($resumable_id ::: int) ::: ?tuple(int, float);

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

/** @kphp-extern-func-info interruptible */
Expand Down Expand Up @@ -134,15 +142,6 @@ 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;
* 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 */
Expand Down
2 changes: 1 addition & 1 deletion builtin-functions/kphp-light/string.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function htmlspecialchars_decode ($str ::: string, $flags ::: int = ENT_COMPAT)


function nl2br ($str ::: string, $is_xhtml ::: bool = true) ::: string;
function number_format ($number ::: float, $decimals ::: int = 0, $dec_point ::: string = '.', $thousands_sep ::: string = ',') ::: string;
function number_format ($number ::: float, $decimals ::: int = 0, $dec_point ::: ?string = '.', $thousands_sep ::: ?string = ',') ::: string;
function ord ($c ::: string) ::: int;

/** @kphp-extern-func-info generate-stub */
Expand Down
4 changes: 4 additions & 0 deletions builtin-functions/kphp-light/system.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
function php_uname($mode ::: string = "a"): string;

function posix_getpid(): int;

function exec($command ::: string, &$output ::: mixed = [], int &$result_code = 0): string|false;

function header_register_callback (callable():void $callback) ::: bool;
8 changes: 7 additions & 1 deletion builtin-functions/kphp-light/unsupported/kml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
/** @kphp-extern-func-info generate-stub */
function kml_get_custom_property(string $model_name, string $property_name): ?string;
/** @kphp-extern-func-info generate-stub */
function kml_xgboost_predict_matrix(string $model_name, float[][] $features_map_matrix): ?float[];
function kml_xgboost_predict_matrix(string $model_name, float[][] $features_map_matrix): ?float[];

/** @kphp-extern-func-info generate-stub */
function kml_model_exists(string $model_name): bool;

/** @kphp-extern-func-info generate-stub */
function kml_catboost_predict_ht(string $model_name, float[] $features_map): ?float;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@



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

function get_engine_version() ::: string;
/** @kphp-extern-func-info generate-stub */

function get_kphp_cluster_name(): string;
/** @kphp-extern-func-info generate-stub */
function get_webserver_stats() ::: tuple(int, int, int, int);
Expand Down Expand Up @@ -80,7 +80,6 @@ define('LC_MESSAGES', 5);
/** @kphp-extern-func-info generate-stub */
function setlocale ($category ::: int, $locale ::: string) ::: string | false;

/** @kphp-extern-func-info generate-stub */
function debug_backtrace() ::: string[][];

function estimate_memory_usage($value ::: any) ::: int;
Expand Down
14 changes: 7 additions & 7 deletions runtime-light/core/globals/php-script-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ inline constexpr std::string_view PHP_AUTH_PW = "PHP_AUTH_PW";
struct PhpScriptBuiltInSuperGlobals {

// variables below are PHP language superglobals
mixed v$_SERVER;
mixed v$_GET;
mixed v$_POST;
mixed v$_ENV;
mixed v$_FILES;
mixed v$_COOKIE;
mixed v$_REQUEST;
mixed v$_SERVER{array<mixed>()};
mixed v$_GET{array<mixed>()};
mixed v$_POST{array<mixed>()};
mixed v$_ENV{array<mixed>()};
mixed v$_FILES{array<mixed>()};
mixed v$_COOKIE{array<mixed>()};
mixed v$_REQUEST{array<mixed>()};

// variables below are not superglobals of the PHP language, but since they are set by runtime,
// the compiler is also aware about them
Expand Down
20 changes: 19 additions & 1 deletion runtime-light/stdlib/array/array-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,25 @@ array<int64_t> f$array_count_values(const array<T> &a) {

template<class T>
array<T> f$array_fill(int64_t start_index, int64_t num, const T &value) {
php_critical_error("call to unsupported function");
if (num < 0) [[unlikely]] {
php_warning("Parameter num of array_fill must not be negative");
return {};
}
if (num == 0) [[unlikely]] {
return {};
}
array<T> result(array_size(num, start_index == 0));

if (result.is_vector()) {
result.fill_vector(num, value);
} else {
result.set_value(start_index, value);
while (--num > 0) {
result.push_back(value);
}
}

return result;
}

template<class T1, class T>
Expand Down
10 changes: 6 additions & 4 deletions runtime-light/stdlib/instance-cache/instance-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#include "runtime-common/core/runtime-core.h"

template<typename ClassInstanceType>
bool f$instance_cache_store(const string & /*key*/, const ClassInstanceType & /*instance*/, int64_t /*ttl*/ = 0) {
php_critical_error("call to unsupported function");
bool f$instance_cache_store(const string & /*key*/, const ClassInstanceType & /*instance*/, int64_t /*ttl*/ = 0) noexcept {
php_warning("called stub instance_cache_store");
return false;
}

template<typename ClassInstanceType>
ClassInstanceType f$instance_cache_fetch(const string & /*class_name*/, const string & /*key*/, bool /*even_if_expired*/ = false) {
php_critical_error("call to unsupported function");
ClassInstanceType f$instance_cache_fetch(const string & /*class_name*/, const string & /*key*/, bool /*even_if_expired*/ = false) noexcept {
php_warning("called stub instance_cache_fetch");
return {};
}
2 changes: 1 addition & 1 deletion runtime-light/stdlib/output/output-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void f$ob_start(const string &callback) noexcept {
}

if (!callback.empty()) {
php_critical_error("unsupported callback %s at buffering level %d", callback.c_str(), httpResponse.current_buffer + 1);
php_warning("unsupported callback %s at buffering level %d", callback.c_str(), httpResponse.current_buffer + 1);
}
++httpResponse.current_buffer;
}
Expand Down
3 changes: 3 additions & 0 deletions runtime-light/stdlib/rpc/rpc-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ array<mixed> make_fetch_error(string &&error_msg, int32_t error_code) {

array<mixed> fetch_function_untyped(const class_instance<RpcTlQuery> &rpc_query) noexcept {
php_assert(!rpc_query.is_null());
if (TlRpcError error{}; error.try_fetch()) [[unlikely]] {
return make_fetch_error(std::move(error.error_msg), error.error_code);
}
CurrentTlQuery::get().set_current_tl_function(rpc_query);
auto fetcher{rpc_query.get()->result_fetcher->extract_untyped_fetcher()};
php_assert(fetcher);
Expand Down
5 changes: 5 additions & 0 deletions runtime-light/stdlib/rpc/rpc-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ task_t<array<int64_t>> f$rpc_send_typed_query_requests(string actor, array<class

task_t<array<array<mixed>>> f$rpc_fetch_responses(array<int64_t> query_ids) noexcept;

template<class T>
task_t<array<array<mixed>>> f$rpc_fetch_responses(const array<T> &query_ids) noexcept {
co_return co_await f$rpc_fetch_responses(array<int64_t>::convert_from(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$rpc_fetch_typed_responses(array<query_id_t> query_ids) noexcept {
Expand Down
10 changes: 10 additions & 0 deletions runtime-light/stdlib/server/args-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ inline Optional<string> f$ini_get(const string &key) noexcept {
const auto &component_st{ComponentState::get()};
return component_st.ini_opts.has_key(key) ? Optional<string>{component_st.ini_opts.get_value(key)} : Optional<string>{false};
}

inline string f$get_engine_version() noexcept {
php_warning("called stub get_engine_version");
return {};
}

inline string f$get_kphp_cluster_name() noexcept {
php_warning("called stub get_kphp_cluster_name");
return string("adm512");
}
6 changes: 6 additions & 0 deletions runtime-light/stdlib/server/handler-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ requires(std::invocable<F, Args...>) void f$register_shutdown_function(F &&f, Ar
std::forward<F>(f), std::forward<Args>(args)...)};
InstanceState::get().shutdown_functions.emplace_back(std::move(shutdown_function_task));
}

template<typename F>
void f$register_kphp_on_warning_callback(F && /*callback*/) {
php_warning("called stub register_kphp_on_warning_callback");
}

25 changes: 20 additions & 5 deletions runtime-light/stdlib/system/system-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ int64_t f$estimate_memory_usage(const T & /*unused*/) {
php_critical_error("call to unsupported function");
}

template<typename F>
void f$register_kphp_on_warning_callback(F && /*callback*/) {
php_critical_error("call to unsupported function");
}

template<typename F>
bool f$register_kphp_on_oom_callback(F && /*callback*/) {
php_critical_error("call to unsupported function");
Expand Down Expand Up @@ -69,3 +64,23 @@ inline string f$php_uname(const string &mode = string{1, 'a'}) noexcept {
return image_st.uname_info_a;
}
}

inline array<array<string>> f$debug_backtrace() noexcept {
php_warning("called stub debug_backtrace");
return {};
}

template<typename F>
bool f$header_register_callback(F &&) {
php_warning("called stub header_register_callback");
return true;
}

inline Optional<string> f$exec([[maybe_unused]] const string &command) noexcept {
php_critical_error("call to unsupported function");
}

inline Optional<string> f$exec([[maybe_unused]] const string &command, [[maybe_unused]] mixed &output,
[[maybe_unused]] int64_t &result_code = SystemInstanceState::get().result_code_dummy) noexcept {
php_critical_error("call to unsupported function");
}
19 changes: 19 additions & 0 deletions runtime-light/utils/php-warning.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2025 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#pragma once

#include <cstdint>

#include "runtime-common/core/utils/kphp-assert-core.h"

inline int64_t f$error_reporting([[maybe_unused]] int64_t level) noexcept {
php_warning("called stub error_reporting");
return 0;
}

inline int64_t f$error_reporting() noexcept {
php_warning("called stub error_reporting");
return 0;
}
Loading