Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bfc3ff7
Adds ability to use defaults for verbatim types
gupnik Jul 30, 2023
18dc0ac
Adds RuntimeOrigin and PalletInfo in DefaultConfig
gupnik Jul 30, 2023
7fb9749
Adds RuntimeEvent in DefaultConfig
gupnik Jul 30, 2023
43fff80
Adds RuntimeEvent in DefaultConfig
gupnik Jul 30, 2023
8e45209
Minor fix
gupnik Jul 30, 2023
9af59d6
Minor fix
gupnik Jul 30, 2023
44f2845
Everything in frame_system can now have a default
gupnik Jul 30, 2023
eed9dc8
Adds docs
gupnik Aug 4, 2023
d2a3546
Adds UI Test for no_bounds
gupnik Aug 4, 2023
821424a
Updates docs
gupnik Aug 4, 2023
5e54173
Adds UI tests for verbatim
gupnik Aug 4, 2023
cd3e530
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 4, 2023
641cc9b
Minor update
gupnik Aug 4, 2023
90af58e
Minor updates
gupnik Aug 4, 2023
c3f5134
Minor updates
gupnik Aug 4, 2023
7f80e65
Addresses review comments
gupnik Aug 9, 2023
38c0601
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 9, 2023
846f296
Fixes test
gupnik Aug 9, 2023
6dfb929
Update frame/support/procedural/src/derive_impl.rs
gupnik Aug 13, 2023
0ddf452
Minor fix
gupnik Aug 13, 2023
3e90665
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 14, 2023
de6e5b6
Minor
gupnik Aug 14, 2023
ce1ad29
Optionally keep verbatim to be replaced later
gupnik Aug 14, 2023
821758b
Fixes build
gupnik Aug 14, 2023
d33f51f
Uses runtime_type
gupnik Aug 15, 2023
96fc62c
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 17, 2023
e051985
Fixes comment
gupnik Aug 17, 2023
16028ff
Fixes comment
gupnik Aug 17, 2023
34f66f6
Fixes test
gupnik Aug 17, 2023
97e470c
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 17, 2023
92ddd1e
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 17, 2023
3524c14
Uses no_aggregated_types as an option in derive_impl
gupnik Aug 21, 2023
1218faf
Uses specific imports
gupnik Aug 21, 2023
01071a9
Fmt
gupnik Aug 21, 2023
a3db9f4
Updates doc
gupnik Aug 21, 2023
28f7cec
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 22, 2023
9d31723
Update frame/support/procedural/src/derive_impl.rs
gupnik Aug 23, 2023
3f1fcc6
Update frame/support/procedural/src/derive_impl.rs
gupnik Aug 23, 2023
58762cf
Addresses review comment
gupnik Aug 23, 2023
cb2a8e0
Addresses review comment
gupnik Aug 23, 2023
32f33ae
fmt
gupnik Aug 23, 2023
88f6253
Renames test files
gupnik Aug 23, 2023
bb30704
Adds docs using docify
gupnik Aug 24, 2023
8f3191f
Fixes test
gupnik Aug 24, 2023
718c1ce
Fixes UI tests
gupnik Aug 24, 2023
969bf0e
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
…derive-impl-improvements
  • Loading branch information
gupnik committed Aug 14, 2023
commit 3e90665416c0921493cd0889f05be8f2a8cfb80a
5 changes: 3 additions & 2 deletions frame/examples/default-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ pub mod pallet {
#[cfg(any(test, doc))]
pub mod tests {
use super::*;
use frame_support::derive_impl;
use frame_support::{derive_impl, parameter_types};
use pallet::{self as pallet_default_config_example, config_preludes::*};

type Block = frame_system::mocking::MockBlock<Runtime>;

Expand All @@ -144,7 +145,7 @@ pub mod tests {
);

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
impl frame_system::Config for Runtime {
// all of this is coming from `frame_system::config_preludes::TestDefaultConfig`.

// type Nonce = u32;
Expand Down
1 change: 0 additions & 1 deletion frame/multisig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ std = [
"sp-runtime/std",
"sp-std/std",
"pallet-balances/std",
"sp-core/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
71 changes: 40 additions & 31 deletions frame/support/procedural/src/pallet/expand/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,49 @@ Consequently, a runtime that wants to include this pallet must implement this tr
);

// we only emit `DefaultConfig` if there are trait items, so an empty `DefaultConfig` is
// impossible consequently
if config.default_sub_trait.len() > 0 {
let trait_items = &config
.default_sub_trait
.iter()
.map(|item| {
if item.1 {
if let syn::TraitItem::Type(item) = item.0.clone() {
let mut item = item.clone();
item.bounds.clear();
syn::TraitItem::Type(item)
// impossible consequently.
match &config.default_sub_trait {
Some(default_sub_trait) if default_sub_trait.items.len() > 0 => {
let trait_items = &config
.default_sub_trait
.iter()
.map(|item| {
if item.1 {
if let syn::TraitItem::Type(item) = item.0.clone() {
let mut item = item.clone();
item.bounds.clear();
syn::TraitItem::Type(item)
} else {
item.0.clone()
}
} else {
item.0.clone()
}
} else {
item.0.clone()
})
.collect::<Vec<_>>();

let type_param_bounds = if default_sub_trait.has_system {
let system = &def.frame_system;
quote::quote!(: #system::DefaultConfig)
} else {
quote::quote!()
};

quote!(
/// Based on [`Config`]. Auto-generated by
/// [`#[pallet::config(with_default)]`](`frame_support::pallet_macros::config`).
/// Can be used in tandem with
/// [`#[register_default_config]`](`frame_support::register_default_config`) and
/// [`#[derive_impl]`](`frame_support::derive_impl`) to derive test config traits
/// based on existing pallet config traits in a safe and developer-friendly way.
///
/// See [here](`frame_support::pallet_macros::config`) for more information and caveats about
/// the auto-generated `DefaultConfig` trait and how it is generated.
pub trait DefaultConfig #type_param_bounds {
#(#trait_items)*
}
})
.collect::<Vec<_>>();
quote!(
/// Based on [`Config`]. Auto-generated by
/// [`#[pallet::config(with_default)]`](`frame_support::pallet_macros::config`).
/// Can be used in tandem with
/// [`#[register_default_config]`](`frame_support::register_default_config`) and
/// [`#[derive_impl]`](`frame_support::derive_impl`) to derive test config traits
/// based on existing pallet config traits in a safe and developer-friendly way.
///
/// See [here](`frame_support::pallet_macros::config`) for more information and caveats about
/// the auto-generated `DefaultConfig` trait and how it is generated.
pub trait DefaultConfig {
#(#trait_items)*
}
)
} else {
Default::default()
)
},
_ => Default::default(),
}
}
19 changes: 11 additions & 8 deletions frame/support/procedural/src/pallet/parse/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ mod keyword {

#[derive(Default)]
pub struct DefaultTrait {
pub items: Vec<syn::TraitItem>,
/// A bool for each sub-trait item indicates whether the item has
/// `#[pallet::no_default_bounds]` attached to it. If true, the item will not have any bounds
/// in the generated default sub-trait.
pub items: Vec<(syn::TraitItem, bool)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an enum instead of a boolean in here?

Copy link
Contributor Author

@gupnik gupnik Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it adds a lot of value here. What are the enum variants that you would suggest?

pub has_system: bool,
}

Expand All @@ -65,12 +68,8 @@ pub struct ConfigDef {
///
/// Contains default sub-trait items (instantiated by `#[pallet::config(with_default)]`).
/// Vec will be empty if `#[pallet::config(with_default)]` is not specified or if there are
/// no trait items
///
/// A bool for each sub-trait item indicates whether the item has
/// `#[pallet::no_default_bounds]` attached to it. If true, the item will not have any bounds
/// in the generated default sub-trait.
pub default_sub_trait: Vec<(syn::TraitItem, bool)>,
/// no trait items.
pub default_sub_trait: Option<DefaultTrait>,
}

/// Input definition for a constant in pallet config.
Expand Down Expand Up @@ -431,7 +430,11 @@ impl ConfigDef {
}

if !already_no_default && enable_default {
default_sub_trait.push((trait_item.clone(), already_no_default_bounds));
default_sub_trait
.as_mut()
.expect("is 'Some(_)' if 'enable_default'; qed")
.items
.push((trait_item.clone(), already_no_default_bounds));
}
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.