Skip to content

Commit 5aa00a1

Browse files
authored
[k2] revert "[k2] replace tl::is_int32_overflow with std::in_range (#1527)" (#1530)
It turns out it's intentional that the code didn't use standard algorithms here. The reason for that is that it doesn't matter for TL whether tl::int is signed or unsigned This reverts commit 01a7aa6.
1 parent 6e3bca8 commit 5aa00a1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

runtime-light/stdlib/rpc/rpc-api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ inline bool f$store_byte(int64_t v) noexcept {
8484
}
8585

8686
inline bool f$store_int(int64_t v) noexcept {
87-
if (!std::in_range<int32_t>(v)) [[unlikely]] {
87+
if (tl::is_int32_overflow(v)) [[unlikely]] {
8888
kphp::log::warning("integer {} overflows int32, it will be cast to {}", v, static_cast<int32_t>(v));
8989
}
9090
tl::i32{.value = static_cast<int32_t>(v)}.store(RpcServerInstanceState::get().tl_storer);
@@ -243,7 +243,7 @@ inline bool f$rpc_parse(const Optional<string>& new_rpc_data) noexcept {
243243
class_instance<C$VK$TL$RpcFunction> f$rpc_server_fetch_request() noexcept;
244244

245245
inline kphp::coro::task<bool> f$store_error(int64_t error_code, string error_msg) noexcept {
246-
if (!std::in_range<int32_t>(error_code)) [[unlikely]] {
246+
if (tl::is_int32_overflow(error_code)) [[unlikely]] {
247247
kphp::log::warning("error_code overflows int32, {} will be stored", static_cast<int32_t>(error_code));
248248
}
249249

runtime-light/stdlib/rpc/rpc-tl-builtins.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
#include "runtime-light/stdlib/rpc/rpc-tl-builtins.h"
66

7-
#include <cstdint>
8-
#include <utility>
9-
107
#include "runtime-light/server/rpc/rpc-server-state.h"
118
#include "runtime-light/stdlib/diagnostics/logs.h"
9+
#include "runtime-light/tl/tl-core.h"
1210

1311
mixed tl_arr_get(const mixed& arr, const string& str_key, int64_t num_key, int64_t precomputed_hash) noexcept {
1412
auto& cur_query{CurrentTlQuery::get()};
@@ -30,7 +28,7 @@ mixed tl_arr_get(const mixed& arr, const string& str_key, int64_t num_key, int64
3028

3129
int32_t t_Int::prepare_int_for_storing(int64_t v) noexcept {
3230
auto v32{static_cast<int32_t>(v)};
33-
if (!std::in_range<int32_t>(v)) [[unlikely]] {
31+
if (tl::is_int32_overflow(v)) [[unlikely]] {
3432
if (RpcServerInstanceState::get().fail_rpc_on_int32_overflow) {
3533
CurrentTlQuery::get().raise_storing_error("Got int32 overflow with value '%" PRIi64 "'. Serialization will fail.", v);
3634
} else {

runtime-light/tl/tl-core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
#include <span>
1313
#include <utility>
1414

15+
#include "common/algorithms/find.h"
1516
#include "runtime-common/core/allocator/script-allocator.h"
1617
#include "runtime-common/core/std/containers.h"
1718
#include "runtime-light/metaprogramming/concepts.h"
1819
#include "runtime-light/stdlib/diagnostics/logs.h"
1920

2021
namespace tl {
2122

23+
inline bool is_int32_overflow(int64_t v) noexcept {
24+
const auto v32{static_cast<int32_t>(v)};
25+
return vk::none_of_equal(v, int64_t{v32}, int64_t{static_cast<uint32_t>(v32)});
26+
}
27+
2228
class storer {
2329
static constexpr auto DEFAULT_BUFFER_CAPACITY = 1024;
2430

0 commit comments

Comments
 (0)