Skip to content

Commit

Permalink
Replace derivative dependency with derive-where (paritytech#7324)
Browse files Browse the repository at this point in the history
# Description

Close paritytech#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 <[email protected]>
  • Loading branch information
conr2d and gui1117 authored Jan 30, 2025
1 parent 80e30ec commit 0d644ca
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/weight-reclaim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 3 additions & 8 deletions cumulus/pallets/weight-reclaim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>);

Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 4 additions & 10 deletions polkadot/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"))]
Expand Down Expand Up @@ -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))]
Expand Down
17 changes: 5 additions & 12 deletions polkadot/xcm/src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))]
Expand Down Expand Up @@ -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))]
Expand Down
17 changes: 5 additions & 12 deletions polkadot/xcm/src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))]
Expand Down Expand Up @@ -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))]
Expand Down
17 changes: 5 additions & 12 deletions polkadot/xcm/src/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))]
Expand Down Expand Up @@ -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))]
Expand Down
17 changes: 17 additions & 0 deletions prdoc/pr_7324.prdoc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0d644ca

Please sign in to comment.