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

Restructure frame_support macro related exports - #14745

Merged
paritytech-processbot[bot] merged 33 commits into
masterfrom
jg/restructure-macro-related-exports
Aug 23, 2023
Merged

Restructure frame_support macro related exports#14745
paritytech-processbot[bot] merged 33 commits into
masterfrom
jg/restructure-macro-related-exports

Conversation

@juangirini

@juangirinijuangirini commented Aug 10, 2023

Copy link
Copy Markdown
Contributor

@juangirini

Copy link
Copy Markdown
ContributorAuthor

bot fmt

@command-bot

command-botBot commented Aug 14, 2023

Copy link
Copy Markdown

@juangirinihttps://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
Copy Markdown

@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.

@juangirinijuangirini changed the title [WIP] Restructure macro related exportsRestructure macro related exportsAug 15, 2023
@juangirini
juangirini marked this pull request as ready for review August 15, 2023 16:20
@juangirini
juangirini requested review from a teamAugust 15, 2023 16:20
@juangirini
juangirini requested a review from athei as a code ownerAugust 15, 2023 16:20
@juangirini
juangirini requested a review from bkchrAugust 16, 2023 11:05
@juangirini

Copy link
Copy Markdown
ContributorAuthor

bot fmt

@command-bot

command-botBot commented Aug 16, 2023

Copy link
Copy Markdown

@juangirinihttps://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
Copy Markdown

@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

ggwpez commented Aug 16, 2023

Copy link
Copy Markdown
Member

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.

@liamaharonliamaharon left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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.

Comment threadframe/session/benchmarking/src/lib.rs Outdated
Comment on lines +71 to +74
#scrate::__private::codec::Encode,
#scrate::__private::codec::Decode,
#scrate::__private::scale_info::TypeInfo,
#scrate::__private::RuntimeDebug,

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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].

Comment threadframe/support/src/lib.rs
pub use codec::{
Codec, Decode, Encode, EncodeAsRef, EncodeLike, HasCompact, Input, MaxEncodedLen, Output,
};
pub use scale_info::TypeInfo;

Copy link
Copy Markdown
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
Copy Markdown
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.

juangiriniand others added 3 commits August 17, 2023 10:03
@juangirini

Copy link
Copy Markdown
ContributorAuthor

bot rebase

@paritytech-processbot

Copy link
Copy Markdown

Rebased

@juangirini

Copy link
Copy Markdown
ContributorAuthor

bot rebase

@paritytech-processbot

Copy link
Copy Markdown

Rebased

@juangirini

Copy link
Copy Markdown
ContributorAuthor

bot rebase

@paritytech-processbot

Copy link
Copy Markdown

Rebased

@juangirini

Copy link
Copy Markdown
ContributorAuthor

bot merge

@paritytech-processbot

Copy link
Copy Markdown

Waiting for commit status.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_reviewPull request needs code review.B1-note_worthyChanges should be noted in the release notesC1-lowPR touches the given topic and has a low impact on builders.D2-breaksapiT1-runtimeThis PR/Issue is related to the topic “runtime”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@juangirini@ggwpez@gilescope@bkchr@KiChjang@liamaharon