diff options
author | galtsev <galtsev@yandex-team.com> | 2025-01-11 01:47:12 +0300 |
---|---|---|
committer | galtsev <galtsev@yandex-team.com> | 2025-01-11 02:04:26 +0300 |
commit | 70f661e686e52e323a44ae351a803b7eb8031eb6 (patch) | |
tree | fabbdeef92616c4c4d930fd82c11982ecf1c6a2f /yt | |
parent | 4b74ecb3d4b0394d9e045a31e6a4e32632ce76c3 (diff) | |
download | ydb-70f661e686e52e323a44ae351a803b7eb8031eb6.tar.gz |
YT-21993: Remove Phoenix v1
commit_hash:e4285d508e98757c71cb20a91f3cd1f3a56a3c73
Diffstat (limited to 'yt')
-rw-r--r-- | yt/yt/client/table_client/table_upload_options.cpp | 4 | ||||
-rw-r--r-- | yt/yt/client/table_client/table_upload_options.h | 6 | ||||
-rw-r--r-- | yt/yt/core/misc/arithmetic_formula.cpp | 1 | ||||
-rw-r--r-- | yt/yt/core/misc/digest.cpp | 43 | ||||
-rw-r--r-- | yt/yt/core/misc/digest.h | 10 | ||||
-rw-r--r-- | yt/yt/core/misc/histogram.cpp | 47 | ||||
-rw-r--r-- | yt/yt/core/misc/histogram.h | 4 | ||||
-rw-r--r-- | yt/yt/core/misc/phoenix-inl.h | 48 | ||||
-rw-r--r-- | yt/yt/core/misc/phoenix.cpp | 34 | ||||
-rw-r--r-- | yt/yt/core/misc/phoenix.h | 258 | ||||
-rw-r--r-- | yt/yt/core/misc/unittests/phoenix_compatibility_ut.cpp | 433 | ||||
-rw-r--r-- | yt/yt/core/misc/unittests/phoenix_ut.cpp | 626 | ||||
-rw-r--r-- | yt/yt/core/misc/unittests/ya.make | 2 | ||||
-rw-r--r-- | yt/yt/core/phoenix/context.h | 27 | ||||
-rw-r--r-- | yt/yt/core/phoenix/type_decl-inl.h | 50 | ||||
-rw-r--r-- | yt/yt/core/phoenix/type_def-inl.h | 57 | ||||
-rw-r--r-- | yt/yt/core/profiling/unittests/timer_ut.cpp | 5 | ||||
-rw-r--r-- | yt/yt/core/ya.make | 1 |
18 files changed, 100 insertions, 1556 deletions
diff --git a/yt/yt/client/table_client/table_upload_options.cpp b/yt/yt/client/table_client/table_upload_options.cpp index 3908a272da..ba09c3fcfc 100644 --- a/yt/yt/client/table_client/table_upload_options.cpp +++ b/yt/yt/client/table_client/table_upload_options.cpp @@ -61,7 +61,7 @@ ui64 TEpochSchema::Set(const TTableSchemaPtr& schema) return ++Revision_; } -void TEpochSchema::Persist(const NPhoenix::TPersistenceContext& context) +void TEpochSchema::Persist(const NPhoenix2::TPersistenceContext& context) { using NYT::Persist; @@ -91,7 +91,7 @@ TTableSchemaPtr TTableUploadOptions::GetUploadSchema() const } } -void TTableUploadOptions::Persist(const NPhoenix::TPersistenceContext& context) +void TTableUploadOptions::Persist(const NPhoenix2::TPersistenceContext& context) { using NYT::Persist; diff --git a/yt/yt/client/table_client/table_upload_options.h b/yt/yt/client/table_client/table_upload_options.h index 24e19766fd..74ea519213 100644 --- a/yt/yt/client/table_client/table_upload_options.h +++ b/yt/yt/client/table_client/table_upload_options.h @@ -13,7 +13,7 @@ #include <yt/yt/core/compression/public.h> -#include <yt/yt/core/misc/phoenix.h> +#include <yt/yt/core/phoenix/context.h> namespace NYT::NTableClient { @@ -39,7 +39,7 @@ public: ui64 Set(const TTableSchemaPtr& schema); - void Persist(const NPhoenix::TPersistenceContext& context); + void Persist(const NPhoenix2::TPersistenceContext& context); ui64 Reset(); @@ -67,7 +67,7 @@ struct TTableUploadOptions TTableSchemaPtr GetUploadSchema() const; - void Persist(const NPhoenix::TPersistenceContext& context); + void Persist(const NPhoenix2::TPersistenceContext& context); }; const std::vector<TString>& GetTableUploadOptionsAttributeKeys(); diff --git a/yt/yt/core/misc/arithmetic_formula.cpp b/yt/yt/core/misc/arithmetic_formula.cpp index 143e3de8f6..d4231991ec 100644 --- a/yt/yt/core/misc/arithmetic_formula.cpp +++ b/yt/yt/core/misc/arithmetic_formula.cpp @@ -1,5 +1,4 @@ #include "arithmetic_formula.h" -#include "phoenix.h" #include <yt/yt/core/misc/error.h> diff --git a/yt/yt/core/misc/digest.cpp b/yt/yt/core/misc/digest.cpp index 0ecdb4a37e..8ce0bd4ef9 100644 --- a/yt/yt/core/misc/digest.cpp +++ b/yt/yt/core/misc/digest.cpp @@ -1,17 +1,23 @@ #include "digest.h" #include "config.h" -#include <yt/yt/core/misc/phoenix.h> +#include <yt/yt/core/phoenix/type_def.h> namespace NYT { -using namespace NPhoenix; +using namespace NPhoenix2; + +//////////////////////////////////////////////////////////////////////////////// + +void IPersistentDigest::RegisterMetadata(auto&& /*registrar*/) +{ } + +PHOENIX_DEFINE_TYPE(IPersistentDigest); //////////////////////////////////////////////////////////////////////////////// class TLogDigest : public IPersistentDigest - , public NPhoenix::TFactoryTag<NPhoenix::TSimpleFactory> { public: TLogDigest(TLogDigestConfigPtr config) @@ -60,21 +66,6 @@ public: std::fill(Buckets_.begin(), Buckets_.end(), 0); } - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - Persist(context, Step_); - Persist(context, LogStep_); - Persist(context, LowerBound_); - Persist(context, UpperBound_); - Persist(context, DefaultValue_); - Persist(context, BucketCount_); - Persist(context, SampleCount_); - Persist(context, Buckets_); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TLogDigest, 0x42424243); - private: double Step_; double LogStep_; @@ -88,9 +79,23 @@ private: i64 SampleCount_ = 0; std::vector<i64> Buckets_; + + PHOENIX_DECLARE_POLYMORPHIC_TYPE(TLogDigest, 0x42424243); }; -DEFINE_DYNAMIC_PHOENIX_TYPE(TLogDigest); +void TLogDigest::RegisterMetadata(auto&& registrar) +{ + PHOENIX_REGISTER_FIELD(1, Step_)(); + PHOENIX_REGISTER_FIELD(2, LogStep_)(); + PHOENIX_REGISTER_FIELD(3, LowerBound_)(); + PHOENIX_REGISTER_FIELD(4, UpperBound_)(); + PHOENIX_REGISTER_FIELD(5, DefaultValue_)(); + PHOENIX_REGISTER_FIELD(6, BucketCount_)(); + PHOENIX_REGISTER_FIELD(7, SampleCount_)(); + PHOENIX_REGISTER_FIELD(8, Buckets_)(); +} + +PHOENIX_DEFINE_TYPE(TLogDigest); //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/misc/digest.h b/yt/yt/core/misc/digest.h index afa8054284..fed29d666d 100644 --- a/yt/yt/core/misc/digest.h +++ b/yt/yt/core/misc/digest.h @@ -2,7 +2,8 @@ #include "public.h" -#include <yt/yt/core/misc/phoenix.h> +#include <yt/yt/core/phoenix/context.h> +#include <yt/yt/core/phoenix/type_decl.h> namespace NYT { @@ -31,9 +32,12 @@ DEFINE_REFCOUNTED_TYPE(IDigest) struct IPersistentDigest : public IDigest - , public NPhoenix::IPersistent + , public NPhoenix2::IPersistent { - void Persist(const NPhoenix::TPersistenceContext& context) override = 0; + using TLoadContext = NPhoenix2::TLoadContext; + using TSaveContext = NPhoenix2::TSaveContext; + + PHOENIX_DECLARE_POLYMORPHIC_TYPE(IPersistentDigest, 0x1ed99609); }; DEFINE_REFCOUNTED_TYPE(IPersistentDigest) diff --git a/yt/yt/core/misc/histogram.cpp b/yt/yt/core/misc/histogram.cpp index ef055668d0..9ce25ad784 100644 --- a/yt/yt/core/misc/histogram.cpp +++ b/yt/yt/core/misc/histogram.cpp @@ -1,5 +1,8 @@ #include "histogram.h" +#include <yt/yt/core/phoenix/type_decl.h> +#include <yt/yt/core/phoenix/type_def.h> + #include <yt/yt/core/yson/public.h> #include <yt/yt/core/ytree/fluent.h> @@ -8,13 +11,12 @@ namespace NYT { using namespace NYTree; using namespace NYson; -using namespace NPhoenix; +using namespace NPhoenix2; //////////////////////////////////////////////////////////////////////////////// class THistogram : public IHistogram - , public NPhoenix::TFactoryTag<NPhoenix::TSimpleFactory> { public: THistogram() = default; @@ -74,31 +76,15 @@ public: return result; } - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - Persist(context, MaxBuckets_); - Persist(context, ValueMin_); - Persist(context, ValueMax_); - Persist(context, Items_); - } - private: struct TItem { i64 Value; i64 Count; - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, Value); - Persist(context, Count); - } + PHOENIX_DECLARE_TYPE(TItem, 0x9860143c); }; - DECLARE_DYNAMIC_PHOENIX_TYPE(THistogram, 0x636d76d7); - static const i64 HistogramViewReserveFactor = 2; i64 MaxBuckets_ = 0; @@ -140,9 +126,30 @@ private: View_.Count[GetBucketIndex(item.Value)] += item.Count; } } + + PHOENIX_DECLARE_FRIEND(); + PHOENIX_DECLARE_POLYMORPHIC_TYPE(THistogram, 0x636d76d7); }; -DEFINE_DYNAMIC_PHOENIX_TYPE(THistogram); +void THistogram::RegisterMetadata(auto&& registrar) +{ + PHOENIX_REGISTER_FIELD(1, MaxBuckets_)(); + PHOENIX_REGISTER_FIELD(2, ValueMin_)(); + PHOENIX_REGISTER_FIELD(3, ValueMax_)(); + PHOENIX_REGISTER_FIELD(4, Items_)(); +} + +PHOENIX_DEFINE_TYPE(THistogram); + +//////////////////////////////////////////////////////////////////////////////// + +void THistogram::TItem::RegisterMetadata(auto&& registrar) +{ + PHOENIX_REGISTER_FIELD(1, Value)(); + PHOENIX_REGISTER_FIELD(2, Count)(); +} + +PHOENIX_DEFINE_TYPE(THistogram::TItem); //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/misc/histogram.h b/yt/yt/core/misc/histogram.h index 8230790e85..f361573724 100644 --- a/yt/yt/core/misc/histogram.h +++ b/yt/yt/core/misc/histogram.h @@ -3,7 +3,7 @@ #include "public.h" #include "serialize.h" -#include <yt/yt/core/misc/phoenix.h> +#include <yt/yt/core/phoenix/context.h> namespace NYT { @@ -21,7 +21,7 @@ struct THistogramView }; struct IHistogram - : public virtual NPhoenix::IPersistent + : public virtual NPhoenix2::IPersistent { virtual void AddValue(i64 value, i64 count = 1) = 0; virtual void RemoveValue(i64 value, i64 count = 1) = 0; diff --git a/yt/yt/core/misc/phoenix-inl.h b/yt/yt/core/misc/phoenix-inl.h deleted file mode 100644 index 56cc3f199c..0000000000 --- a/yt/yt/core/misc/phoenix-inl.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef PHOENIX_INL_H_ -#error "Direct inclusion of this file is not allowed, include phoenix.h" -// For the sake of sane code completion. -#include "phoenix.h" -#endif - -#include <type_traits> - -namespace NYT::NPhoenix { - -//////////////////////////////////////////////////////////////////////////////// - -template <class T> -void* TProfiler::DoInstantiate() -{ - using TFactory = typename TFactoryTraits<T>::TFactory; - using TBase = typename TPolymorphicTraits<T>::TBase; - - T* ptr = TFactory::template Instantiate<T>(); - TBase* basePtr = static_cast<TBase*>(ptr); - return basePtr; -} - -template <class T> -void TProfiler::Register(ui32 tag) -{ - using TIdClass = typename TIdClass<T>::TType; - - auto pair = TagToEntry_.emplace(tag, TEntry()); - YT_VERIFY(pair.second); - auto& entry = pair.first->second; - entry.Tag = tag; - entry.TypeInfo = &typeid(TIdClass); - entry.Factory = std::bind(&DoInstantiate<T>); - YT_VERIFY(TypeInfoToEntry_.emplace(entry.TypeInfo, &entry).second); -} - -template <class T> -T* TProfiler::Instantiate(ui32 tag) -{ - using TBase = typename TPolymorphicTraits<T>::TBase; - TBase* basePtr = static_cast<TBase*>(GetEntry(tag).Factory()); - return dynamic_cast<T*>(basePtr); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NPhoenix diff --git a/yt/yt/core/misc/phoenix.cpp b/yt/yt/core/misc/phoenix.cpp deleted file mode 100644 index fbfb730469..0000000000 --- a/yt/yt/core/misc/phoenix.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "phoenix.h" - -#include "collection_helpers.h" - -namespace NYT::NPhoenix { - -//////////////////////////////////////////////////////////////////////////////// - -TProfiler::TProfiler() -{ } - -TProfiler* TProfiler::Get() -{ - return Singleton<TProfiler>(); -} - -ui32 TProfiler::GetTag(const std::type_info& typeInfo) -{ - return GetEntry(typeInfo).Tag; -} - -const TProfiler::TEntry& TProfiler::GetEntry(ui32 tag) -{ - return GetOrCrash(TagToEntry_, tag); -} - -const TProfiler::TEntry& TProfiler::GetEntry(const std::type_info& typeInfo) -{ - return *GetOrCrash(TypeInfoToEntry_, &typeInfo); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NPhoenix diff --git a/yt/yt/core/misc/phoenix.h b/yt/yt/core/misc/phoenix.h deleted file mode 100644 index cbdd744c24..0000000000 --- a/yt/yt/core/misc/phoenix.h +++ /dev/null @@ -1,258 +0,0 @@ -#pragma once - -#include "id_generator.h" -#include "mpl.h" -#include "serialize.h" - -#include <yt/yt/core/actions/callback.h> - -#include <yt/yt/core/phoenix/context.h> -#include <yt/yt/core/phoenix/polymorphic.h> -#include <yt/yt/core/phoenix/type_decl.h> -#include <yt/yt/core/phoenix/type_def.h> - -#include <typeinfo> - -namespace NYT::NPhoenix { - -//////////////////////////////////////////////////////////////////////////////// - -constexpr ui32 InlineObjectIdMask = 0x80000000; -constexpr ui32 NullObjectId = 0x00000000; - -//////////////////////////////////////////////////////////////////////////////// - -using NPhoenix2::NDetail::TSerializer; -using NPhoenix2::TLoadContext; -using NPhoenix2::TSaveContext; - -using TDynamicTag = NPhoenix2::TPolymorphicBase; - -//////////////////////////////////////////////////////////////////////////////// - -template <class TFactory> -struct TFactoryTag -{ }; - -//////////////////////////////////////////////////////////////////////////////// - -template <class T, class = void> -struct TPolymorphicTraits -{ - static const bool Dynamic = false; - using TBase = T; -}; - -template <class T> -struct TPolymorphicTraits< - T, - typename std::enable_if_t< - std::is_convertible_v<T&, TDynamicTag&> - > -> -{ - static const bool Dynamic = true; - using TBase = TDynamicTag; -}; - -//////////////////////////////////////////////////////////////////////////////// - -struct TNullFactory -{ - template <class T> - static T* Instantiate() - { - YT_ABORT(); - } -}; - -struct TSimpleFactory -{ - template <class T> - static T* Instantiate() - { - return new T(); - } -}; - -struct TRefCountedFactory -{ - template <class T> - static T* Instantiate() - { - return New<T>().Release(); - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -template <class T, class = void> -struct TFactoryTraits -{ - using TFactory = TSimpleFactory; -}; - -template <class T> -struct TFactoryTraits< - T, - typename std::enable_if_t< - std::conjunction_v< - std::is_convertible<T*, NYT::TRefCountedBase*>, - std::negation<std::is_convertible<T*, TFactoryTag<TNullFactory>*>> - > - > -> -{ - using TFactory = TRefCountedFactory; -}; - -template <class T> -struct TFactoryTraits< - T, - typename std::enable_if_t< - std::is_convertible_v<T*, TFactoryTag<TNullFactory>*> - > -> -{ - using TFactory = TNullFactory; -}; - -//////////////////////////////////////////////////////////////////////////////// - -template <class T, class = void> -struct TIdClass -{ - using TType = T; -}; - -template <class T> -struct TIdClass< - T, - typename std::enable_if_t< - std::is_convertible_v<T*, NYT::TRefCountedBase*> - > -> -{ - using TType = NYT::TRefCountedWrapper<T>; -}; - - -//////////////////////////////////////////////////////////////////////////////// - -class TProfiler -{ -public: - static TProfiler* Get(); - - ui32 GetTag(const std::type_info& typeInfo); - - template <class T> - T* Instantiate(ui32 tag); - - template <class T> - void Register(ui32 tag); - -private: - struct TEntry - { - const std::type_info* TypeInfo; - ui32 Tag; - std::function<void*()> Factory; - }; - - THashMap<const std::type_info*, TEntry*> TypeInfoToEntry_; - THashMap<ui32, TEntry> TagToEntry_; - - TProfiler(); - - const TEntry& GetEntry(ui32 tag); - const TEntry& GetEntry(const std::type_info& typeInfo); - - template <class T> - static void* DoInstantiate(); - - Y_DECLARE_SINGLETON_FRIEND() -}; - -//////////////////////////////////////////////////////////////////////////////// - -template < - class TType, - ui32 tag, - class TFactory = typename TFactoryTraits<TType>::TFactory -> -struct TDynamicInitializer -{ - TDynamicInitializer() - { - TProfiler::Get()->Register<TType>(tag); - } -}; - -template < - class TType, - ui32 tag -> -struct TDynamicInitializer<TType, tag, TRefCountedFactory> -{ - TDynamicInitializer() - { - TProfiler::Get()->Register<TType>(tag); - } -}; - -#define DECLARE_DYNAMIC_PHOENIX_TYPE(...) \ - static ::NYT::NPhoenix::TDynamicInitializer<__VA_ARGS__> \ - DynamicPhoenixInitializer; \ - PHOENIX_DECLARE_OPAQUE_TYPE(__VA_ARGS__) - -// __VA_ARGS__ are used because sometimes we want a template type -// to be an argument but the single macro argument may not contain -// commas. Dat preprocessor :/ -#define DEFINE_DYNAMIC_PHOENIX_TYPE(...) \ - decltype(__VA_ARGS__::DynamicPhoenixInitializer) \ - __VA_ARGS__::DynamicPhoenixInitializer; \ - PHOENIX_DEFINE_OPAQUE_TYPE(__VA_ARGS__) - -#define INHERIT_DYNAMIC_PHOENIX_TYPE(baseType, type, tag) \ -class type \ - : public baseType \ -{ \ -public: \ - using baseType::baseType; \ - \ -private: \ - DECLARE_DYNAMIC_PHOENIX_TYPE(type, tag); \ -} - -#define INHERIT_DYNAMIC_PHOENIX_TYPE_TEMPLATED(baseType, type, tag, ...) \ -class type \ - : public baseType<__VA_ARGS__> \ -{ \ -public: \ - using baseType::baseType; \ - \ -private: \ - DECLARE_DYNAMIC_PHOENIX_TYPE(type, tag); \ -} - -//////////////////////////////////////////////////////////////////////////////// - -template <class C> -struct ICustomPersistent - : public virtual TDynamicTag -{ - virtual ~ICustomPersistent() = default; - virtual void Persist(const C& context) = 0; -}; - -using TPersistenceContext = TCustomPersistenceContext<TSaveContext, TLoadContext>; -using IPersistent = ICustomPersistent<TPersistenceContext>; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NPhoenix - -#define PHOENIX_INL_H_ -#include "phoenix-inl.h" -#undef PHOENIX_INL_H_ diff --git a/yt/yt/core/misc/unittests/phoenix_compatibility_ut.cpp b/yt/yt/core/misc/unittests/phoenix_compatibility_ut.cpp deleted file mode 100644 index 02c1e22516..0000000000 --- a/yt/yt/core/misc/unittests/phoenix_compatibility_ut.cpp +++ /dev/null @@ -1,433 +0,0 @@ -#include <yt/yt/core/test_framework/framework.h> - -#include <yt/yt/core/misc/blob_output.h> -#include <yt/yt/core/misc/phoenix.h> - -#include <yt/yt/core/phoenix/type_decl.h> -#include <yt/yt/core/phoenix/type_def.h> -#include <yt/yt/core/phoenix/polymorphic.h> - -namespace NYT { -namespace { - -//////////////////////////////////////////////////////////////////////////////// - -using TSaveContext = NPhoenix::TSaveContext; -using TLoadContext = NPhoenix::TLoadContext; -using TPersistenceContext = NPhoenix::TPersistenceContext; -using IPersistent = NPhoenix::IPersistent; -using IPersistent2 = NPhoenix2::ICustomPersistent<TSaveContext, TLoadContext, TPersistenceContext>; - -//////////////////////////////////////////////////////////////////////////////// - -template <class T> -TSharedRef Serialize(const T& value) -{ - TBlobOutput output; - TSaveContext context(&output); - Save(context, value); - context.Finish(); - return output.Flush(); -} - -template <class T> -void Deserialize(T& value, TRef ref) -{ - TMemoryInput input(ref.Begin(), ref.Size()); - TLoadContext context(&input); - Load(context, value); -} - -template <class T> -void InplaceDeserialize(TIntrusivePtr<T> value, TRef ref) -{ - TMemoryInput input(ref.Begin(), ref.Size()); - TLoadContext context(&input); - NPhoenix::TSerializer::InplaceLoad(context, value); -} - -//////////////////////////////////////////////////////////////////////////////// - -namespace NPhoenixCompatibilityMixedComposition { - -struct TComponentV1 -{ - int A = 0; - double B = 0; - - bool operator==(const TComponentV1& other) const = default; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, A); - Persist(context, B); - } -}; - -struct TComponentV2 -{ - int C = 0; - double D = 0; - - bool operator==(const TComponentV2& other) const = default; - - PHOENIX_DECLARE_TYPE(TComponentV2, 0x89e65bad); -}; - -void TComponentV2::RegisterMetadata(auto&& registrar) -{ - PHOENIX_REGISTER_FIELD(1, C)(); - PHOENIX_REGISTER_FIELD(2, D)(); -} - -PHOENIX_DEFINE_TYPE(TComponentV2); - -struct TCompositeV1 -{ - TComponentV1 X; - TComponentV2 Y; - - bool operator==(const TCompositeV1& other) const = default; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - Persist(context, Y); - } -}; - -struct TCompositeV2 -{ - TComponentV1 U; - TComponentV2 V; - - bool operator==(const TCompositeV2& other) const = default; - - PHOENIX_DECLARE_TYPE(TCompositeV2, 0xd1c75b13); -}; - -void TCompositeV2::RegisterMetadata(auto&& registrar) -{ - PHOENIX_REGISTER_FIELD(1, U)(); - PHOENIX_REGISTER_FIELD(2, V)(); -} - -PHOENIX_DEFINE_TYPE(TCompositeV2); - -} // namespace NPhoenixCompatibilityMixedComposition - -TEST(TPhoenixCompatibilityTest, MixedComposition) -{ - using namespace NPhoenixCompatibilityMixedComposition; - - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TComponentV1>); - EXPECT_TRUE(NPhoenix2::SupportsPhoenix2<TComponentV2>); - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TCompositeV1>); - EXPECT_TRUE(NPhoenix2::SupportsPhoenix2<TCompositeV2>); - - struct TDerived : public TComponentV2 { - }; - - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TDerived>); - - TComponentV1 component_v1; - component_v1.A = 7; - component_v1.B = 3.1416; - - TComponentV2 component_v2; - component_v2.C = 13; - component_v2.D = 2.7183; - - { - TCompositeV1 composite_v1; - composite_v1.X = component_v1; - composite_v1.Y = component_v2; - - TCompositeV1 composite_v1_2; - Deserialize(composite_v1_2, Serialize(composite_v1)); - - EXPECT_EQ(composite_v1_2, composite_v1); - } - - { - TCompositeV2 composite_v2; - composite_v2.U = component_v1; - composite_v2.V = component_v2; - - TCompositeV2 composite_v2_2; - Deserialize(composite_v2_2, Serialize(composite_v2)); - - EXPECT_EQ(composite_v2_2, composite_v2); - } -} - -//////////////////////////////////////////////////////////////////////////////// - -namespace NPhoenixCompatibilityMixedInheritance { - -struct TBaseV1 -{ - int A = 0; - double B = 0; - - bool operator==(const TBaseV1& other) const = default; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - - Persist(context, A); - Persist(context, B); - } - - PHOENIX_DECLARE_OPAQUE_TYPE(TBaseV1, 0xc5b6cc03); -}; - -PHOENIX_DEFINE_OPAQUE_TYPE(TBaseV1); - -struct TBaseV2 -{ - int C = 0; - double D = 0; - - bool operator==(const TBaseV2& other) const = default; - - PHOENIX_DECLARE_TYPE(TBaseV2, 0x5d59f4a3); -}; - -void TBaseV2::RegisterMetadata(auto&& registrar) -{ - PHOENIX_REGISTER_FIELD(1, C)(); - PHOENIX_REGISTER_FIELD(2, D)(); -} - -PHOENIX_DEFINE_TYPE(TBaseV2); - -struct TDerivedV1 - : public TBaseV1 - , public TBaseV2 -{ - int E = 0; - double F = 0; - - bool operator==(const TDerivedV1& other) const = default; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - - TBaseV1::Persist(context); - TBaseV2::Persist(context); - - Persist(context, E); - Persist(context, F); - } -}; - -struct TDerivedV2 - : public TBaseV1 - , public TBaseV2 -{ - int E = 0; - double F = 0; - - bool operator==(const TDerivedV2& other) const = default; - - PHOENIX_DECLARE_TYPE(TDerivedV2, 0x7d64560b); -}; - -void TDerivedV2::RegisterMetadata(auto&& registrar) -{ - registrar.template BaseType<TBaseV1>(); - registrar.template BaseType<TBaseV2>(); - - PHOENIX_REGISTER_FIELD(1, E)(); - PHOENIX_REGISTER_FIELD(2, F)(); -} - -PHOENIX_DEFINE_TYPE(TDerivedV2); - -} // namespace NPhoenixCompatibilityMixedInheritance - -TEST(TPhoenixCompatibilityTest, MixedInheritance) -{ - using namespace NPhoenixCompatibilityMixedInheritance; - - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TBaseV1>); - EXPECT_TRUE(NPhoenix2::SupportsPhoenix2<TBaseV2>); - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TDerivedV1>); - EXPECT_TRUE(NPhoenix2::SupportsPhoenix2<TDerivedV2>); - - TDerivedV1 derived_v1; - derived_v1.A = 77; - derived_v1.B = -0.77; - derived_v1.C = 33; - derived_v1.D = -0.33; - derived_v1.E = 5; - derived_v1.F = -0.5; - - TDerivedV1 derived_v1_2; - Deserialize(derived_v1_2, Serialize(derived_v1)); - - EXPECT_EQ(derived_v1_2, derived_v1); - - TDerivedV2 derived_v2; - derived_v2.A = 77; - derived_v2.B = -0.77; - derived_v2.C = 33; - derived_v2.D = -0.33; - derived_v2.E = 5; - derived_v2.F = -0.5; - - TDerivedV2 derived_v2_2; - Deserialize(derived_v2_2, Serialize(derived_v2)); - - EXPECT_EQ(derived_v2_2, derived_v2); -} - -//////////////////////////////////////////////////////////////////////////////// - -namespace NPhoenixCompatibilityMixedPolymorphic { - -struct TBaseV1 - : public TRefCounted - , public IPersistent -{ - int A = 0; - double B = 0; - - bool operator==(const TBaseV1& other) const = default; - - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - - Persist(context, A); - Persist(context, B); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TBaseV1, 0xbb6b6874); -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(TBaseV1); - -struct TBaseV2 - : public TRefCounted - , public IPersistent2 -{ - int C = 0; - double D = 0; - - bool operator==(const TBaseV2& other) const = default; - - PHOENIX_DECLARE_POLYMORPHIC_TYPE(TBaseV2, 0x20673022); -}; - -void TBaseV2::RegisterMetadata(auto&& registrar) -{ - PHOENIX_REGISTER_FIELD(1, C)(); - PHOENIX_REGISTER_FIELD(2, D)(); -} - -PHOENIX_DEFINE_TYPE(TBaseV2); - -struct TDerivedV1 - : public TBaseV2 -{ - int E = 0; - double F = 0; - - bool operator==(const TDerivedV1& other) const = default; - - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - - TBaseV2::Persist(context); - - Persist(context, E); - Persist(context, F); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TDerivedV1, 0x5b176bab); -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(TDerivedV1); - -struct TDerivedV2 - : public TBaseV1 - , public IPersistent2 -{ - int E = 0; - double F = 0; - - bool operator==(const TDerivedV2& other) const = default; - - PHOENIX_DECLARE_POLYMORPHIC_TYPE(TDerivedV2, 0xc461765b); -}; - -void TDerivedV2::RegisterMetadata(auto&& registrar) -{ - registrar.template BaseType<TBaseV1>(); - - PHOENIX_REGISTER_FIELD(1, E)(); - PHOENIX_REGISTER_FIELD(2, F)(); -} - -PHOENIX_DEFINE_TYPE(TDerivedV2); - -} // namespace NPhoenixCompatibilityMixedPolymorphic - -TEST(TPhoenixCompatibilityTest, MixedPolymorphic) -{ - using namespace NPhoenixCompatibilityMixedPolymorphic; - - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TBaseV1>); - EXPECT_TRUE(NPhoenix2::SupportsPhoenix2<TBaseV2>); - EXPECT_FALSE(NPhoenix2::SupportsPhoenix2<TDerivedV1>); - EXPECT_TRUE(NPhoenix2::SupportsPhoenix2<TDerivedV2>); - - EXPECT_TRUE(NPhoenix2::NDetail::TPolymorphicTraits<TBaseV1>::Polymorphic); - EXPECT_TRUE(NPhoenix2::NDetail::TPolymorphicTraits<TBaseV2>::Polymorphic); - EXPECT_TRUE(NPhoenix2::NDetail::TPolymorphicTraits<TDerivedV1>::Polymorphic); - EXPECT_TRUE(NPhoenix2::NDetail::TPolymorphicTraits<TDerivedV2>::Polymorphic); - - auto derived_v1 = New<TDerivedV1>(); - derived_v1->C = 33; - derived_v1->D = -0.33; - derived_v1->E = 5; - derived_v1->F = -0.5; - - TIntrusivePtr<TBaseV2> base_v2_2; - Deserialize(base_v2_2, Serialize(derived_v1)); - - auto* derived_v1_2 = dynamic_cast<TDerivedV1*>(base_v2_2.Get()); - EXPECT_NE(derived_v1_2, nullptr); - EXPECT_EQ(derived_v1_2->C, 33); - EXPECT_EQ(derived_v1_2->D, -0.33); - EXPECT_EQ(derived_v1_2->E, 5); - EXPECT_EQ(derived_v1_2->F, -0.5); - - auto derived_v2 = New<TDerivedV2>(); - derived_v2->A = 33; - derived_v2->B = -0.33; - derived_v2->E = 5; - derived_v2->F = -0.5; - - TIntrusivePtr<TBaseV1> base_v1_2; - Deserialize(base_v1_2, Serialize(derived_v2)); - - auto* derived_v2_2 = dynamic_cast<TDerivedV2*>(base_v1_2.Get()); - EXPECT_NE(derived_v2_2, nullptr); - EXPECT_EQ(derived_v2_2->A, 33); - EXPECT_EQ(derived_v2_2->B, -0.33); - EXPECT_EQ(derived_v2_2->E, 5); - EXPECT_EQ(derived_v2_2->F, -0.5); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace -} // namespace NYT diff --git a/yt/yt/core/misc/unittests/phoenix_ut.cpp b/yt/yt/core/misc/unittests/phoenix_ut.cpp index 1d41675444..a161cc71ef 100644 --- a/yt/yt/core/misc/unittests/phoenix_ut.cpp +++ b/yt/yt/core/misc/unittests/phoenix_ut.cpp @@ -1,625 +1 @@ -#include <yt/yt/core/test_framework/framework.h> - -#include <yt/yt/core/misc/blob_output.h> -#include <yt/yt/core/misc/phoenix.h> - -namespace NYT { -namespace { - -//////////////////////////////////////////////////////////////////////////////// - -using TSaveContext = NPhoenix::TSaveContext; -using TLoadContext = NPhoenix::TLoadContext; -using IPersistent = NPhoenix::IPersistent; -using TPersistenceContext = NPhoenix::TPersistenceContext; - -//////////////////////////////////////////////////////////////////////////////// - -template <class T> -TSharedRef Serialize(const T& value) -{ - TBlobOutput output; - TSaveContext context(&output); - Save(context, value); - context.Finish(); - return output.Flush(); -} - -template <class T> -void Deserialize(T& value, TRef ref) -{ - TMemoryInput input(ref.Begin(), ref.Size()); - TLoadContext context(&input); - Load(context, value); -} - -template <class T> -void InplaceDeserialize(TIntrusivePtr<T> value, TRef ref) -{ - TMemoryInput input(ref.Begin(), ref.Size()); - TLoadContext context(&input); - NPhoenix::TSerializer::InplaceLoad(context, value); -} - -//////////////////////////////////////////////////////////////////////////////// - -namespace NSimple { - -TEST(TPhoenixTest, Scalar) -{ - struct C - { - C() - : A(-1) - , B(-1) - { } - - int A; - double B; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, A); - Persist(context, B); - } - }; - - C c1; - c1.A = 10; - c1.B = 3.14; - - C c2; - Deserialize(c2, Serialize(c1)); - - EXPECT_EQ(c1.A, c2.A); - EXPECT_EQ(c1.B, c2.B); -} - -TEST(TPhoenixTest, Guid) -{ - TGuid g1(1, 2, 3, 4); - - TGuid g2(5, 6, 7, 8); - Deserialize(g2, Serialize(g1)); - - EXPECT_EQ(g1, g2); -} - -TEST(TPhoenixTest, Vector) -{ - std::vector<int> v1; - v1.push_back(1); - v1.push_back(2); - v1.push_back(3); - - std::vector<int> v2; - v2.push_back(33); - Deserialize(v2, Serialize(v1)); - - EXPECT_EQ(v1, v2); -} - -} // namespace NSimple - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef1 { - -struct A; -struct B; - -struct A - : public TRefCounted -{ - TIntrusivePtr<B> X; - TIntrusivePtr<B> Y; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - Persist(context, Y); - } - -}; - -struct B - : public TRefCounted -{ - B() - : V(-1) - { } - - int V; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, V); - } - -}; - -TEST(TPhoenixTest, Ref1) -{ - auto a1 = New<A>(); - a1->X = New<B>(); - a1->X->V = 1; - a1->Y = New<B>(); - a1->Y->V = 2; - - TIntrusivePtr<A> a2; - Deserialize(a2, Serialize(a1)); - - EXPECT_EQ(a2->GetRefCount(), 1); - EXPECT_EQ(a2->X->GetRefCount(), 1); - EXPECT_EQ(a2->X->V, 1); - EXPECT_EQ(a2->Y->GetRefCount(), 1); - EXPECT_EQ(a2->Y->V, 2); -} - -} // namespace NRef1 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef2 { - -struct A - : public TRefCounted -{ - TIntrusivePtr<A> X; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - } - -}; - -TEST(TPhoenixTest, Ref2) -{ - auto a1 = New<A>(); - - TIntrusivePtr<A> a2; - Deserialize(a2, Serialize(a1)); - - EXPECT_EQ(a2->GetRefCount(), 1); - EXPECT_FALSE(a2->X.operator bool()); -} - -} // namespace NRef2 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef3 { - -struct A - : public TRefCounted -{ - TIntrusivePtr<A> X; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - } - -}; - -TEST(TPhoenixTest, Ref3) -{ - auto a1 = New<A>(); - a1->X = a1; - - TIntrusivePtr<A> a2; - Deserialize(a2, Serialize(a1)); - - EXPECT_EQ(a2->GetRefCount(), 2); - EXPECT_EQ(a2->X, a2); - - a1->X.Reset(); - a2->X.Reset(); -} - -} // namespace NRef3 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef4 { - -struct A - : public TRefCounted -{ - A() - : X(nullptr) - { } - - A* X; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - } - -}; - -TEST(TPhoenixTest, Ref4) -{ - auto a1 = New<A>(); - a1->X = a1.Get(); - - TIntrusivePtr<A> a2; - Deserialize(a2, Serialize(a1)); - - EXPECT_EQ(a2->GetRefCount(), 1); - EXPECT_EQ(a2->X, a2); -} - -} // namespace NRef4 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef5 { - -struct A; -struct B; - -struct A - : public TRefCounted -{ - A() - : X(nullptr) - , Y(nullptr) - { } - - B* X; - TIntrusivePtr<B> Y; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - Persist(context, Y); - } -}; - -struct B - : public TRefCounted -{ - B() - : V(-1) - { } - - int V; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, V); - } - -}; - -TEST(TPhoenixTest, Ref5) -{ - auto a1 = New<A>(); - a1->Y = New<B>(); - a1->Y->V = 7; - a1->X = a1->Y.Get(); - - TIntrusivePtr<A> a2; - Deserialize(a2, Serialize(a1)); - - EXPECT_EQ(a2->GetRefCount(), 1); - EXPECT_EQ(a2->Y->GetRefCount(), 1); - EXPECT_EQ(a2->Y->V, 7); - EXPECT_EQ(a2->X, a2->Y); -} - -} // namespace NRef5 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef6 { - -struct TBase - : public TRefCounted - , public IPersistent -{ }; - -struct TDerived1 - : public TBase -{ - TDerived1() - : V(-1) - { } - - int V; - - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - Persist(context, V); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TDerived1, 0x71297841); - -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(TDerived1); - -struct TDerived2 - : public TBase -{ - TDerived2() - : V(-1) - { } - - double V; - - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - Persist(context, V); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TDerived2, 0x62745629); - -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(TDerived2); - -TEST(TPhoenixTest, Ref6) -{ - auto derived1 = New<TDerived1>(); - derived1->V = 5; - TIntrusivePtr<TBase> base1(derived1); - - TIntrusivePtr<TBase> base2; - Deserialize(base2, Serialize(base1)); - - EXPECT_EQ(base2->GetRefCount(), 1); - auto* derived2 = dynamic_cast<TDerived1*>(base2.Get()); - EXPECT_NE(derived2, nullptr); - EXPECT_EQ(derived2->V, 5); -} - -} // namespace NRef6 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef7 { - -struct TNonConstructable - : public TRefCounted - , public NPhoenix::TFactoryTag<NPhoenix::TNullFactory> -{ - explicit TNonConstructable(int x) - : X(x) - { } - - int X; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TNonConstructable, 0x14712618); - -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(TNonConstructable); - -TEST(TPhoenixTest, Ref7) -{ - auto obj1 = New<TNonConstructable>(123); - EXPECT_EQ(obj1->X, 123); - - auto obj2 = New<TNonConstructable>(456); - - InplaceDeserialize(obj2, Serialize(obj1)); - - EXPECT_EQ(obj2->X, 123); -} - -} // namespace NRef7 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef8 { - -struct A; -struct B; - -struct A - : public NPhoenix::TFactoryTag<NPhoenix::TSimpleFactory> -{ - int X; - std::unique_ptr<B> T; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - Persist(context, T); - } - -}; - -struct B - : public NPhoenix::TFactoryTag<NPhoenix::TSimpleFactory> -{ - int Y; - A* Z; - - void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, Y); - Persist(context, Z); - } - -}; - -TEST(TPhoenixTest, Ref8) -{ - std::unique_ptr<A> a1(new A()); - a1->X = 123; - a1->T.reset(new B()); - a1->T->Y = 456; - a1->T->Z = a1.get(); - - std::unique_ptr<A> a2; - Deserialize(a2, Serialize(a1)); - - EXPECT_EQ(a2->X, 123); - EXPECT_EQ(a2->T->Y, 456); - EXPECT_EQ(a2->T->Z, a2.get()); -} - -} // namespace NRef8 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef9 { - -struct A; -struct B; - -struct A - : public IPersistent -{ - explicit A(int x) - : X(x) - { } - - int X; - - virtual void Foo() = 0; - - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - Persist(context, X); - } - -}; - -struct B - : public A - , public NPhoenix::TFactoryTag<NPhoenix::TSimpleFactory> -{ - B() - : A(0) - , Y(0) - , Z(nullptr) - { } - - int Y; - A* Z; - - void Foo() override - { } - - void Persist(const TPersistenceContext& context) override - { - using NYT::Persist; - A::Persist(context); - Persist(context, Y); - Persist(context, Z); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(B, 0x54717818); - -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(B); - -TEST(TPhoenixTest, Ref9) -{ - std::unique_ptr<B> b1(new B()); - b1->X = 123; - b1->Y = 456; - b1->Z = b1.get(); - - std::unique_ptr<A> a1(b1.release()); - - std::unique_ptr<A> a2; - Deserialize(a2, Serialize(a1)); - - B* b2 = dynamic_cast<B*>(a2.get()); - EXPECT_NE(b2, nullptr); - EXPECT_EQ(b2->X, 123); - EXPECT_EQ(b2->Y, 456); - EXPECT_EQ(b2->Z, b2); -} - -} // namespace NRef9 - -//////////////////////////////////////////////////////////////////////////////// - -namespace NRef10 { - -struct TBase - : public TRefCounted - , public NPhoenix::TDynamicTag -{ - TBase() - : X (0) - { } - - int X; - - virtual void Persist(const TPersistenceContext& context) - { - using NYT::Persist; - Persist(context, X); - } -}; - -struct TDerived - : public TBase -{ - TDerived() - { } - - int Y; - - void Persist(const TPersistenceContext& context) override - { - TBase::Persist(context); - - using NYT::Persist; - Persist(context, Y); - } - - DECLARE_DYNAMIC_PHOENIX_TYPE(TDerived, 0x57818795); - -}; - -DEFINE_DYNAMIC_PHOENIX_TYPE(TDerived); - -TEST(TPhoenixTest, Ref10) -{ - auto obj1 = New<TDerived>(); - obj1->X = 123; - obj1->Y = 456; - - auto obj2 = New<TDerived>(); - - InplaceDeserialize(obj2, Serialize(TIntrusivePtr<TBase>(obj1))); - - EXPECT_EQ(obj2->X, 123); - EXPECT_EQ(obj2->Y, 456); -} - -} // namespace NRef10 - -//////////////////////////////////////////////////////////////////////////////// -} // namespace -} // namespace NYT +// TODO(galtsev): remove file diff --git a/yt/yt/core/misc/unittests/ya.make b/yt/yt/core/misc/unittests/ya.make index f8ab343a69..aaae16b1df 100644 --- a/yt/yt/core/misc/unittests/ya.make +++ b/yt/yt/core/misc/unittests/ya.make @@ -49,8 +49,6 @@ SRCS( mpl_ut.cpp pattern_formatter_ut.cpp persistent_queue_ut.cpp - phoenix_ut.cpp - phoenix_compatibility_ut.cpp pool_allocator_ut.cpp proc_ut.cpp random_ut.cpp diff --git a/yt/yt/core/phoenix/context.h b/yt/yt/core/phoenix/context.h index 7e555c910e..d4cadf0950 100644 --- a/yt/yt/core/phoenix/context.h +++ b/yt/yt/core/phoenix/context.h @@ -72,35 +72,16 @@ private: //////////////////////////////////////////////////////////////////////////////// -template <class TSaveContext, class TLoadContext, class TPersistenceContext> +template <class TSaveContext, class TLoadContext> struct ICustomPersistent : public virtual TPolymorphicBase { - virtual void SaveImpl(TSaveContext& context) const - { - const_cast<ICustomPersistent<TSaveContext, TLoadContext, TPersistenceContext>*>(this)->Persist(context); - } - - virtual void LoadImpl(TLoadContext& context) - { - Persist(context); - } - - virtual void Save(TSaveContext& context) const - { - SaveImpl(context); - } - - virtual void Load(TLoadContext& context) - { - LoadImpl(context); - } - - virtual void Persist(const TPersistenceContext& context) = 0; + virtual void Save(TSaveContext& context) const = 0; + virtual void Load(TLoadContext& context) = 0; }; +using IPersistent = ICustomPersistent<TSaveContext, TLoadContext>; using TPersistenceContext = TCustomPersistenceContext<TSaveContext, TLoadContext>; -using IPersistent = ICustomPersistent<TSaveContext, TLoadContext, TPersistenceContext>; //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/phoenix/type_decl-inl.h b/yt/yt/core/phoenix/type_decl-inl.h index fc4444370e..e5db38c330 100644 --- a/yt/yt/core/phoenix/type_decl-inl.h +++ b/yt/yt/core/phoenix/type_decl-inl.h @@ -57,12 +57,8 @@ private: \ PHOENIX_DECLARE_TYPE__PROLOGUE(type, typeTagValue); \ public: \ static const ::NYT::NPhoenix2::TTypeDescriptor& GetTypeDescriptor(); \ - void SaveImpl(TSaveContext& context) const saveLoadModifier; \ - void LoadImpl(TLoadContext& context) saveLoadModifier; \ void Save(TSaveContext& context) const saveLoadModifier; \ void Load(TLoadContext& context) saveLoadModifier; \ - void Persist(const TPersistenceContext& context) saveLoadModifier; \ - using TPhoenix2SupportTag = type; \ \ private: \ static const ::NYT::NPhoenix2::NDetail::TRuntimeFieldDescriptorMap<type, TLoadContext>& GetRuntimeFieldDescriptorMap() @@ -93,34 +89,14 @@ public: \ return map; \ } \ \ - void SaveImpl(TSaveContext& context) const saveLoadModifier \ - { \ - ::NYT::NPhoenix2::NDetail::SaveImpl(this, context); \ - } \ - \ - void LoadImpl(TLoadContext& context) saveLoadModifier \ - { \ - ::NYT::NPhoenix2::NDetail::LoadImpl(this, context); \ - } \ - \ void Save(TSaveContext& context) const saveLoadModifier \ { \ - const_cast<type*>(this)->Persist(context); \ + ::NYT::NPhoenix2::NDetail::SaveImpl(this, context); \ } \ \ void Load(TLoadContext& context) saveLoadModifier \ { \ - Persist(context); \ - } \ - \ - void Persist(const TPersistenceContext& context) saveLoadModifier \ - { \ - if (context.IsSave()) { \ - type::SaveImpl(context.SaveContext()); \ - } else { \ - YT_VERIFY(context.IsLoad()); \ - type::LoadImpl(context.LoadContext()); \ - } \ + ::NYT::NPhoenix2::NDetail::LoadImpl(this, context); \ } #define PHOENIX_DECLARE_TEMPLATE_TYPE(type, typeTag) \ @@ -134,6 +110,28 @@ public: \ [[maybe_unused]] static constexpr auto TypeTag = ::NYT::NPhoenix2::TTypeTag(typeTagValue); \ static const ::NYT::NPhoenix2::TTypeDescriptor& GetTypeDescriptor() +#define PHOENIX_INHERIT_POLYMORPHIC_TYPE(baseType, type, tag) \ +class type \ + : public baseType \ +{ \ +public: \ + using baseType::baseType; \ + \ +private: \ + PHOENIX_DECLARE_POLYMORPHIC_TYPE(type, tag); \ +} + +#define PHOENIX_INHERIT_POLYMORPHIC_TEMPLATE_TYPE(baseType, type, tag, ...) \ +class type \ + : public baseType<__VA_ARGS__> \ +{ \ +public: \ + using baseType::baseType; \ + \ +private: \ + PHOENIX_DECLARE_POLYMORPHIC_TYPE(type, tag); \ +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NPhoenix2::NDetail diff --git a/yt/yt/core/phoenix/type_def-inl.h b/yt/yt/core/phoenix/type_def-inl.h index 91d3e6e6b2..59535a02ec 100644 --- a/yt/yt/core/phoenix/type_def-inl.h +++ b/yt/yt/core/phoenix/type_def-inl.h @@ -4,7 +4,6 @@ #include "type_def.h" #endif -#include "concepts.h" #include "factory.h" #include "polymorphic.h" #include "context.h" @@ -42,34 +41,14 @@ namespace NYT::NPhoenix2::NDetail { return map; \ } \ \ - void type::SaveImpl(TSaveContext& context) const \ - { \ - ::NYT::NPhoenix2::NDetail::SaveImpl(this, context); \ - } \ - \ - void type::LoadImpl(TLoadContext& context) \ - { \ - ::NYT::NPhoenix2::NDetail::LoadImpl(this, context); \ - } \ - \ void type::Save(TSaveContext& context) const \ { \ - const_cast<type*>(this)->Persist(context); \ + ::NYT::NPhoenix2::NDetail::SaveImpl(this, context); \ } \ \ void type::Load(TLoadContext& context) \ { \ - Persist(context); \ - } \ - \ - void type::Persist(const TPersistenceContext& context) \ - { \ - if (context.IsSave()) { \ - type::SaveImpl(context.SaveContext()); \ - } else { \ - YT_VERIFY(context.IsLoad()); \ - type::LoadImpl(context.LoadContext()); \ - } \ + ::NYT::NPhoenix2::NDetail::LoadImpl(this, context); \ } \ \ template <class T> \ @@ -322,26 +301,11 @@ public: { } template <class TBase> - requires SupportsPhoenix2<TBase> - void BaseType() - { - This_->TBase::SaveImpl(Context_); - } - - template <class TBase> - requires (!SupportsPhoenix2<TBase> && !SupportsPersist<TBase, TContext>) void BaseType() { This_->TBase::Save(Context_); } - template <class TBase> - requires (!SupportsPhoenix2<TBase> && SupportsPersist<TBase, TContext>) - void BaseType() - { - const_cast<TThis*>(This_)->TBase::Persist(Context_); - } - private: const TThis* const This_; TContext& Context_; @@ -523,26 +487,11 @@ public: { } template <class TBase> - requires SupportsPhoenix2<TBase> - void BaseType() - { - This_->TBase::LoadImpl(Context_); - } - - template <class TBase> - requires (!SupportsPhoenix2<TBase> && !SupportsPersist<TBase, TContext>) void BaseType() { This_->TBase::Load(Context_); } - template <class TBase> - requires (!SupportsPhoenix2<TBase> && SupportsPersist<TBase, TContext>) - void BaseType() - { - This_->TBase::Persist(Context_); - } - private: TThis* const This_; TContext& Context_; @@ -650,7 +599,7 @@ public: : This_(other.This_) , Context_(other.Context_) , Name_(other.Name_) - , LoadHandler_(other.LoadHandler) + , LoadHandler_(other.LoadHandler_) , MinVersion_(other.MinVersion_) , BeforeVersion_(other.BeforeVersion_) , VersionFilter_(other.VersionFilter_) diff --git a/yt/yt/core/profiling/unittests/timer_ut.cpp b/yt/yt/core/profiling/unittests/timer_ut.cpp index 6c7720288c..c1cce5c44d 100644 --- a/yt/yt/core/profiling/unittests/timer_ut.cpp +++ b/yt/yt/core/profiling/unittests/timer_ut.cpp @@ -6,7 +6,8 @@ #include <yt/yt/core/misc/lazy_ptr.h> #include <yt/yt/core/misc/blob_output.h> -#include <yt/yt/core/misc/phoenix.h> + +#include <yt/yt/core/phoenix/context.h> #include <util/generic/cast.h> @@ -14,7 +15,7 @@ namespace NYT::NProfiling { namespace { using namespace NConcurrency; -using namespace NPhoenix; +using namespace NPhoenix2; //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/ya.make b/yt/yt/core/ya.make index 04c85cab3a..e6f1868960 100644 --- a/yt/yt/core/ya.make +++ b/yt/yt/core/ya.make @@ -143,7 +143,6 @@ SRCS( misc/relaxed_mpsc_queue.cpp misc/parser_helpers.cpp misc/pattern_formatter.cpp - misc/phoenix.cpp misc/pool_allocator.cpp misc/proc.cpp misc/process_exit_profiler.cpp |