From 0d644ca084f4f83271e30793d5618638016baf32 Mon Sep 17 00:00:00 2001 From: Jeeyong Um <conr2d@proton.me> Date: Thu, 30 Jan 2025 18:33:26 +0900 Subject: [PATCH] Replace derivative dependency with derive-where (#7324) # Description Close #7122. This PR replaces the unmaintained `derivative` dependency with `derive-where`. ## Integration This PR doesn't change the public interfaces. ## Review Notes The `derivative` crate, previously used to derive basic traits for structs with generics or enums, is no longer actively maintained. It has been replaced with the `derive-where` crate, which offers a more straightforward syntax while providing the same features as `derivative`. --------- Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- cumulus/pallets/weight-reclaim/Cargo.toml | 2 +- cumulus/pallets/weight-reclaim/src/lib.rs | 11 +++-------- polkadot/xcm/Cargo.toml | 2 +- polkadot/xcm/src/lib.rs | 14 ++++---------- polkadot/xcm/src/v3/mod.rs | 17 +++++------------ polkadot/xcm/src/v4/mod.rs | 17 +++++------------ polkadot/xcm/src/v5/mod.rs | 17 +++++------------ prdoc/pr_7324.prdoc | 17 +++++++++++++++++ 10 files changed, 44 insertions(+), 59 deletions(-) create mode 100644 prdoc/pr_7324.prdoc diff --git a/Cargo.lock b/Cargo.lock index 35d8926bb39..6448c77d245 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5103,7 +5103,7 @@ version = "1.0.0" dependencies = [ "cumulus-primitives-proof-size-hostfunction 0.2.0", "cumulus-primitives-storage-weight-reclaim 1.0.0", - "derivative", + "derive-where", "docify", "frame-benchmarking 28.0.0", "frame-support 28.0.0", @@ -28260,7 +28260,7 @@ version = "7.0.0" dependencies = [ "array-bytes", "bounded-collections", - "derivative", + "derive-where", "environmental", "frame-support 28.0.0", "hex", diff --git a/Cargo.toml b/Cargo.toml index 36c048d77c8..0d415fe4fdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -740,8 +740,8 @@ cumulus-test-relay-sproof-builder = { path = "cumulus/test/relay-sproof-builder" cumulus-test-runtime = { path = "cumulus/test/runtime" } cumulus-test-service = { path = "cumulus/test/service" } curve25519-dalek = { version = "4.1.3" } -derivative = { version = "2.2.0", default-features = false } derive-syn-parse = { version = "0.2.0" } +derive-where = { version = "1.2.7" } derive_more = { version = "0.99.17", default-features = false } digest = { version = "0.10.3", default-features = false } directories = { version = "5.0.1" } diff --git a/cumulus/pallets/weight-reclaim/Cargo.toml b/cumulus/pallets/weight-reclaim/Cargo.toml index 8bde6abaff6..d412a9b105d 100644 --- a/cumulus/pallets/weight-reclaim/Cargo.toml +++ b/cumulus/pallets/weight-reclaim/Cargo.toml @@ -27,7 +27,7 @@ frame-system = { workspace = true } # Other dependencies codec = { features = ["derive"], workspace = true } -derivative = { features = ["use_core"], workspace = true } +derive-where = { workspace = true } docify = { workspace = true } log = { workspace = true, default-features = true } scale-info = { features = ["derive"], workspace = true } diff --git a/cumulus/pallets/weight-reclaim/src/lib.rs b/cumulus/pallets/weight-reclaim/src/lib.rs index bd9929033af..7bbd2cf29d8 100644 --- a/cumulus/pallets/weight-reclaim/src/lib.rs +++ b/cumulus/pallets/weight-reclaim/src/lib.rs @@ -29,7 +29,7 @@ extern crate alloc; use alloc::vec::Vec; use codec::{Decode, Encode}; use cumulus_primitives_storage_weight_reclaim::get_proof_size; -use derivative::Derivative; +use derive_where::derive_where; use frame_support::{ dispatch::{DispatchInfo, PostDispatchInfo}, pallet_prelude::Weight, @@ -83,13 +83,8 @@ pub mod pallet { /// calculates the unused weight using the post information and reclaim the unused weight. /// So this extension can be used as a drop-in replacement for `WeightReclaim` extension for /// parachains. -#[derive(Encode, Decode, TypeInfo, Derivative)] -#[derivative( - Clone(bound = "S: Clone"), - Eq(bound = "S: Eq"), - PartialEq(bound = "S: PartialEq"), - Default(bound = "S: Default") -)] +#[derive(Encode, Decode, TypeInfo)] +#[derive_where(Clone, Eq, PartialEq, Default; S)] #[scale_info(skip_type_params(T))] pub struct StorageWeightReclaim<T, S>(pub S, core::marker::PhantomData<T>); diff --git a/polkadot/xcm/Cargo.toml b/polkadot/xcm/Cargo.toml index e90354e4e6a..f5f824ee409 100644 --- a/polkadot/xcm/Cargo.toml +++ b/polkadot/xcm/Cargo.toml @@ -15,7 +15,7 @@ workspace = true array-bytes = { workspace = true, default-features = true } bounded-collections = { features = ["serde"], workspace = true } codec = { features = ["derive", "max-encoded-len"], workspace = true } -derivative = { features = ["use_core"], workspace = true } +derive-where = { workspace = true } environmental = { workspace = true } frame-support = { workspace = true } hex-literal = { workspace = true, default-features = true } diff --git a/polkadot/xcm/src/lib.rs b/polkadot/xcm/src/lib.rs index a41a8e797b0..2271835a9a5 100644 --- a/polkadot/xcm/src/lib.rs +++ b/polkadot/xcm/src/lib.rs @@ -25,7 +25,7 @@ extern crate alloc; use codec::{Decode, DecodeLimit, Encode, Error as CodecError, Input, MaxEncodedLen}; -use derivative::Derivative; +use derive_where::derive_where; use frame_support::dispatch::GetDispatchInfo; use scale_info::TypeInfo; @@ -88,13 +88,7 @@ macro_rules! versioned_type { $(#[$index5:meta])+ V5($v5:ty), }) => { - #[derive(Derivative, Encode, Decode, TypeInfo)] - #[derivative( - Clone(bound = ""), - Eq(bound = ""), - PartialEq(bound = ""), - Debug(bound = "") - )] + #[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(replace_segment("staging_xcm", "xcm"))] @@ -311,8 +305,8 @@ versioned_type! { } /// A single XCM message, together with its version code. -#[derive(Derivative, Encode, Decode, TypeInfo)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Encode, Decode, TypeInfo)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(RuntimeCall))] diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index b60209a440c..6ae987a9830 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -28,7 +28,7 @@ use codec::{ MaxEncodedLen, }; use core::{fmt::Debug, result}; -use derivative::Derivative; +use derive_where::derive_where; use scale_info::TypeInfo; mod junction; @@ -57,8 +57,8 @@ pub const VERSION: super::Version = 3; /// An identifier for a query. pub type QueryId = u64; -#[derive(Derivative, Default, Encode, TypeInfo)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Default, Encode, TypeInfo)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[scale_info(bounds(), skip_type_params(Call))] #[scale_info(replace_segment("staging_xcm", "xcm"))] @@ -474,15 +474,8 @@ impl XcmContext { /// /// This is the inner XCM format and is version-sensitive. Messages are typically passed using the /// outer XCM format, known as `VersionedXcm`. -#[derive( - Derivative, - Encode, - Decode, - TypeInfo, - xcm_procedural::XcmWeightInfoTrait, - xcm_procedural::Builder, -)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(Call))] diff --git a/polkadot/xcm/src/v4/mod.rs b/polkadot/xcm/src/v4/mod.rs index a0ce551b760..66816e2fb6e 100644 --- a/polkadot/xcm/src/v4/mod.rs +++ b/polkadot/xcm/src/v4/mod.rs @@ -35,7 +35,7 @@ use codec::{ MaxEncodedLen, }; use core::{fmt::Debug, result}; -use derivative::Derivative; +use derive_where::derive_where; use frame_support::dispatch::GetDispatchInfo; use scale_info::TypeInfo; @@ -65,8 +65,8 @@ pub const VERSION: super::Version = 4; /// An identifier for a query. pub type QueryId = u64; -#[derive(Derivative, Default, Encode, TypeInfo)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Default, Encode, TypeInfo)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(Call))] @@ -436,15 +436,8 @@ impl XcmContext { /// /// This is the inner XCM format and is version-sensitive. Messages are typically passed using the /// outer XCM format, known as `VersionedXcm`. -#[derive( - Derivative, - Encode, - Decode, - TypeInfo, - xcm_procedural::XcmWeightInfoTrait, - xcm_procedural::Builder, -)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(Call))] diff --git a/polkadot/xcm/src/v5/mod.rs b/polkadot/xcm/src/v5/mod.rs index 21845d07529..51f6d839e97 100644 --- a/polkadot/xcm/src/v5/mod.rs +++ b/polkadot/xcm/src/v5/mod.rs @@ -29,7 +29,7 @@ use codec::{ MaxEncodedLen, }; use core::{fmt::Debug, result}; -use derivative::Derivative; +use derive_where::derive_where; use scale_info::TypeInfo; mod asset; @@ -59,8 +59,8 @@ pub const VERSION: super::Version = 5; /// An identifier for a query. pub type QueryId = u64; -#[derive(Derivative, Default, Encode, TypeInfo)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Default, Encode, TypeInfo)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(Call))] @@ -378,15 +378,8 @@ impl XcmContext { /// /// This is the inner XCM format and is version-sensitive. Messages are typically passed using the /// outer XCM format, known as `VersionedXcm`. -#[derive( - Derivative, - Encode, - Decode, - TypeInfo, - xcm_procedural::XcmWeightInfoTrait, - xcm_procedural::Builder, -)] -#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))] +#[derive(Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)] +#[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(Call))] diff --git a/prdoc/pr_7324.prdoc b/prdoc/pr_7324.prdoc new file mode 100644 index 00000000000..e4fb7db7817 --- /dev/null +++ b/prdoc/pr_7324.prdoc @@ -0,0 +1,17 @@ +title: Replace derivative dependency with derive-where +author: conr2d +topic: runtime + +doc: +- audience: Runtime Dev + description: |- + The `derivative` crate, previously used to derive basic traits for structs with + generics or enums, is no longer actively maintained. It has been replaced with + the `derive-where` crate, which offers a more straightforward syntax while + providing the same features as `derivative`. + +crates: + - name: cumulus-pallet-weight-reclaim + bump: patch + - name: staging-xcm + bump: patch -- GitLab