From 2db0962794abfda61095b31096129fb404a02f44 Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Tue, 5 Nov 2024 23:53:07 +0300 Subject: [PATCH 1/2] Set refcnt to ExtraRefCnt::for_global_const for object in ImageState --- runtime-common/stdlib/string/string-context.h | 38 +++++++++++++------ runtime-light/component/image.h | 4 +- runtime-light/tl/tl-builtins.cpp | 3 ++ runtime/string-context.cpp | 4 +- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/runtime-common/stdlib/string/string-context.h b/runtime-common/stdlib/string/string-context.h index 3b0884cbed..8181b9cf63 100644 --- a/runtime-common/stdlib/string/string-context.h +++ b/runtime-common/stdlib/string/string-context.h @@ -9,6 +9,7 @@ #include #include "common/mixin/not_copyable.h" +#include "common/php-functions.h" #include "runtime-common/core/runtime-core.h" namespace string_context_impl_ { @@ -46,19 +47,18 @@ class StringLibContext final : vk::not_copyable { }; struct StringLibConstants final : vk::not_copyable { - const string COLON_STR{string_context_impl_::COLON_, static_cast(std::char_traits::length(string_context_impl_::COLON_))}; - const string CP1251_STR{string_context_impl_::CP1251_, static_cast(std::char_traits::length(string_context_impl_::CP1251_))}; - const string DOT_STR{string_context_impl_::DOT_, static_cast(std::char_traits::length(string_context_impl_::DOT_))}; - const string COMMA_STR{string_context_impl_::COMMA_, static_cast(std::char_traits::length(string_context_impl_::COMMA_))}; - const string BACKSLASH_STR{string_context_impl_::BACKSLASH_, - static_cast(std::char_traits::length(string_context_impl_::BACKSLASH_))}; - const string QUOTE_STR{string_context_impl_::QUOTE_, static_cast(std::char_traits::length(string_context_impl_::QUOTE_))}; - const string NEWLINE_STR{string_context_impl_::NEWLINE_, static_cast(std::char_traits::length(string_context_impl_::NEWLINE_))}; - const string SPACE_STR{string_context_impl_::SPACE_, static_cast(std::char_traits::length(string_context_impl_::SPACE_))}; + string COLON_STR{string_context_impl_::COLON_, static_cast(std::char_traits::length(string_context_impl_::COLON_))}; + string CP1251_STR{string_context_impl_::CP1251_, static_cast(std::char_traits::length(string_context_impl_::CP1251_))}; + string DOT_STR{string_context_impl_::DOT_, static_cast(std::char_traits::length(string_context_impl_::DOT_))}; + string COMMA_STR{string_context_impl_::COMMA_, static_cast(std::char_traits::length(string_context_impl_::COMMA_))}; + string BACKSLASH_STR{string_context_impl_::BACKSLASH_, static_cast(std::char_traits::length(string_context_impl_::BACKSLASH_))}; + string QUOTE_STR{string_context_impl_::QUOTE_, static_cast(std::char_traits::length(string_context_impl_::QUOTE_))}; + string NEWLINE_STR{string_context_impl_::NEWLINE_, static_cast(std::char_traits::length(string_context_impl_::NEWLINE_))}; + string SPACE_STR{string_context_impl_::SPACE_, static_cast(std::char_traits::length(string_context_impl_::SPACE_))}; // +1 here to since char_traits::length doesn't count '\0' at the end - const string WHAT_STR{string_context_impl_::WHAT_, static_cast(std::char_traits::length(string_context_impl_::WHAT_)) + 1}; - const string ONE_STR{string_context_impl_::ONE_, static_cast(std::char_traits::length(string_context_impl_::ONE_))}; - const string PERCENT_STR{string_context_impl_::PERCENT_, static_cast(std::char_traits::length(string_context_impl_::PERCENT_))}; + string WHAT_STR{string_context_impl_::WHAT_, static_cast(std::char_traits::length(string_context_impl_::WHAT_)) + 1}; + string ONE_STR{string_context_impl_::ONE_, static_cast(std::char_traits::length(string_context_impl_::ONE_))}; + string PERCENT_STR{string_context_impl_::PERCENT_, static_cast(std::char_traits::length(string_context_impl_::PERCENT_))}; const char lhex_digits[17] = "0123456789abcdef"; const char uhex_digits[17] = "0123456789ABCDEF"; @@ -72,5 +72,19 @@ struct StringLibConstants final : vk::not_copyable { static constexpr int64_t STR_PAD_RIGHT = 1; static constexpr int64_t STR_PAD_BOTH = 2; + StringLibConstants() noexcept { + COLON_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + CP1251_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + DOT_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + COMMA_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + BACKSLASH_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + QUOTE_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + NEWLINE_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + SPACE_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + WHAT_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + ONE_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + PERCENT_STR.set_reference_counter_to(ExtraRefCnt::for_global_const); + } + static const StringLibConstants &get() noexcept; }; diff --git a/runtime-light/component/image.h b/runtime-light/component/image.h index 6c094708b2..0cd5c11005 100644 --- a/runtime-light/component/image.h +++ b/runtime-light/component/image.h @@ -10,6 +10,6 @@ struct ImageState final : private vk::not_copyable { char *c_linear_mem; - RpcImageState rpc_image_state; - StringImageState string_image_state; + RpcImageState rpc_image_state{}; + StringImageState string_image_state{}; }; diff --git a/runtime-light/tl/tl-builtins.cpp b/runtime-light/tl/tl-builtins.cpp index 0f1c236a06..b12fd1a0ff 100644 --- a/runtime-light/tl/tl-builtins.cpp +++ b/runtime-light/tl/tl-builtins.cpp @@ -4,9 +4,12 @@ #include "runtime-light/tl/tl-builtins.h" +#include "common/php-functions.h" + void register_tl_storers_table_and_fetcher(const array &gen$ht, tl_fetch_wrapper_ptr gen$t_ReqResult_fetch) { auto &rpc_mutable_image_state{RpcImageState::get_mutable()}; rpc_mutable_image_state.tl_storers_ht = gen$ht; + rpc_mutable_image_state.tl_storers_ht.set_reference_counter_to(ExtraRefCnt::for_global_const); rpc_mutable_image_state.tl_fetch_wrapper = gen$t_ReqResult_fetch; } diff --git a/runtime/string-context.cpp b/runtime/string-context.cpp index cf7d07e630..91c872ebbb 100644 --- a/runtime/string-context.cpp +++ b/runtime/string-context.cpp @@ -4,13 +4,13 @@ #include "runtime-common/stdlib/string/string-context.h" -static StringLibContext string_lib_context; +static StringLibContext string_lib_context{}; StringLibContext &StringLibContext::get() noexcept { return string_lib_context; } -const static StringLibConstants string_lib_constants; +const static StringLibConstants string_lib_constants{}; const StringLibConstants &StringLibConstants::get() noexcept { return string_lib_constants; From 6d005522955ae07013c8ba70f389f552968f76c5 Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Wed, 6 Nov 2024 15:50:55 +0300 Subject: [PATCH 2/2] Add new untyped RPC builtins to compiler's untyped RPC usage detection --- compiler/pipes/final-check.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/pipes/final-check.cpp b/compiler/pipes/final-check.cpp index 466c02f426..e9783ac148 100644 --- a/compiler/pipes/final-check.cpp +++ b/compiler/pipes/final-check.cpp @@ -883,7 +883,7 @@ void FinalCheckPass::check_op_func_call(VertexAdaptor call) { check_header_register_callback(call); } else if (function_name == "to_mixed") { check_to_mixed_call(call); - } else if (vk::string_view{function_name}.starts_with("rpc_tl_query")) { + } else if (vk::string_view{function_name}.starts_with("rpc_tl_query") || vk::string_view{function_name}.starts_with("rpc_send_request")) { G->set_untyped_rpc_tl_used(); } else if (vk::string_view{function_name}.starts_with("FFI$$")) { check_ffi_call(call);