Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage expansion in pallet section #6023

Merged
merged 7 commits into from
Oct 12, 2024

Conversation

eagr
Copy link
Contributor

@eagr eagr commented Oct 11, 2024

fixes #5320 @sam0x17 @gupnik

Description

The issue could be confirmed with the added example. The cause is for macro hygiene, entries in the #( #entries_builder )* expansion won't be able to reference the entries defined outside. The solution here is to allow the reference to be passed into the expansion with closure.

Or we could just switch to the unhygienic span with quote::quote! instead such that entries will resolve to the "outer" definition.

@eagr eagr requested a review from a team as a code owner October 11, 2024 10:19
@eagr
Copy link
Contributor Author

eagr commented Oct 12, 2024

For the added test, without the fix:

test tests/split_ui/pass/split_storage.rs [should pass] ... error
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0425]: cannot find value `entries` in this scope
 --> tests/split_ui/pass/storage.rs
  |
  |     #[pallet::storage]
  |               ^^^^^^^ not found in this scope
  |
 ::: tests/split_ui/pass/split_storage.rs:5:1
  |
5 | #[import_section(storage::storage)]
  | ----------------------------------- in this macro invocation
  |
  = note: this error originates in the macro `storage::__export_tokens_tt_storage` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `entries` in this scope
 --> tests/split_ui/pass/storage.rs
  |
  |     #[pallet::storage]
  |               ^^^^^^^ not found in this scope
  |
 ::: tests/split_ui/pass/split_storage.rs:5:1
  |
5 | #[import_section(storage::storage)]
  | ----------------------------------- in this macro invocation
  |
  = note: this error originates in the macro `storage::__export_tokens_tt_storage` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens` (in Nightly builds, run with -Z macro-backtrace for more info)

@paritytech-review-bot paritytech-review-bot bot requested a review from a team October 12, 2024 08:45
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

I'm surprise the code didn't compile.
New code is good, so it is good to me.

substrate/frame/support/test/tests/split_ui.rs Outdated Show resolved Hide resolved
@gui1117 gui1117 added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Oct 12, 2024
@eagr eagr requested review from bkchr and gui1117 October 12, 2024 19:59
@bkchr bkchr enabled auto-merge October 12, 2024 21:19
@bkchr bkchr added this pull request to the merge queue Oct 12, 2024
Merged via the queue into paritytech:master with commit d1c115b Oct 12, 2024
203 checks passed
ordian added a commit that referenced this pull request Oct 14, 2024
* master:
  Fix storage expansion in pallet section (#6023)
  /cmd: Improved devx of benching many pallets simultaneously (#6007)
Zebedeusz pushed a commit that referenced this pull request Oct 14, 2024
fixes #5320 @sam0x17 @gupnik 

# Description

The issue could be confirmed with the added example. The cause is for
macro hygiene, `entries` in the `#( #entries_builder )*` expansion won't
be able to reference the `entries` defined outside. The solution here is
to allow the reference to be passed into the expansion with closure.

Or we could just switch to the unhygienic span with `quote::quote!`
instead such that `entries` will resolve to the "outer" definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pallet_section not work for storage
3 participants