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

K2: use special refcnt for shared globals #1138

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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 compiler/pipes/final-check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ void FinalCheckPass::check_op_func_call(VertexAdaptor<op_func_call> 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);
Expand Down
38 changes: 26 additions & 12 deletions runtime-common/stdlib/string/string-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "common/mixin/not_copyable.h"
#include "common/php-functions.h"
#include "runtime-common/core/runtime-core.h"

namespace string_context_impl_ {
Expand Down Expand Up @@ -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<string::size_type>(std::char_traits<char>::length(string_context_impl_::COLON_))};
const string CP1251_STR{string_context_impl_::CP1251_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::CP1251_))};
const string DOT_STR{string_context_impl_::DOT_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::DOT_))};
const string COMMA_STR{string_context_impl_::COMMA_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::COMMA_))};
const string BACKSLASH_STR{string_context_impl_::BACKSLASH_,
static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::BACKSLASH_))};
const string QUOTE_STR{string_context_impl_::QUOTE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::QUOTE_))};
const string NEWLINE_STR{string_context_impl_::NEWLINE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::NEWLINE_))};
const string SPACE_STR{string_context_impl_::SPACE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::SPACE_))};
string COLON_STR{string_context_impl_::COLON_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::COLON_))};
string CP1251_STR{string_context_impl_::CP1251_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::CP1251_))};
string DOT_STR{string_context_impl_::DOT_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::DOT_))};
string COMMA_STR{string_context_impl_::COMMA_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::COMMA_))};
string BACKSLASH_STR{string_context_impl_::BACKSLASH_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::BACKSLASH_))};
string QUOTE_STR{string_context_impl_::QUOTE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::QUOTE_))};
string NEWLINE_STR{string_context_impl_::NEWLINE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::NEWLINE_))};
string SPACE_STR{string_context_impl_::SPACE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::SPACE_))};
// +1 here to since char_traits<char>::length doesn't count '\0' at the end
const string WHAT_STR{string_context_impl_::WHAT_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::WHAT_)) + 1};
const string ONE_STR{string_context_impl_::ONE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::ONE_))};
const string PERCENT_STR{string_context_impl_::PERCENT_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::PERCENT_))};
string WHAT_STR{string_context_impl_::WHAT_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::WHAT_)) + 1};
string ONE_STR{string_context_impl_::ONE_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::ONE_))};
string PERCENT_STR{string_context_impl_::PERCENT_, static_cast<string::size_type>(std::char_traits<char>::length(string_context_impl_::PERCENT_))};

const char lhex_digits[17] = "0123456789abcdef";
const char uhex_digits[17] = "0123456789ABCDEF";
Expand All @@ -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;
};
4 changes: 2 additions & 2 deletions runtime-light/component/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
};
3 changes: 3 additions & 0 deletions runtime-light/tl/tl-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tl_storer_ptr> &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;
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/string-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading