From 335572490a28616554626748c014153253e25002 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Tue, 3 Sep 2024 17:45:00 +0300 Subject: [PATCH 01/16] make phpt work --- builtin-functions/kphp-light/unsupported/math.txt | 2 ++ builtin-functions/kphp-light/unsupported/string.txt | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin-functions/kphp-light/unsupported/math.txt b/builtin-functions/kphp-light/unsupported/math.txt index 52c6582f89..2021fcb343 100644 --- a/builtin-functions/kphp-light/unsupported/math.txt +++ b/builtin-functions/kphp-light/unsupported/math.txt @@ -166,4 +166,6 @@ function is_infinite ($v ::: float) ::: bool; function is_nan ($v ::: float) ::: bool; /** @kphp-extern-func-info generate-stub */ function random_int($l ::: int, $r ::: int) ::: int | false; +/** @kphp-extern-func-info generate-stub */ +function random_bytes($length ::: int) ::: string | false; diff --git a/builtin-functions/kphp-light/unsupported/string.txt b/builtin-functions/kphp-light/unsupported/string.txt index c343f50ae4..e5d4a9a755 100644 --- a/builtin-functions/kphp-light/unsupported/string.txt +++ b/builtin-functions/kphp-light/unsupported/string.txt @@ -61,7 +61,8 @@ function strtolower ($str ::: string) ::: string; function strtoupper ($str ::: string) ::: string; /** @kphp-extern-func-info generate-stub */ function wordwrap ($str ::: string, $width ::: int = 75, $break ::: string = '\n', $cut ::: bool = false) ::: string; - +/** @kphp-extern-func-info generate-stub */ +function str_getcsv($str ::: string, string $delimiter ::: string = ",", string $enclosure ::: string = "\"", string $escape ::: string = "\\") ::: mixed[] | false; /** From bb4bdadce04b7c0afb1f81b6302e263a7ac65270 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Mon, 21 Oct 2024 15:01:36 +0300 Subject: [PATCH 02/16] fix runtime issues --- runtime-light/allocator/runtime-light-allocator.cpp | 4 ++++ runtime-light/stdlib/output/output-buffer.cpp | 2 +- runtime-light/utils/panic.cpp | 5 ++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime-light/allocator/runtime-light-allocator.cpp b/runtime-light/allocator/runtime-light-allocator.cpp index 6002b78ca2..9823a9bca4 100644 --- a/runtime-light/allocator/runtime-light-allocator.cpp +++ b/runtime-light/allocator/runtime-light-allocator.cpp @@ -103,6 +103,10 @@ void *RuntimeAllocator::realloc_script_memory(void *mem, size_t new_size, size_t void RuntimeAllocator::free_script_memory(void *mem, size_t size) noexcept { php_assert(size); + if (unlikely(!is_script_allocator_available())) { + free_global_memory(mem, size); + return; + } ComponentState &rt_ctx = *get_component_context(); rt_ctx.runtime_allocator.memory_resource.deallocate(mem, size); diff --git a/runtime-light/stdlib/output/output-buffer.cpp b/runtime-light/stdlib/output/output-buffer.cpp index 4529abd8e6..91675a1645 100644 --- a/runtime-light/stdlib/output/output-buffer.cpp +++ b/runtime-light/stdlib/output/output-buffer.cpp @@ -60,7 +60,7 @@ Optional f$ob_get_clean() noexcept { return httpResponse.output_buffers[httpResponse.current_buffer].str(); } -string f$ob_get_content() { +string f$ob_get_contents() noexcept { Response &httpResponse{get_component_context()->response}; return httpResponse.output_buffers[httpResponse.current_buffer].str(); } diff --git a/runtime-light/utils/panic.cpp b/runtime-light/utils/panic.cpp index bec6d7aa52..0416135fc3 100644 --- a/runtime-light/utils/panic.cpp +++ b/runtime-light/utils/panic.cpp @@ -13,11 +13,10 @@ void critical_error_handler() { constexpr const char *message = "script panic"; const auto &platform_ctx = *get_platform_context(); - auto &component_ctx = *get_component_context(); platform_ctx.log(Debug, strlen(message), message); - if (component_ctx.poll_status != PollStatus::PollFinishedOk && component_ctx.poll_status != PollStatus::PollFinishedError) { - component_ctx.poll_status = PollStatus::PollFinishedError; + if (get_component_context() != nullptr) { + get_component_context()->poll_status = PollStatus::PollFinishedError; } platform_ctx.abort(); exit(1); From c06e4472434f80c63a0dad6a717602383fcd0c33 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Mon, 28 Oct 2024 18:05:45 +0300 Subject: [PATCH 03/16] add math functions --- .../kphp-light/unsupported/math.txt | 8 -- runtime-light/stdlib/math/math-functions.cpp | 37 ++++++ runtime-light/stdlib/math/math-functions.h | 119 ++++++++++++++++++ runtime-light/stdlib/math/math.h | 61 --------- runtime-light/stdlib/stdlib.cmake | 1 + 5 files changed, 157 insertions(+), 69 deletions(-) create mode 100644 runtime-light/stdlib/math/math-functions.cpp create mode 100644 runtime-light/stdlib/math/math-functions.h delete mode 100644 runtime-light/stdlib/math/math.h diff --git a/builtin-functions/kphp-light/unsupported/math.txt b/builtin-functions/kphp-light/unsupported/math.txt index 2021fcb343..0c22f918d4 100644 --- a/builtin-functions/kphp-light/unsupported/math.txt +++ b/builtin-functions/kphp-light/unsupported/math.txt @@ -38,17 +38,14 @@ function atan ($v ::: float) ::: float; */ function atan2 ($y ::: float, $x ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function ceil ($v ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function cos ($v ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function deg2rad ($v ::: float) ::: float; @@ -58,7 +55,6 @@ function deg2rad ($v ::: float) ::: float; */ function exp ($v ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function floor ($v ::: float) ::: float; @@ -68,12 +64,10 @@ function floor ($v ::: float) ::: float; */ function fmod ($x ::: float, $y ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function log ($v ::: float, $base ::: float = 2.7182818284590452353602874713527) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function round ($v ::: float, $precision ::: int = 0) ::: float; @@ -83,7 +77,6 @@ function round ($v ::: float, $precision ::: int = 0) ::: float; */ function sin ($v ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function sqrt ($v ::: float) ::: float; @@ -93,7 +86,6 @@ function sqrt ($v ::: float) ::: float; */ function tan ($v ::: float) ::: float; /** - * @kphp-extern-func-info generate-stub * @kphp-pure-function */ function pi() ::: float; diff --git a/runtime-light/stdlib/math/math-functions.cpp b/runtime-light/stdlib/math/math-functions.cpp new file mode 100644 index 0000000000..e1e7b54262 --- /dev/null +++ b/runtime-light/stdlib/math/math-functions.cpp @@ -0,0 +1,37 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2024 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#include "runtime-light/stdlib/math/math-functions.h" + +#include + +mixed f$abs(const mixed &v) { + mixed num = v.to_numeric(); + if (num.is_int()) { + return std::abs(num.to_int()); + } + return fabs(num.to_float()); +} + +int64_t f$abs(int64_t v) { + return std::abs(v); +} + +double f$abs(double v) { + return std::abs(v); +} + +int64_t f$abs(const Optional &v) { + return f$abs(val(v)); +} + +int64_t f$abs(const Optional &v) { + return f$abs(static_cast(val(v))); +} + +double f$abs(const Optional &v) { + return f$abs(val(v)); +} + + diff --git a/runtime-light/stdlib/math/math-functions.h b/runtime-light/stdlib/math/math-functions.h new file mode 100644 index 0000000000..5465cb1b4b --- /dev/null +++ b/runtime-light/stdlib/math/math-functions.h @@ -0,0 +1,119 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2024 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#include "runtime-common/core/runtime-core.h" + +mixed f$abs(const mixed &v); +int64_t f$abs(int64_t v); +double f$abs(double v); +int64_t f$abs(const Optional &v); +int64_t f$abs(const Optional &v); +double f$abs(const Optional &v); + +inline double f$ceil(double v) { + return ceil(v); +} + +inline double f$cos(double v) { + return cos(v); +} + +inline double f$deg2rad(double v) { + return v * M_PI / 180; +} + +inline double f$floor(double v) { + return floor(v); +} + +inline double f$log(double v) { + if (v <= 0.0) { + return 0.0; + } + return log(v); +} + +inline double f$log(double v, double base) { + if (v <= 0.0 || base <= 0.0 || fabs(base - 1.0) < 1e-9) { + return 0.0; + } + return log(v) / log(base); +} + +template +T f$min(const array &a) { + if (a.count() == 0) { + php_warning("Empty array specified to function min"); + return T(); + } + + typename array::const_iterator p = a.begin(); + T res = p.get_value(); + for (++p; p != a.end(); ++p) { + if (lt(p.get_value(), res)) { + res = p.get_value(); + } + } + return res; +} + +template +T f$max(const array &a) { + if (a.count() == 0) { + php_warning("Empty array specified to function max"); + return T(); + } + + typename array::const_iterator p = a.begin(); + T res = p.get_value(); + for (++p; p != a.end(); ++p) { + if (lt(res, p.get_value())) { + res = p.get_value(); + } + } + return res; +} + +template +T f$min(const T &arg1) { + return arg1; +} + +template +T f$min(const T &arg1, const T &arg2, Args&& ...args) { + return f$min(lt(arg1, arg2) ? arg1 : arg2, std::forward(args)...); +} + +template +T f$max(const T &arg1) { + return arg1; +} + +template +T f$max(const T &arg1, const T &arg2, Args&& ...args) { + return f$max(lt(arg2, arg1) ? arg1 : arg2, std::forward(args)...); +} + +inline double f$pi() { + return M_PI; +} + +inline double f$round(double v, int64_t precision = 0) { + if (std::abs(precision) > 100) { + php_warning("Wrong parameter precision (%" PRIi64 ") in function round", precision); + return v; + } + + double mul = pow(10.0, (double)precision); + return round(v * mul) / mul; +} + +inline double f$sqrt(double v) { + if (v < 0) { + return 0.0; + } + return sqrt(v); +} \ No newline at end of file diff --git a/runtime-light/stdlib/math/math.h b/runtime-light/stdlib/math/math.h deleted file mode 100644 index a559a18228..0000000000 --- a/runtime-light/stdlib/math/math.h +++ /dev/null @@ -1,61 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2024 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#pragma once - -#include "runtime-common/core/runtime-core.h" - -inline mixed f$abs(const mixed &v) { - php_critical_error("call to unsupported function"); -} - -inline int64_t f$abs(int64_t v) { - php_critical_error("call to unsupported function"); -} - -inline double f$abs(double v) { - php_critical_error("call to unsupported function"); -} - -inline int64_t f$abs(const Optional &v) { - php_critical_error("call to unsupported function"); -} - -inline int64_t f$abs(const Optional &v) { - php_critical_error("call to unsupported function"); -} - -inline double f$abs(const Optional &v) { - php_critical_error("call to unsupported function"); -} - -template -T f$min(const array &a) { - php_critical_error("call to unsupported function"); -} - -template -T f$max(const array &a) { - php_critical_error("call to unsupported function"); -} - -template -T f$min(const T &arg1) { - php_critical_error("call to unsupported function"); -} - -template -T f$min(const T &arg1, const T &arg2, Args&&... args) { - php_critical_error("call to unsupported function"); -} - -template -T f$max(const T &arg1) { - php_critical_error("call to unsupported function"); -} - -template -T f$max(const T &arg1, const T &arg2, Args&&... args) { - php_critical_error("call to unsupported function"); -} diff --git a/runtime-light/stdlib/stdlib.cmake b/runtime-light/stdlib/stdlib.cmake index 31d2714f42..40fb78f457 100644 --- a/runtime-light/stdlib/stdlib.cmake +++ b/runtime-light/stdlib/stdlib.cmake @@ -11,6 +11,7 @@ prepend( hash/hash-functions.cpp job-worker/job-worker-api.cpp job-worker/job-worker-client-context.cpp + math/math-functions.cpp output/output-buffer.cpp output/print-functions.cpp regex/regex-context.cpp From 1df9b7a9afc904b00da84de9bc60bcd5e564b0c5 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Tue, 29 Oct 2024 17:04:34 +0300 Subject: [PATCH 04/16] add some .txt --- builtin-functions/kphp-light/rpc.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin-functions/kphp-light/rpc.txt b/builtin-functions/kphp-light/rpc.txt index 435146e2dc..79da29c5fc 100644 --- a/builtin-functions/kphp-light/rpc.txt +++ b/builtin-functions/kphp-light/rpc.txt @@ -83,6 +83,8 @@ 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_queue_push ($queue_id ::: int, $request_ids ::: mixed) ::: int; +/** @kphp-extern-func-info generate-stub */ function rpc_tl_pending_queries_count () ::: int; function rpc_tl_query_result_synchronously ($query_ids ::: array) ::: mixed[][]; @@ -113,6 +115,9 @@ function rpc_server_store_response(@tl\RpcFunctionReturnResult $response) ::: vo /** @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 tl_common_h_dep generate-stub */ +function typed_rpc_tl_query_result_one (int $query_id) ::: @tl\RpcResponse; + /** @kphp-extern-func-info generate-stub can_throw */ function fetch_lookup_int () ::: int; From efe49b14c0b4c64213dc92a04407447bfb904a9c Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Wed, 30 Oct 2024 14:51:55 +0300 Subject: [PATCH 05/16] add #ifndef --- compiler/lexer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/lexer.cpp b/compiler/lexer.cpp index aee442b81a..4839a4ac54 100644 --- a/compiler/lexer.cpp +++ b/compiler/lexer.cpp @@ -18,6 +18,7 @@ #include "compiler/stage.h" #include "compiler/threading/thread-id.h" +#include "compiler/compiler-core.h" /*** LexerData @@ -1018,7 +1019,8 @@ bool TokenLexerComment::parse(LexerData *lexer_data) const { } bool TokenLexerIfndefComment::parse(LexerData *lexer_data) const { - kphp_assert(lexer_data->get_code_view().starts_with("#ifndef KPHP")); + kphp_assert(lexer_data->get_code_view().starts_with("#ifndef KPHP") + || (lexer_data->get_code_view().starts_with("#ifndef K2") && G->is_output_mode_k2())); auto endif_pos = lexer_data->get_code_view().find("#endif"); if (endif_pos == vk::string_view::npos) { @@ -1126,6 +1128,9 @@ void TokenLexerPHP::init() { h->add_rule("/*|//|#", &vk::singleton::get()); h->add_simple_rule("#ifndef KPHP", &vk::singleton::get()); + if (G->is_output_mode_k2()) { + h->add_simple_rule("#ifndef K2", &vk::singleton::get()); + } h->add_simple_rule("\'", &vk::singleton::get()); h->add_simple_rule("\"", &vk::singleton::get()); h->add_simple_rule("<<<", &vk::singleton::get()); From 9fe7c3da4d0ee9cf6922b65f852126c42f47392d Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Thu, 31 Oct 2024 19:04:42 +0300 Subject: [PATCH 06/16] fix #ifndef --- compiler/compiler.cpp | 3 +++ compiler/lexer.cpp | 10 ++++++---- compiler/lexer.h | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/compiler.cpp b/compiler/compiler.cpp index 98ff1101e1..d4fdbd826b 100644 --- a/compiler/compiler.cpp +++ b/compiler/compiler.cpp @@ -196,6 +196,9 @@ bool compiler_execute(CompilerSettings *settings) { //TODO: call it with pthread_once on need lexer_init(); + if (G->is_output_mode_k2()) { + k2_lexer_init(); + } OpInfo::init_static(); MultiKey::init_static(); TypeData::init_static(); diff --git a/compiler/lexer.cpp b/compiler/lexer.cpp index 4839a4ac54..c8f98f6d80 100644 --- a/compiler/lexer.cpp +++ b/compiler/lexer.cpp @@ -1020,7 +1020,7 @@ bool TokenLexerComment::parse(LexerData *lexer_data) const { bool TokenLexerIfndefComment::parse(LexerData *lexer_data) const { kphp_assert(lexer_data->get_code_view().starts_with("#ifndef KPHP") - || (lexer_data->get_code_view().starts_with("#ifndef K2") && G->is_output_mode_k2())); + || lexer_data->get_code_view().starts_with("#ifndef K2")); auto endif_pos = lexer_data->get_code_view().find("#endif"); if (endif_pos == vk::string_view::npos) { @@ -1128,9 +1128,6 @@ void TokenLexerPHP::init() { h->add_rule("/*|//|#", &vk::singleton::get()); h->add_simple_rule("#ifndef KPHP", &vk::singleton::get()); - if (G->is_output_mode_k2()) { - h->add_simple_rule("#ifndef K2", &vk::singleton::get()); - } h->add_simple_rule("\'", &vk::singleton::get()); h->add_simple_rule("\"", &vk::singleton::get()); h->add_simple_rule("<<<", &vk::singleton::get()); @@ -1256,6 +1253,11 @@ void lexer_init() { vk::singleton::get().init(); } +void k2_lexer_init() { + auto & h = vk::singleton::get().h; + h->add_simple_rule("#ifndef K2", &vk::singleton::get()); +} + std::vector php_text_to_tokens(vk::string_view text) { static TokenLexerGlobal lexer; diff --git a/compiler/lexer.h b/compiler/lexer.h index 0665247f76..6b9042ba7f 100644 --- a/compiler/lexer.h +++ b/compiler/lexer.h @@ -200,5 +200,6 @@ struct TokenLexerGlobal final : TokenLexer { }; void lexer_init(); +void k2_lexer_init(); std::vector php_text_to_tokens(vk::string_view text); std::vector phpdoc_to_tokens(vk::string_view text); From 35381901ad61b8caa0216576244720afd276a54d Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Sat, 2 Nov 2024 15:49:26 +0300 Subject: [PATCH 07/16] move some math functions --- .../stdlib/math/math-functions.cpp | 4 +- .../stdlib/math/math-functions.h | 38 ++++- runtime-common/stdlib/stdlib.cmake | 3 +- runtime-light/stdlib/math/random-functions.h | 7 - runtime-light/stdlib/stdlib.cmake | 1 - runtime/math_functions.cpp | 10 -- runtime/math_functions.h | 146 +----------------- 7 files changed, 42 insertions(+), 167 deletions(-) rename {runtime-light => runtime-common}/stdlib/math/math-functions.cpp (89%) rename {runtime-light => runtime-common}/stdlib/math/math-functions.h (75%) delete mode 100644 runtime-light/stdlib/math/random-functions.h diff --git a/runtime-light/stdlib/math/math-functions.cpp b/runtime-common/stdlib/math/math-functions.cpp similarity index 89% rename from runtime-light/stdlib/math/math-functions.cpp rename to runtime-common/stdlib/math/math-functions.cpp index e1e7b54262..144a912f6f 100644 --- a/runtime-light/stdlib/math/math-functions.cpp +++ b/runtime-common/stdlib/math/math-functions.cpp @@ -2,9 +2,9 @@ // Copyright (c) 2024 LLC «V Kontakte» // Distributed under the GPL v3 License, see LICENSE.notice.txt -#include "runtime-light/stdlib/math/math-functions.h" +#include "runtime-common/stdlib/math/math-functions.h" -#include +#include mixed f$abs(const mixed &v) { mixed num = v.to_numeric(); diff --git a/runtime-light/stdlib/math/math-functions.h b/runtime-common/stdlib/math/math-functions.h similarity index 75% rename from runtime-light/stdlib/math/math-functions.h rename to runtime-common/stdlib/math/math-functions.h index 5465cb1b4b..ed99ebe888 100644 --- a/runtime-light/stdlib/math/math-functions.h +++ b/runtime-common/stdlib/math/math-functions.h @@ -6,6 +6,42 @@ #include "runtime-common/core/runtime-core.h" +inline double f$ceil(double v); + +inline double f$cos(double v); + +inline double f$deg2rad(double v); + +inline double f$floor(double v); + +inline double f$log(double v); + +inline double f$log(double v, double base); + +template +inline T f$min(const array &a); + +template +inline T f$max(const array &a); + +template +inline T f$min(const T &arg1); + +template +inline T f$min(const T &arg1, const T &arg2, Args&&... args); + +template +inline T f$max(const T &arg1); + +template +inline T f$max(const T &arg1, const T &arg2, Args&&... args); + +inline double f$pi(); + +inline double f$round(double v, int64_t precision = 0); + +inline double f$sqrt(double v); + mixed f$abs(const mixed &v); int64_t f$abs(int64_t v); double f$abs(double v); @@ -101,7 +137,7 @@ inline double f$pi() { return M_PI; } -inline double f$round(double v, int64_t precision = 0) { +inline double f$round(double v, int64_t precision) { if (std::abs(precision) > 100) { php_warning("Wrong parameter precision (%" PRIi64 ") in function round", precision); return v; diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index 7b4e259f9c..05a109ae7f 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -1,4 +1,5 @@ prepend(STDLIB_STRING stdlib/string/ string-functions.cpp mbstring-functions.cpp) +prepend(STDLIB_MATH stdlib/math/ math-functions.cpp) -set(STDLIB_SRC "${STDLIB_STRING}") +set(STDLIB_SRC ${STDLIB_STRING} ${STDLIB_MATH}) diff --git a/runtime-light/stdlib/math/random-functions.h b/runtime-light/stdlib/math/random-functions.h deleted file mode 100644 index ba5dfa3ecb..0000000000 --- a/runtime-light/stdlib/math/random-functions.h +++ /dev/null @@ -1,7 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2024 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#include -#include - diff --git a/runtime-light/stdlib/stdlib.cmake b/runtime-light/stdlib/stdlib.cmake index 40fb78f457..31d2714f42 100644 --- a/runtime-light/stdlib/stdlib.cmake +++ b/runtime-light/stdlib/stdlib.cmake @@ -11,7 +11,6 @@ prepend( hash/hash-functions.cpp job-worker/job-worker-api.cpp job-worker/job-worker-client-context.cpp - math/math-functions.cpp output/output-buffer.cpp output/print-functions.cpp regex/regex-context.cpp diff --git a/runtime/math_functions.cpp b/runtime/math_functions.cpp index 928b5ad87a..6e358065f9 100644 --- a/runtime/math_functions.cpp +++ b/runtime/math_functions.cpp @@ -358,16 +358,6 @@ string f$base_convert(const string &number, int64_t frombase, int64_t tobase) { return result; } -double f$round(double v, int64_t precision) { - if (std::abs(precision) > 100) { - php_warning("Wrong parameter precision (%" PRIi64 ") in function round", precision); - return v; - } - - double mul = pow(10.0, (double)precision); - return round(v * mul) / mul; -} - void init_math_functions() noexcept { MTRandGenerator::get().lazy_init(); } diff --git a/runtime/math_functions.h b/runtime/math_functions.h index 9102d45fbb..4da9b71a0b 100644 --- a/runtime/math_functions.h +++ b/runtime/math_functions.h @@ -5,6 +5,7 @@ #pragma once #include "runtime-common/core/runtime-core.h" +#include "runtime-common/stdlib/math/math-functions.h" int64_t f$bindec(const string &number) noexcept; @@ -38,43 +39,12 @@ Optional f$random_int(int64_t l, int64_t r) noexcept; Optional f$random_bytes(int64_t length) noexcept; - -template -inline T f$min(const array &a); - -template -inline T f$max(const array &a); - -template -inline T f$min(const T &arg1); - -template -inline T f$min(const T &arg1, const T &arg2, Args&&... args); - -template -inline T f$max(const T &arg1); - -template -inline T f$max(const T &arg1, const T &arg2, Args&&... args); - // TODO REMOVE? constexpr int64_t PHP_ROUND_HALF_UP = 123423141; constexpr int64_t PHP_ROUND_HALF_DOWN = 123423144; constexpr int64_t PHP_ROUND_HALF_EVEN = 123423145; constexpr int64_t PHP_ROUND_HALF_ODD = 123423146; -mixed f$abs(const mixed &v); - -int64_t f$abs(int64_t v); - -double f$abs(double v); - -int64_t f$abs(const Optional &v); - -int64_t f$abs(const Optional &v); - -double f$abs(const Optional &v); - inline double f$acos(double v); inline double f$atan(double v); @@ -83,20 +53,12 @@ inline double f$atan2(double y, double x); string f$base_convert(const string &number, int64_t frombase, int64_t tobase); -inline double f$ceil(double v); - -inline double f$cos(double v); - inline double f$cosh(double v); inline double f$acosh(double v); -inline double f$deg2rad(double v); - inline double f$exp(double v); -inline double f$floor(double v); - inline double f$fmod(double x, double y); inline bool f$is_finite(double v); @@ -105,20 +67,10 @@ inline bool f$is_infinite(double v); inline bool f$is_nan(double v); -inline double f$log(double v); - -inline double f$log(double v, double base); - -inline double f$pi(); - -double f$round(double v, int64_t precision = 0); - inline double f$sin(double v); inline double f$sinh(double v); -inline double f$sqrt(double v); - inline double f$tan(double v); inline double f$asin(double v); @@ -135,61 +87,6 @@ void init_math_functions() noexcept; * */ - -template -T f$min(const array &a) { - if (a.count() == 0) { - php_warning("Empty array specified to function min"); - return T(); - } - - typename array::const_iterator p = a.begin(); - T res = p.get_value(); - for (++p; p != a.end(); ++p) { - if (lt(p.get_value(), res)) { - res = p.get_value(); - } - } - return res; -} - -template -T f$max(const array &a) { - if (a.count() == 0) { - php_warning("Empty array specified to function max"); - return T(); - } - - typename array::const_iterator p = a.begin(); - T res = p.get_value(); - for (++p; p != a.end(); ++p) { - if (lt(res, p.get_value())) { - res = p.get_value(); - } - } - return res; -} - -template -T f$min(const T &arg1) { - return arg1; -} - -template -T f$min(const T &arg1, const T &arg2, Args&& ...args) { - return f$min(lt(arg1, arg2) ? arg1 : arg2, std::forward(args)...); -} - -template -T f$max(const T &arg1) { - return arg1; -} - -template -T f$max(const T &arg1, const T &arg2, Args&& ...args) { - return f$max(lt(arg2, arg1) ? arg1 : arg2, std::forward(args)...); -} - double f$acos(double v) { return acos(v); } @@ -202,14 +99,6 @@ double f$atan2(double y, double x) { return atan2(y, x); } -double f$ceil(double v) { - return ceil(v); -} - -double f$cos(double v) { - return cos(v); -} - double f$cosh(double v) { return cosh(v); } @@ -218,18 +107,10 @@ double f$acosh(double v) { return acosh(v); } -double f$deg2rad(double v) { - return v * M_PI / 180; -} - double f$exp(double v) { return exp(v); } -double f$floor(double v) { - return floor(v); -} - double f$fmod(double x, double y) { if (fabs(x) > 1e100 || fabs(y) < 1e-100) { return 0.0; @@ -250,24 +131,6 @@ bool f$is_nan(double v) { return (std::fpclassify(v) == FP_NAN); } -double f$log(double v) { - if (v <= 0.0) { - return 0.0; - } - return log(v); -} - -double f$log(double v, double base) { - if (v <= 0.0 || base <= 0.0 || fabs(base - 1.0) < 1e-9) { - return 0.0; - } - return log(v) / log(base); -} - -double f$pi() { - return M_PI; -} - double f$sin(double v) { return sin(v); } @@ -276,13 +139,6 @@ double f$sinh(double v) { return sinh(v); } -double f$sqrt(double v) { - if (v < 0) { - return 0.0; - } - return sqrt(v); -} - double f$tan(double v) { return tan(v); } From 32406b7d7714544de63f1171b2ec8f9924062771 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Sat, 2 Nov 2024 15:57:11 +0300 Subject: [PATCH 08/16] add newline --- runtime-common/stdlib/math/math-functions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-common/stdlib/math/math-functions.h b/runtime-common/stdlib/math/math-functions.h index ed99ebe888..60987c373c 100644 --- a/runtime-common/stdlib/math/math-functions.h +++ b/runtime-common/stdlib/math/math-functions.h @@ -152,4 +152,4 @@ inline double f$sqrt(double v) { return 0.0; } return sqrt(v); -} \ No newline at end of file +} From 67a6200ffe68a0e85f9774fa8d28d17993fe695f Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Sat, 2 Nov 2024 16:09:32 +0300 Subject: [PATCH 09/16] rename api --- runtime-light/stdlib/job-worker/job-worker-api.cpp | 10 +++++----- runtime-light/stdlib/job-worker/job-worker-api.h | 10 +++++----- runtime-light/stdlib/rpc/rpc-api.cpp | 4 ++-- runtime-light/stdlib/rpc/rpc-api.h | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/runtime-light/stdlib/job-worker/job-worker-api.cpp b/runtime-light/stdlib/job-worker/job-worker-api.cpp index 2d593f54be..78213eac37 100644 --- a/runtime-light/stdlib/job-worker/job-worker-api.cpp +++ b/runtime-light/stdlib/job-worker/job-worker-api.cpp @@ -84,17 +84,17 @@ task_t kphp_job_worker_start_impl(string request, double timeout, bool // ================================================================================================ -task_t> f$k2_job_worker_start(string request, double timeout) noexcept { +task_t> f$job_worker_send_request(string request, double timeout) noexcept { const auto fork_id{co_await kphp_job_worker_start_impl(std::move(request), timeout, false)}; co_return fork_id != INVALID_FORK_ID ? fork_id : false; } -task_t f$k2_job_worker_start_no_reply(string request, double timeout) noexcept { +task_t f$job_worker_send_noreply_request(string request, double timeout) noexcept { const auto fork_id{co_await kphp_job_worker_start_impl(std::move(request), timeout, true)}; co_return fork_id != INVALID_FORK_ID; } -task_t>> f$k2_job_worker_start_multi(array requests, double timeout) noexcept { +task_t>> f$job_worker_send_multi_request(array requests, double timeout) noexcept { array> fork_ids{requests.size()}; for (const auto &it : requests) { const auto fork_id{co_await kphp_job_worker_start_impl(it.get_value(), timeout, false)}; @@ -105,7 +105,7 @@ task_t>> f$k2_job_worker_start_multi(array reque // ================================================================================================ -task_t f$k2_job_worker_fetch_request() noexcept { +task_t f$job_worker_fetch_request() noexcept { if (!f$is_kphp_job_workers_enabled()) { php_warning("couldn't fetch job worker request: job workers are disabled"); co_return string{}; @@ -119,7 +119,7 @@ task_t f$k2_job_worker_fetch_request() noexcept { co_return std::exchange(jw_server_ctx.body, string{}); } -task_t f$k2_job_worker_store_response(string response) noexcept { +task_t f$job_worker_store_response(string response) noexcept { auto &component_ctx{*get_component_context()}; auto &jw_server_ctx{JobWorkerServerComponentContext::get()}; if (!f$is_kphp_job_workers_enabled()) { // workers are enabled diff --git a/runtime-light/stdlib/job-worker/job-worker-api.h b/runtime-light/stdlib/job-worker/job-worker-api.h index 839cb001e8..f9c36a3339 100644 --- a/runtime-light/stdlib/job-worker/job-worker-api.h +++ b/runtime-light/stdlib/job-worker/job-worker-api.h @@ -13,17 +13,17 @@ // === Client ===================================================================================== -task_t> f$k2_job_worker_start(string request, double timeout) noexcept; +task_t> f$job_worker_send_request(string request, double timeout) noexcept; -task_t f$k2_job_worker_start_no_reply(string request, double timeout) noexcept; +task_t f$job_worker_send_noreply_request(string request, double timeout) noexcept; -task_t>> f$k2_job_worker_start_multi(array requests, double timeout) noexcept; +task_t>> f$job_worker_send_multi_request(array requests, double timeout) noexcept; // === Server ===================================================================================== -task_t f$k2_job_worker_fetch_request() noexcept; +task_t f$job_worker_fetch_request() noexcept; -task_t f$k2_job_worker_store_response(string response) noexcept; +task_t f$job_worker_store_response(string response) noexcept; // === Misc ======================================================================================= diff --git a/runtime-light/stdlib/rpc/rpc-api.cpp b/runtime-light/stdlib/rpc/rpc-api.cpp index 5b7d561a65..ef7246a30d 100644 --- a/runtime-light/stdlib/rpc/rpc-api.cpp +++ b/runtime-light/stdlib/rpc/rpc-api.cpp @@ -358,7 +358,7 @@ string f$fetch_string() noexcept { // === Rpc Query ================================================================================== -task_t> f$k2_kphp_rpc_tl_query(string actor, array tl_objects, double timeout, bool ignore_answer, +task_t> f$rpc_send_request(string actor, array tl_objects, double timeout, bool ignore_answer, class_instance requests_extra_info, bool need_responses_extra_info) noexcept { if (ignore_answer && need_responses_extra_info) { php_warning("Both $ignore_answer and $need_responses_extra_info are 'true'. Can't collect metrics for ignored answers"); @@ -380,7 +380,7 @@ task_t> f$k2_kphp_rpc_tl_query(string actor, array tl_obje co_return query_ids; } -task_t>> f$k2_kphp_rpc_tl_query_result(array query_ids) noexcept { +task_t>> f$rpc_fetch_response(array query_ids) noexcept { array> res{query_ids.size()}; for (const auto &it : query_ids) { res.set_value(it.get_key(), co_await rpc_impl_::rpc_tl_query_result_one_impl(it.get_value())); diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index 3cd4869bff..b3c70f9546 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -59,11 +59,11 @@ string f$fetch_string() noexcept; // === Rpc Query ================================================================================== - task_t> f$k2_kphp_rpc_tl_query(string actor, array tl_objects, double timeout = -1.0, bool ignore_answer = false, + task_t> f$rpc_send_request(string actor, array tl_objects, double timeout = -1.0, bool ignore_answer = false, class_instance requests_extra_info = {}, bool need_responses_extra_info = false) noexcept; template rpc_function_t, std::same_as rpc_request_t = KphpRpcRequest> -task_t> f$k2_kphp_typed_rpc_tl_query(string actor, array> query_functions, double timeout = -1.0, +task_t> f$rpc_send_typed_query_request(string actor, array> query_functions, double timeout = -1.0, bool ignore_answer = false, class_instance requests_extra_info = {}, bool need_responses_extra_info = false) noexcept { if (ignore_answer && need_responses_extra_info) { @@ -87,11 +87,11 @@ task_t> f$k2_kphp_typed_rpc_tl_query(string actor, array>> f$k2_kphp_rpc_tl_query_result(array query_ids) noexcept; +task_t>> f$rpc_fetch_response(array query_ids) noexcept; template query_id_t = int64_t, std::same_as error_factory_t = RpcResponseErrorFactory> requires std::default_initializable task_t>> -f$k2_kphp_typed_rpc_tl_query_result(array query_ids) noexcept { +f$rpc_fetch_typed_response(array query_ids) noexcept { array> res{query_ids.size()}; for (const auto &it : query_ids) { res.set_value(it.get_key(), co_await rpc_impl_::typed_rpc_tl_query_result_one_impl(it.get_value(), error_factory_t{})); From 7d3e62d1cfb3267a6411aeb8e475a5dca293e2ee Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Sat, 2 Nov 2024 16:30:01 +0300 Subject: [PATCH 10/16] remove impl --- runtime/math_functions.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/runtime/math_functions.cpp b/runtime/math_functions.cpp index 6e358065f9..9c312c1b5f 100644 --- a/runtime/math_functions.cpp +++ b/runtime/math_functions.cpp @@ -267,35 +267,6 @@ Optional f$random_bytes(int64_t length) noexcept { return str; } -mixed f$abs(const mixed &v) { - mixed num = v.to_numeric(); - if (num.is_int()) { - return std::abs(num.to_int()); - } - return fabs(num.to_float()); -} - -int64_t f$abs(int64_t v) { - return std::abs(v); -} - -double f$abs(double v) { - return std::abs(v); -} - -int64_t f$abs(const Optional &v) { - return f$abs(val(v)); -} - -int64_t f$abs(const Optional &v) { - return f$abs(static_cast(val(v))); -} - -double f$abs(const Optional &v) { - return f$abs(val(v)); -} - - string f$base_convert(const string &number, int64_t frombase, int64_t tobase) { if (frombase < 2 || frombase > 36) { From 99020d37db84d89edd4579819fdb2756c6014c67 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Sat, 2 Nov 2024 16:21:27 +0300 Subject: [PATCH 11/16] mark all interruptible --- builtin-functions/kphp-light/functions.txt | 4 +- builtin-functions/kphp-light/job-workers.txt | 10 +-- .../{unsupported => }/kphp-toggles.txt | 5 +- builtin-functions/kphp-light/rpc.txt | 42 ++++----- .../kphp-light/{unsupported => }/string.txt | 89 ++++++++++--------- .../kphp-light/unsupported-functions.txt | 2 - .../kphp-light/unsupported/misc.txt | 31 ++----- 7 files changed, 85 insertions(+), 98 deletions(-) rename builtin-functions/kphp-light/{unsupported => }/kphp-toggles.txt (93%) rename builtin-functions/kphp-light/{unsupported => }/string.txt (77%) diff --git a/builtin-functions/kphp-light/functions.txt b/builtin-functions/kphp-light/functions.txt index 5f73fe5f1c..8f81433d6d 100644 --- a/builtin-functions/kphp-light/functions.txt +++ b/builtin-functions/kphp-light/functions.txt @@ -3,9 +3,11 @@ 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'; +require_once __DIR__ . '/rpc.txt'; +require_once __DIR__ . '/string.txt'; +require_once __DIR__ . '/kphp-toggles.txt'; /** defined in runtime-core.h **/ function likely ($x ::: bool) ::: bool; diff --git a/builtin-functions/kphp-light/job-workers.txt b/builtin-functions/kphp-light/job-workers.txt index 60d498a4fc..ced0644ab6 100644 --- a/builtin-functions/kphp-light/job-workers.txt +++ b/builtin-functions/kphp-light/job-workers.txt @@ -45,17 +45,17 @@ function get_job_workers_number(): int; // === Job Worker Old API ================================================================================= -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_start(KphpJobWorkerRequest $request, float $timeout): future | false; -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_start_no_reply(KphpJobWorkerRequest $request, float $timeout): bool; -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_start_multi(KphpJobWorkerRequest[] $request, float $timeout): (future | false)[]; -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible 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 */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_store_response(KphpJobWorkerResponse $response) ::: int; diff --git a/builtin-functions/kphp-light/unsupported/kphp-toggles.txt b/builtin-functions/kphp-light/kphp-toggles.txt similarity index 93% rename from builtin-functions/kphp-light/unsupported/kphp-toggles.txt rename to builtin-functions/kphp-light/kphp-toggles.txt index b37589f6dc..f3465b94a4 100644 --- a/builtin-functions/kphp-light/unsupported/kphp-toggles.txt +++ b/builtin-functions/kphp-light/kphp-toggles.txt @@ -1,10 +1,9 @@ Date: Sat, 2 Nov 2024 19:15:11 +0300 Subject: [PATCH 12/16] add total interruptible functions --- compiler/stats.cpp | 4 ++++ compiler/stats.h | 1 + 2 files changed, 5 insertions(+) diff --git a/compiler/stats.cpp b/compiler/stats.cpp index 4d2b687882..b37816525f 100644 --- a/compiler/stats.cpp +++ b/compiler/stats.cpp @@ -44,6 +44,9 @@ void Stats::on_function_processed(FunctionPtr function) { if (function->is_resumable) { ++total_resumable_functions_; } + if (function->is_interruptible) { + ++total_interruptible_functions_; + } if (function->is_inline) { ++total_inline_functions_; } @@ -78,6 +81,7 @@ void Stats::write_to(std::ostream &out, bool with_indent) const { out << indent << "functions.total_inline: " << total_inline_functions_ << std::endl; out << indent << "functions.total_throwing: " << total_throwing_functions_ << std::endl; out << indent << "functions.total_resumable: " << total_resumable_functions_ << std::endl; + out << indent << "functions.total_interruptible: " << total_interruptible_functions_ << std::endl; out << block_sep; out << indent << "memory.rss: " << memory_rss_ * 1024 << std::endl; out << indent << "memory.rss_peak: " << memory_rss_peak_ * 1024 << std::endl; diff --git a/compiler/stats.h b/compiler/stats.h index fa78c56df9..ca3ef4707e 100644 --- a/compiler/stats.h +++ b/compiler/stats.h @@ -43,6 +43,7 @@ class Stats { std::atomic total_functions_{0u}; std::atomic total_throwing_functions_{0u}; std::atomic total_resumable_functions_{0u}; + std::atomic total_interruptible_functions_{0u}; std::atomic total_inline_functions_{0u}; std::atomic memory_rss_{0}; From d4ac1c9423240a382bfc8907dbe0e76a2af58fef Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Wed, 6 Nov 2024 12:39:04 +0300 Subject: [PATCH 13/16] fix issues --- builtin-functions/kphp-light/rpc.txt | 8 +-- runtime-common/stdlib/math/math-functions.cpp | 12 ++-- runtime-common/stdlib/math/math-functions.h | 72 +++++++++---------- runtime-light/stdlib/rpc/rpc-api.cpp | 4 +- runtime-light/stdlib/rpc/rpc-api.h | 8 +-- tests/k2-components/test_rpc_memcached.php | 12 ++-- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/builtin-functions/kphp-light/rpc.txt b/builtin-functions/kphp-light/rpc.txt index 83a2b7d5ae..c5bce048d2 100644 --- a/builtin-functions/kphp-light/rpc.txt +++ b/builtin-functions/kphp-light/rpc.txt @@ -33,16 +33,16 @@ final class KphpRpcRequestsExtraInfo { } /** @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[]; +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 */ -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[]; +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_response($query_ids ::: array) ::: mixed[][]; +function rpc_fetch_responses($query_ids ::: array) ::: mixed[][]; /** @kphp-extern-func-info interruptible */ -function rpc_fetch_typed_response(int[] $query_ids) ::: @tl\RpcResponse[]; +function rpc_fetch_typed_responses(int[] $query_ids) ::: @tl\RpcResponse[]; /** @kphp-extern-func-info can_throw */ function fetch_int () ::: int; diff --git a/runtime-common/stdlib/math/math-functions.cpp b/runtime-common/stdlib/math/math-functions.cpp index 144a912f6f..f534991057 100644 --- a/runtime-common/stdlib/math/math-functions.cpp +++ b/runtime-common/stdlib/math/math-functions.cpp @@ -6,7 +6,7 @@ #include -mixed f$abs(const mixed &v) { +mixed f$abs(const mixed &v) noexcept { mixed num = v.to_numeric(); if (num.is_int()) { return std::abs(num.to_int()); @@ -14,23 +14,23 @@ mixed f$abs(const mixed &v) { return fabs(num.to_float()); } -int64_t f$abs(int64_t v) { +int64_t f$abs(int64_t v) noexcept { return std::abs(v); } -double f$abs(double v) { +double f$abs(double v) noexcept { return std::abs(v); } -int64_t f$abs(const Optional &v) { +int64_t f$abs(const Optional &v) noexcept { return f$abs(val(v)); } -int64_t f$abs(const Optional &v) { +int64_t f$abs(const Optional &v) noexcept { return f$abs(static_cast(val(v))); } -double f$abs(const Optional &v) { +double f$abs(const Optional &v) noexcept { return f$abs(val(v)); } diff --git a/runtime-common/stdlib/math/math-functions.h b/runtime-common/stdlib/math/math-functions.h index 60987c373c..e4b569cd88 100644 --- a/runtime-common/stdlib/math/math-functions.h +++ b/runtime-common/stdlib/math/math-functions.h @@ -6,73 +6,73 @@ #include "runtime-common/core/runtime-core.h" -inline double f$ceil(double v); +inline double f$ceil(double v) noexcept; -inline double f$cos(double v); +inline double f$cos(double v) noexcept; -inline double f$deg2rad(double v); +inline double f$deg2rad(double v) noexcept; -inline double f$floor(double v); +inline double f$floor(double v) noexcept; -inline double f$log(double v); +inline double f$log(double v) noexcept; -inline double f$log(double v, double base); +inline double f$log(double v, double base) noexcept; template -inline T f$min(const array &a); +inline T f$min(const array &a) noexcept; template -inline T f$max(const array &a); +inline T f$max(const array &a) noexcept; template -inline T f$min(const T &arg1); +inline T f$min(const T &arg1) noexcept; template -inline T f$min(const T &arg1, const T &arg2, Args&&... args); +inline T f$min(const T &arg1, const T &arg2, Args&&... args) noexcept; template -inline T f$max(const T &arg1); +inline T f$max(const T &arg1) noexcept; template -inline T f$max(const T &arg1, const T &arg2, Args&&... args); +inline T f$max(const T &arg1, const T &arg2, Args&&... args) noexcept; -inline double f$pi(); +inline double f$pi() noexcept; -inline double f$round(double v, int64_t precision = 0); +inline double f$round(double v, int64_t precision = 0) noexcept; -inline double f$sqrt(double v); +inline double f$sqrt(double v) noexcept; -mixed f$abs(const mixed &v); -int64_t f$abs(int64_t v); -double f$abs(double v); -int64_t f$abs(const Optional &v); -int64_t f$abs(const Optional &v); -double f$abs(const Optional &v); +mixed f$abs(const mixed &v) noexcept; +int64_t f$abs(int64_t v) noexcept; +double f$abs(double v) noexcept; +int64_t f$abs(const Optional &v) noexcept; +int64_t f$abs(const Optional &v) noexcept; +double f$abs(const Optional &v) noexcept; -inline double f$ceil(double v) { +inline double f$ceil(double v) noexcept { return ceil(v); } -inline double f$cos(double v) { +inline double f$cos(double v) noexcept { return cos(v); } -inline double f$deg2rad(double v) { +inline double f$deg2rad(double v) noexcept { return v * M_PI / 180; } -inline double f$floor(double v) { +inline double f$floor(double v) noexcept { return floor(v); } -inline double f$log(double v) { +inline double f$log(double v) noexcept { if (v <= 0.0) { return 0.0; } return log(v); } -inline double f$log(double v, double base) { +inline double f$log(double v, double base) noexcept { if (v <= 0.0 || base <= 0.0 || fabs(base - 1.0) < 1e-9) { return 0.0; } @@ -80,7 +80,7 @@ inline double f$log(double v, double base) { } template -T f$min(const array &a) { +T f$min(const array &a) noexcept { if (a.count() == 0) { php_warning("Empty array specified to function min"); return T(); @@ -97,7 +97,7 @@ T f$min(const array &a) { } template -T f$max(const array &a) { +T f$max(const array &a) noexcept { if (a.count() == 0) { php_warning("Empty array specified to function max"); return T(); @@ -114,30 +114,30 @@ T f$max(const array &a) { } template -T f$min(const T &arg1) { +T f$min(const T &arg1) noexcept { return arg1; } template -T f$min(const T &arg1, const T &arg2, Args&& ...args) { +T f$min(const T &arg1, const T &arg2, Args&& ...args) noexcept { return f$min(lt(arg1, arg2) ? arg1 : arg2, std::forward(args)...); } template -T f$max(const T &arg1) { +T f$max(const T &arg1) noexcept { return arg1; } template -T f$max(const T &arg1, const T &arg2, Args&& ...args) { +T f$max(const T &arg1, const T &arg2, Args&& ...args) noexcept { return f$max(lt(arg2, arg1) ? arg1 : arg2, std::forward(args)...); } -inline double f$pi() { +inline double f$pi() noexcept { return M_PI; } -inline double f$round(double v, int64_t precision) { +inline double f$round(double v, int64_t precision) noexcept { if (std::abs(precision) > 100) { php_warning("Wrong parameter precision (%" PRIi64 ") in function round", precision); return v; @@ -147,7 +147,7 @@ inline double f$round(double v, int64_t precision) { return round(v * mul) / mul; } -inline double f$sqrt(double v) { +inline double f$sqrt(double v) noexcept { if (v < 0) { return 0.0; } diff --git a/runtime-light/stdlib/rpc/rpc-api.cpp b/runtime-light/stdlib/rpc/rpc-api.cpp index ef7246a30d..de2e113d5e 100644 --- a/runtime-light/stdlib/rpc/rpc-api.cpp +++ b/runtime-light/stdlib/rpc/rpc-api.cpp @@ -358,7 +358,7 @@ string f$fetch_string() noexcept { // === Rpc Query ================================================================================== -task_t> f$rpc_send_request(string actor, array tl_objects, double timeout, bool ignore_answer, +task_t> f$rpc_send_requests(string actor, array tl_objects, double timeout, bool ignore_answer, class_instance requests_extra_info, bool need_responses_extra_info) noexcept { if (ignore_answer && need_responses_extra_info) { php_warning("Both $ignore_answer and $need_responses_extra_info are 'true'. Can't collect metrics for ignored answers"); @@ -380,7 +380,7 @@ task_t> f$rpc_send_request(string actor, array tl_objects, co_return query_ids; } -task_t>> f$rpc_fetch_response(array query_ids) noexcept { +task_t>> f$rpc_fetch_responses(array query_ids) noexcept { array> res{query_ids.size()}; for (const auto &it : query_ids) { res.set_value(it.get_key(), co_await rpc_impl_::rpc_tl_query_result_one_impl(it.get_value())); diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index b3c70f9546..44e6de255a 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -59,11 +59,11 @@ string f$fetch_string() noexcept; // === Rpc Query ================================================================================== - task_t> f$rpc_send_request(string actor, array tl_objects, double timeout = -1.0, bool ignore_answer = false, + task_t> f$rpc_send_requests(string actor, array tl_objects, double timeout = -1.0, bool ignore_answer = false, class_instance requests_extra_info = {}, bool need_responses_extra_info = false) noexcept; template rpc_function_t, std::same_as rpc_request_t = KphpRpcRequest> -task_t> f$rpc_send_typed_query_request(string actor, array> query_functions, double timeout = -1.0, +task_t> f$rpc_send_typed_query_requests(string actor, array> query_functions, double timeout = -1.0, bool ignore_answer = false, class_instance requests_extra_info = {}, bool need_responses_extra_info = false) noexcept { if (ignore_answer && need_responses_extra_info) { @@ -87,11 +87,11 @@ task_t> f$rpc_send_typed_query_request(string actor, array>> f$rpc_fetch_response(array query_ids) noexcept; +task_t>> f$rpc_fetch_responses(array query_ids) noexcept; template query_id_t = int64_t, std::same_as error_factory_t = RpcResponseErrorFactory> requires std::default_initializable task_t>> -f$rpc_fetch_typed_response(array query_ids) noexcept { +f$rpc_fetch_typed_responses(array query_ids) noexcept { array> res{query_ids.size()}; for (const auto &it : query_ids) { res.set_value(it.get_key(), co_await rpc_impl_::typed_rpc_tl_query_result_one_impl(it.get_value(), error_factory_t{})); diff --git a/tests/k2-components/test_rpc_memcached.php b/tests/k2-components/test_rpc_memcached.php index 254db83f1a..7074c6d32a 100644 --- a/tests/k2-components/test_rpc_memcached.php +++ b/tests/k2-components/test_rpc_memcached.php @@ -1,24 +1,24 @@ "memcache.get", "key" => "xxx"]]); - $response = rpc_fetch_response($ids)[0]; + $ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "xxx"]]); + $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result["_"] !== "memcache.not_found") { warning("memcache.not_found expected"); return false; } - $ids = rpc_send_request("mc_main", [["_" => "memcache.set", "key" => "foo", "flags" => 0, "delay" => 0, "value" => "bar"]]); - $response = rpc_fetch_response($ids)[0]; + $ids = rpc_send_requests("mc_main", [["_" => "memcache.set", "key" => "foo", "flags" => 0, "delay" => 0, "value" => "bar"]]); + $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result !== true) { warning("true expected"); return false; } - $ids = rpc_send_request("mc_main", [["_" => "memcache.get", "key" => "foo"]]); - $response = rpc_fetch_response($ids)[0]; + $ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "foo"]]); + $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result["_"] !== "memcache.strvalue" || $result["value"] !== "bar") { warning("\"bar\" expected"); From 5e67a03ea61189fe59cafb7e85f8ac9810b73483 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Wed, 6 Nov 2024 12:42:48 +0300 Subject: [PATCH 14/16] fix issues --- tests/k2-components/test_rpc_memcached.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/k2-components/test_rpc_memcached.php b/tests/k2-components/test_rpc_memcached.php index 7074c6d32a..9b5a68ec06 100644 --- a/tests/k2-components/test_rpc_memcached.php +++ b/tests/k2-components/test_rpc_memcached.php @@ -1,7 +1,7 @@ "memcache.get", "key" => "xxx"]]); + $ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "xxx"]], -1, false, null, false); $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result["_"] !== "memcache.not_found") { @@ -9,15 +9,15 @@ function do_untyped_rpc() { return false; } - $ids = rpc_send_requests("mc_main", [["_" => "memcache.set", "key" => "foo", "flags" => 0, "delay" => 0, "value" => "bar"]]); + $ids = rpc_send_requests("mc_main", [["_" => "memcache.set", "key" => "foo", "flags" => 0, "delay" => 0, "value" => "bar"]], -1, false, null, false); $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result !== true) { warning("true expected"); return false; } - - $ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "foo"]]); + + $ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "foo"]], -1, false, null, false); $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result["_"] !== "memcache.strvalue" || $result["value"] !== "bar") { From fce4bdbbd4dbffeb34bd9068a3dab771700868a0 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Wed, 6 Nov 2024 12:43:07 +0300 Subject: [PATCH 15/16] fix issues --- runtime-common/stdlib/math/math-functions.cpp | 2 -- runtime-common/stdlib/math/math-functions.h | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/runtime-common/stdlib/math/math-functions.cpp b/runtime-common/stdlib/math/math-functions.cpp index f534991057..7a1f4b8c41 100644 --- a/runtime-common/stdlib/math/math-functions.cpp +++ b/runtime-common/stdlib/math/math-functions.cpp @@ -33,5 +33,3 @@ int64_t f$abs(const Optional &v) noexcept { double f$abs(const Optional &v) noexcept { return f$abs(val(v)); } - - diff --git a/runtime-common/stdlib/math/math-functions.h b/runtime-common/stdlib/math/math-functions.h index e4b569cd88..9c62fd5208 100644 --- a/runtime-common/stdlib/math/math-functions.h +++ b/runtime-common/stdlib/math/math-functions.h @@ -28,13 +28,13 @@ template inline T f$min(const T &arg1) noexcept; template -inline T f$min(const T &arg1, const T &arg2, Args&&... args) noexcept; +inline T f$min(const T &arg1, const T &arg2, Args &&...args) noexcept; template inline T f$max(const T &arg1) noexcept; template -inline T f$max(const T &arg1, const T &arg2, Args&&... args) noexcept; +inline T f$max(const T &arg1, const T &arg2, Args &&...args) noexcept; inline double f$pi() noexcept; @@ -118,8 +118,8 @@ T f$min(const T &arg1) noexcept { return arg1; } -template -T f$min(const T &arg1, const T &arg2, Args&& ...args) noexcept { +template +T f$min(const T &arg1, const T &arg2, Args &&...args) noexcept { return f$min(lt(arg1, arg2) ? arg1 : arg2, std::forward(args)...); } @@ -128,8 +128,8 @@ T f$max(const T &arg1) noexcept { return arg1; } -template -T f$max(const T &arg1, const T &arg2, Args&& ...args) noexcept { +template +T f$max(const T &arg1, const T &arg2, Args &&...args) noexcept { return f$max(lt(arg2, arg1) ? arg1 : arg2, std::forward(args)...); } From 286fcc4160ab723eab23590c1ed742af174ffbe8 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Wed, 6 Nov 2024 15:10:29 +0300 Subject: [PATCH 16/16] remove include --- compiler/lexer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/lexer.cpp b/compiler/lexer.cpp index c8f98f6d80..0d6844893b 100644 --- a/compiler/lexer.cpp +++ b/compiler/lexer.cpp @@ -18,7 +18,6 @@ #include "compiler/stage.h" #include "compiler/threading/thread-id.h" -#include "compiler/compiler-core.h" /*** LexerData