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

Restructure frame_support macro related exports #14745

Merged
merged 33 commits into from
Aug 23, 2023

Conversation

juangirini
Copy link
Contributor

@juangirini juangirini commented Aug 10, 2023

@juangirini
Copy link
Contributor Author

bot fmt

@command-bot
Copy link

command-bot bot commented Aug 14, 2023

@juangirini https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3379775 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". 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 bot cancel 30-ab51b0e6-b330-4de7-a7f0-3557e9051f13 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Aug 14, 2023

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

@juangirini juangirini changed the title [WIP] Restructure macro related exports Restructure macro related exports Aug 15, 2023
@juangirini juangirini marked this pull request as ready for review August 15, 2023 16:20
@juangirini juangirini requested review from a team August 15, 2023 16:20
@juangirini juangirini requested a review from athei as a code owner August 15, 2023 16:20
@juangirini juangirini requested a review from bkchr August 16, 2023 11:05
@juangirini
Copy link
Contributor Author

bot fmt

@command-bot
Copy link

command-bot bot commented Aug 16, 2023

@juangirini https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3401090 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". 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 bot cancel 37-5bad9448-a260-4c19-941b-b85f3335db38 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Aug 16, 2023

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

@ggwpez
Copy link
Member

ggwpez commented Aug 16, 2023

This is going to lead to quite a bit of downstream breaking changes. I seem to recall @kianenigma was suggesting that we hide a lot of common imports under one crate ( #14137 ) - this seems like going in the opposite direction? If we're going to do both then it would be kinder for downstream if we landed both PRs at the same time as downstream would probably then have less work to update their codebases.

@gilescope it should not break downstream - unless downstream used internal re-exports, which is a crime anyway…
We now just make the fact that they are internal, more explicit.

Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

Looks fine. Although I am a bit surprised to see this __private syntax. Doesn't feel very Rust-like. Why do we need to use it so much in macros?

Comment on lines +449 to +455
let __benchmarked_call_encoded = $crate::frame_support::__private::codec::Encode::encode(
&__call
);
}: {
let __call_decoded = <
Call<T $(, $instance )?>
as $crate::frame_support::codec::Decode
as $crate::frame_support::__private::codec::Decode
Copy link
Contributor

Choose a reason for hiding this comment

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

this feels..wrong.

curious why we need to do it this way, and can't just pull Encode and Decode from their codec crate.

Copy link
Member

Choose a reason for hiding this comment

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

To make it correct, you would need to re-export codec from frame-benchmarking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, benchmarking re-exports will follow in the parent issue https://github.com/paritytech/substrate/issues/14213

Copy link
Member

Choose a reason for hiding this comment

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

Because its a macro that emits code. The emitted code cannot make the assumption that codec is in the Cargo.toml of the crate that it is being used by.
We therefore need to ship a macro will all exports that it needs.

frame/session/benchmarking/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +71 to +74
#scrate::__private::codec::Encode,
#scrate::__private::codec::Decode,
#scrate::__private::scale_info::TypeInfo,
#scrate::__private::RuntimeDebug,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better way? 😄

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 know it looks weird, but it seems like the "less bad" solution to make it obvious that those re-exports are not supposed to be used externally

Copy link
Contributor

Choose a reason for hiding this comment

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

This actually isn't that bad, since macro-generated code is not part of "surface syntax". I think most people do expect code expanded this way to be sort of internal after all -- if you want to convince yourself more, try looking at the __is_call_part_defined_{num} macros that gets automatically generated and exported while we process #[pallet::call].

frame/support/src/lib.rs Show resolved Hide resolved
pub use codec::{
Codec, Decode, Encode, EncodeAsRef, EncodeLike, HasCompact, Input, MaxEncodedLen, Output,
};
pub use scale_info::TypeInfo;
Copy link
Member

Choose a reason for hiding this comment

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

Most of these exports here are should also be private, but yeah do this later.

Comment on lines +449 to +455
let __benchmarked_call_encoded = $crate::frame_support::__private::codec::Encode::encode(
&__call
);
}: {
let __call_decoded = <
Call<T $(, $instance )?>
as $crate::frame_support::codec::Decode
as $crate::frame_support::__private::codec::Decode
Copy link
Member

Choose a reason for hiding this comment

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

To make it correct, you would need to re-export codec from frame-benchmarking.

@juangirini
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@juangirini
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@juangirini
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@juangirini
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

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. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D2-breaksapi T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants