diff --git a/CMakeLists.txt b/CMakeLists.txt index 70cb8b8d..c7fc7c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ else() set(HAVE_SSE42 FALSE) endif() -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_CXX_EXTENSIONS FALSE) diff --git a/common/delay.h b/common/delay.h index 2d5f37b2..3df8e7d8 100644 --- a/common/delay.h +++ b/common/delay.h @@ -18,7 +18,6 @@ */ #pragma once -#include "absl/strings/internal/str_format/parser.h" #include "td/actor/actor.h" namespace ton { diff --git a/crypto/test/test-db.cpp b/crypto/test/test-db.cpp index c1e4c2ce..7ac1096f 100644 --- a/crypto/test/test-db.cpp +++ b/crypto/test/test-db.cpp @@ -62,6 +62,7 @@ #include "vm/dict.h" #include +#include namespace vm { @@ -2010,7 +2011,7 @@ TEST(TonDb, CompactArrayOld) { SCOPE_EXIT { ton_db->commit_transaction(std::move(txn)); }; - auto smart = txn->begin_smartcontract(""); + auto smart = txn->begin_smartcontract(); SCOPE_EXIT { txn->commit_smartcontract(std::move(smart)); }; @@ -2037,7 +2038,7 @@ TEST(TonDb, CompactArrayOld) { SCOPE_EXIT { ton_db->commit_transaction(std::move(txn)); }; - auto smart = txn->begin_smartcontract(""); + auto smart = txn->begin_smartcontract(); //smart->validate_meta(); SCOPE_EXIT { txn->commit_smartcontract(std::move(smart)); @@ -2058,7 +2059,7 @@ TEST(TonDb, CompactArrayOld) { SCOPE_EXIT { ton_db->abort_transaction(std::move(txn)); }; - auto smart = txn->begin_smartcontract(""); + auto smart = txn->begin_smartcontract(); SCOPE_EXIT { txn->abort_smartcontract(std::move(smart)); }; @@ -2219,7 +2220,7 @@ TEST(TonDb, CellStat) { ASSERT_EQ(stat.cells, new_stat.get_stat().cells); ASSERT_EQ(stat.bits, new_stat.get_stat().bits); - CHECK(usage_tree.unique()); + CHECK(usage_tree.use_count() == 1); usage_tree.reset(); td::Ref C, BC, C_proof; std::shared_ptr usage_tree_B; diff --git a/crypto/vm/cells/CellHash.h b/crypto/vm/cells/CellHash.h index 2810ad46..9435675f 100644 --- a/crypto/vm/cells/CellHash.h +++ b/crypto/vm/cells/CellHash.h @@ -76,7 +76,7 @@ struct CellHash { inline size_t cell_hash_slice_hash(td::Slice hash) { // use offset 8, because in db keys are grouped by first bytes. - return td::as(hash.ubegin() + 8); + return td::as(hash.substr(8, 8).ubegin()); } namespace std { template <> diff --git a/crypto/vm/db/InMemoryBagOfCellsDb.cpp b/crypto/vm/db/InMemoryBagOfCellsDb.cpp index 950233b3..aa8f7910 100644 --- a/crypto/vm/db/InMemoryBagOfCellsDb.cpp +++ b/crypto/vm/db/InMemoryBagOfCellsDb.cpp @@ -14,6 +14,8 @@ #include "td/utils/HashMap.h" #include "td/utils/HashSet.h" +#include + #if TD_PORT_POSIX #include #include @@ -98,7 +100,7 @@ class ArenaPrunnedCellCreator : public ExtCellCreator { } #else static std::unique_ptr alloc() { - auto ptr = reinterpret_cast(malloc(batch_size))); + auto ptr = reinterpret_cast(malloc(batch_size)); CHECK(ptr != nullptr); return std::unique_ptr(ptr); } @@ -292,7 +294,7 @@ struct CellInfoHashTableDense { } template void init_from(Iterator begin, Iterator end) { - auto size = std::distance(begin, end); + auto size = td::narrow_cast(std::distance(begin, end)); dense_ht_buckets_ = std::max(size_t(1), size_t(size / 8)); std::vector offsets(dense_ht_buckets_ + 2); @@ -438,16 +440,16 @@ class CellStorage { add_stat("ht.size", size); add_stat("ht.load", double(size) / std::max(1.0, double(capacity))); } - CHECK(stats.roots_total_count == local_roots_.size()); + CHECK(td::narrow_cast(stats.roots_total_count) == local_roots_.size()); return stats; } void apply_stats_diff(DynamicBagOfCellsDb::Stats diff) { auto unique_access = local_access_.lock(); stats_.apply_diff(diff); - CHECK(stats_.roots_total_count == local_roots_.size()); + CHECK(td::narrow_cast(stats_.roots_total_count) == local_roots_.size()); size_t cells_count{0}; for_each_bucket(0, [&](size_t bucket_id, auto &bucket) { cells_count += bucket.infos_.size(); }); - CHECK(stats_.cells_total_count == cells_count); + CHECK(td::narrow_cast(stats_.cells_total_count) == cells_count); } td::Result> load_cell(const CellHash &hash) const { @@ -541,8 +543,8 @@ class CellStorage { DefaultPrunnedCellCreator default_pc_creator; auto timer = td::Timer(); - size_t cell_count{0}; - size_t desc_count{0}; + td::int64 cell_count{0}; + td::int64 desc_count{0}; if (options.use_less_memory_during_creation) { auto [new_cell_count, new_desc_count] = parallel_scan_cells( default_pc_creator, options.use_arena, diff --git a/crypto/vm/db/TonDb.h b/crypto/vm/db/TonDb.h index 8779f1b2..6cd8aa4f 100644 --- a/crypto/vm/db/TonDb.h +++ b/crypto/vm/db/TonDb.h @@ -113,7 +113,8 @@ class TonDbTransactionImpl; using TonDbTransaction = std::unique_ptr; class TonDbTransactionImpl { public: - SmartContractDb begin_smartcontract(td::Slice hash = {}); + + SmartContractDb begin_smartcontract(td::Slice hash = std::string(32, '\0')); void commit_smartcontract(SmartContractDb txn); void commit_smartcontract(SmartContractDiff txn); diff --git a/tdactor/td/actor/core/ActorTypeStat.cpp b/tdactor/td/actor/core/ActorTypeStat.cpp index e241dd56..8f50fa9c 100644 --- a/tdactor/td/actor/core/ActorTypeStat.cpp +++ b/tdactor/td/actor/core/ActorTypeStat.cpp @@ -2,12 +2,24 @@ #include "td/actor/core/ActorTypeStat.h" #include "td/actor/core/Scheduler.h" #include "td/utils/port/thread_local.h" -#include #include #include #include #include #include +#include +#include "td/utils/port/platform.h" + +#ifdef __has_include +#if __has_include() +#include +#define CXXABI_AVAILABLE 1 +#else +#define CXXABI_AVAILABLE 0 +#endif +#else +#define CXXABI_AVAILABLE 0 +#endif namespace td { namespace actor { @@ -82,6 +94,7 @@ ActorTypeStatRef ActorTypeStatManager::get_actor_type_stat(td::uint32 id, Actor } std::string ActorTypeStatManager::get_class_name(const char *name) { +#if CXXABI_AVAILABLE int status; char *real_name = abi::__cxa_demangle(name, nullptr, nullptr, &status); if (status < 0) { @@ -91,6 +104,9 @@ std::string ActorTypeStatManager::get_class_name(const char *name) { std::string result = real_name; std::free(real_name); return result; +#else + return name; +#endif } ActorTypeStats ActorTypeStatManager::get_stats(double inv_ticks_per_second) { diff --git a/tdutils/td/utils/port/Clocks.cpp b/tdutils/td/utils/port/Clocks.cpp index 59e80f61..7e27d51a 100644 --- a/tdutils/td/utils/port/Clocks.cpp +++ b/tdutils/td/utils/port/Clocks.cpp @@ -22,6 +22,10 @@ #include namespace td { +int64 Clocks::monotonic_nano() { + auto duration = std::chrono::steady_clock::now().time_since_epoch(); + return std::chrono::duration_cast(duration).count(); +} double Clocks::monotonic() { // TODO write system specific functions, because std::chrono::steady_clock is steady only under Windows diff --git a/tdutils/td/utils/port/Clocks.h b/tdutils/td/utils/port/Clocks.h index 7640e216..b2054365 100644 --- a/tdutils/td/utils/port/Clocks.h +++ b/tdutils/td/utils/port/Clocks.h @@ -22,20 +22,22 @@ namespace td { struct Clocks { + static int64 monotonic_nano(); + static double monotonic(); static double system(); static int tz_offset(); -#if defined(__i386__) - static __inline__ td::uint64 rdtsc(void) { +#if defined(__i386__) or defined(__M_IX86) + static uint64 rdtsc() { unsigned long long int x; __asm__ volatile("rdtsc" : "=A"(x)); return x; } - static constexpr td::uint64 rdtsc_frequency(void) { + static constexpr uint64 rdtsc_frequency() { return 2000'000'000; } @@ -46,13 +48,13 @@ struct Clocks { static constexpr double inv_ticks_per_second() { return 0.5e-9; } -#elif defined(__x86_64__) - static __inline__ td::uint64 rdtsc(void) { +#elif defined(__x86_64__) or defined(__M_X64) + static uint64 rdtsc() { unsigned hi, lo; __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi)); return ((unsigned long long)lo) | (((unsigned long long)hi) << 32); } - static constexpr td::uint64 rdtsc_frequency(void) { + static constexpr uint64 rdtsc_frequency() { return 2000'000'000; } @@ -63,13 +65,13 @@ struct Clocks { static constexpr double inv_ticks_per_second() { return 0.5e-9; } -#elif defined(__aarch64__) - static __inline__ td::uint64 rdtsc(void) { +#elif defined(__aarch64__) or defined(_M_ARM64) + static uint64 rdtsc() { unsigned long long val; asm volatile("mrs %0, cntvct_el0" : "=r"(val)); return val; } - static __inline__ td::uint64 rdtsc_frequency(void) { + static uint64 rdtsc_frequency() { unsigned long long val; asm volatile("mrs %0, cntfrq_el0" : "=r"(val)); return val; @@ -79,6 +81,21 @@ struct Clocks { return static_cast(rdtsc_frequency()); } + static double inv_ticks_per_second() { + return 1.0 / static_cast(rdtsc_frequency()); + } +#else + static uint64 rdtsc() { + return monotonic_nano(); + } + static uint64 rdtsc_frequency() { + return 1000'000'000; + } + + static double ticks_per_second() { + return static_cast(rdtsc_frequency()); + } + static double inv_ticks_per_second() { return 1.0 / static_cast(rdtsc_frequency()); } diff --git a/validator/db/celldb.hpp b/validator/db/celldb.hpp index f63d62cd..7cd36689 100644 --- a/validator/db/celldb.hpp +++ b/validator/db/celldb.hpp @@ -29,6 +29,8 @@ #include "db-utils.h" #include "td/db/RocksDb.h" +#include + namespace rocksdb { class Statistics; class DB;