Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Proposal: Flatten AllPallets and similar types #11813

Merged
merged 18 commits into from
Aug 14, 2022

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Jul 11, 2022

Currently, all of the types generated via this macro are nested. For example, you have:

type AllPallets = (System, (Balances, Babe));

As far as I know, the main advantage of this is that we can use recursive implementations in some places. For example, PalletsInfoAccess introduced in https://github.com/paritytech/substrate/pull/10053/files is only implemented for (T1, T2), and there's no need to generate the code for longer tuples.

In fact, if we use only nested tuples, you can probably get away with impl_trait_for_tuple(2) for most items that are implemented for all pallets, such as OnInitialize etc.

The problem is: certain traits like OnInitialize are perfectly comprehensible both for T, and (T1, T2, T3), and (T1, (T2, T3)). But, certain traits like PalletInfoAccess are only comprehensible on individual items, i.e. T, but not on tuples.

And then you have an unfortunate scenario where you want to assert where T: PalletInfoAccess, and you know that each T does indeed implement PalletInfoAccess, but if demonstrated as a nested tuple, this does not work.

You can see a concrete example of this in what I am trying to do here: https://github.com/paritytech/substrate/pull/10174/files#diff-1c449417be9803cb427eed15d51557931141d47d0047561407f1651d319f7103R183

Lastly, in general, arguing about a flat array of tuples rather then nested is generally easier.

  • measure how slower it is to bump impl_trait_for_tuples to 100 instead of 30.

@github-actions github-actions bot added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jul 11, 2022
@kianenigma kianenigma marked this pull request as ready for review July 18, 2022 10:14
@kianenigma kianenigma added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jul 18, 2022
@kianenigma kianenigma requested a review from bkchr July 18, 2022 10:14
@kianenigma
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@kianenigma kianenigma added C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Aug 8, 2022
@kianenigma
Copy link
Contributor Author

/cmd queue -c fmt $

@command-bot
Copy link

command-bot bot commented Aug 8, 2022

@kianenigma Could not find start of command (" $ ")

@kianenigma
Copy link
Contributor Author

/cmd queue -c fmt

@command-bot
Copy link

command-bot bot commented Aug 8, 2022

@kianenigma Could not find start of command (" $ ")

@kianenigma
Copy link
Contributor Author

/cmd queue -c fmt $ 1

@command-bot
Copy link

command-bot bot commented Aug 8, 2022

@kianenigma https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1726286 was started for your command "$PIPELINE_SCRIPTS_DIR/fmt.sh" 1. Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment /cmd cancel 11-58e217d0-cfd8-4c51-94b8-464e4f4538b4 to cancel this command or /cmd cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Aug 8, 2022

@kianenigma Command "$PIPELINE_SCRIPTS_DIR/fmt.sh" 1 has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1726286 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1726286/artifacts/download.

@kianenigma kianenigma requested a review from bkchr August 11, 2022 06:42
frame/support/src/traits/metadata.rs Outdated Show resolved Hide resolved
frame/support/src/migrations.rs Outdated Show resolved Hide resolved

/// All pallets included in the runtime as a nested tuple of types.
/// Excludes the System pallet.
pub type AllPalletsWithoutSystem = ( #all_pallets_without_system );
pub type AllPalletsWithoutSystem = ( #(#names_without_system),* );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub type AllPalletsWithoutSystem = ( #(#names_without_system),* );
pub type AllPalletsWithoutSystem = ( #(#all_pallets_without_system),* );

Comment on lines 375 to 361
pub type AllPalletsWithoutSystemReversed = ( #all_pallets_without_system_reversed );
pub type AllPalletsWithoutSystemReversed =( #(#names_without_system_reverse),* );

/// All pallets included in the runtime as a nested tuple of types in reversed order.
pub type AllPalletsWithSystemReversed = ( #all_pallets_with_system_reversed );
pub type AllPalletsWithSystemReversed = ( #(#names_reversed),* );

/// All pallets included in the runtime as a nested tuple of types in reversed order.
/// With the system pallet first.
pub type AllPalletsReversedWithSystemFirst = (
#system_pallet,
AllPalletsWithoutSystemReversed
);
pub type AllPalletsReversedWithSystemFirst = ( #(#names_reversed_with_system_first),* );
Copy link
Member

Choose a reason for hiding this comment

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

I think we can probably now get rid of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would start by marking them as deprecated? or are you sure they are not needed anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah good idea.

@kianenigma
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1740275

@@ -1,13 +1,13 @@
error[E0107]: missing generics for trait `Hooks`
--> $DIR/hooks_invalid_item.rs:12:18
--> tests/pallet_ui/hooks_invalid_item.rs:12:18
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am a little bit unsure about why I had to change this, but I assume it is harmless.

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 669ed36 into master Aug 14, 2022
@paritytech-processbot paritytech-processbot bot deleted the kiz-flatten-all-pallets-type branch August 14, 2022 19:06
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* flratten AllPallets types

* feature flag it

* fix

* fix

* fmt

* remove todo

* Update frame/support/src/traits/metadata.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update frame/support/src/migrations.rs

Co-authored-by: Bastian Köcher <[email protected]>

* fix

* mark as deprecated

* add docs

* fix ui test?

* fmt

Co-authored-by: parity-processbot <>
Co-authored-by: Bastian Köcher <[email protected]>
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-release-analysis-v0-9-41-v0-9-42/2828/1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants