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

Macros to use path instead of ident #1474

Merged
merged 34 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7102f28
use path instead of ident
juangirini Sep 8, 2023
933fd3f
fix clippy
juangirini Sep 8, 2023
dc43fa5
add path changes to frame_support
juangirini Sep 11, 2023
16668ca
add frame conditional
juangirini Sep 11, 2023
ebd13e3
remove references to the frame-crate
juangirini Sep 11, 2023
270a6b7
update fn description
juangirini Sep 11, 2023
8be65aa
update fn description
juangirini Sep 11, 2023
850a77e
make benchmarks to use generate_crate_access_2018
juangirini Sep 11, 2023
5ae6e07
undo unrelated changes
juangirini Sep 12, 2023
04dc503
undo unrelated changes
juangirini Sep 12, 2023
95444ae
update macro description
juangirini Sep 12, 2023
6a773d0
refactor `generate_crate_access`
juangirini Sep 12, 2023
bc17557
unhardcode codec import
juangirini Sep 13, 2023
6d9887b
bring in hypotetical frame crate
juangirini Sep 14, 2023
35747a1
refactor expected_system_config and add tests
juangirini Sep 15, 2023
330af4a
".git/.scripts/commands/fmt/fmt.sh"
Sep 15, 2023
10bf65c
make zepter happy
juangirini Sep 15, 2023
97bfec4
improve comment
juangirini Sep 21, 2023
6a07bb3
add event_type_bound_system_config_assoc_type test
juangirini Sep 22, 2023
f303276
implement review suggestions
juangirini Oct 2, 2023
963be94
implement review suggestions
juangirini Oct 2, 2023
76de90d
add dummy frame crate for testing
juangirini Oct 3, 2023
32f2f1e
add pallet test example with frame crate
juangirini Oct 4, 2023
877fdc3
wip
juangirini Oct 4, 2023
c89c0c7
make dummy pallet work with frame crate
juangirini Oct 4, 2023
8184085
add dummy pallet with frame crate
juangirini Oct 4, 2023
1ee920b
add min runtime ui test
juangirini Oct 6, 2023
5050625
simplify example pallet
juangirini Oct 12, 2023
55daf79
update comment
juangirini Oct 12, 2023
43ca2c2
zepter improvement
juangirini Oct 12, 2023
2a2b45f
Merge branch 'master' into jg/frame-crate-path
juangirini Oct 12, 2023
b55615b
fix broken test
juangirini Oct 12, 2023
d253b66
update compile test
juangirini Oct 13, 2023
d2009d3
fix todo
juangirini Oct 13, 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
remove references to the frame-crate
  • Loading branch information
juangirini committed Sep 11, 2023
commit ebd13e3dc47f83149e95c44c6194c9dc0459a5c0
24 changes: 3 additions & 21 deletions substrate/frame/support/procedural/src/pallet/parse/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

use super::helper;
use frame_support_procedural_tools::{get_doc_literals, is_using_frame_crate};
use frame_support_procedural_tools::get_doc_literals;
use quote::ToTokens;
use syn::{spanned::Spanned, token, Token};

Expand Down Expand Up @@ -235,16 +235,7 @@ fn check_event_type(

let has_is_type_bound = type_.bounds.iter().any(|s| {
syn::parse2::<IsTypeBoundEventParse>(s.to_token_stream()).map_or(false, |b| {
let mut expected_system_config = if is_using_frame_crate(&frame_system) {
// in this case we know that the only valid frame_system path is one that is
// `frame_system`, as `frame` re-exports it as such.
let fixed_frame_system =
syn::parse2::<syn::Path>(quote::quote!(frame_system))
.expect("is a valid path; qed");
fixed_frame_system
} else {
frame_system.clone()
};
let mut expected_system_config = frame_system.clone();
expected_system_config
.segments
.push(syn::PathSegment::from(syn::Ident::new("Config", b.0.span())));
Expand Down Expand Up @@ -346,16 +337,7 @@ impl ConfigDef {

let has_frame_system_supertrait = item.supertraits.iter().any(|s| {
syn::parse2::<syn::Path>(s.to_token_stream()).map_or(false, |b| {
let mut expected_system_config = if is_using_frame_crate(&frame_system) {
// in this case we know that the only valid supertrait is one that is
// `frame_system::Config`, as `frame` re-exports it as such.
let fixed_frame_system = syn::parse2::<syn::Path>(quote::quote!(frame_system))
.expect("is a valid path; qed");
fixed_frame_system
} else {
// a possible renamed frame-system, which is a direct dependency.
frame_system.clone()
};
let mut expected_system_config = frame_system.clone();
expected_system_config
.segments
.push(syn::PathSegment::from(syn::Ident::new("Config", b.span())));
Expand Down
26 changes: 1 addition & 25 deletions substrate/frame/support/procedural/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,10 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream {
}
}

/// Check if the output of [`generate_crate_access_2018`] (or generally another path) is using the
/// `frame` crate or not.
pub fn is_using_frame_crate(path: &syn::Path) -> bool {
path.segments.first().map(|s| s.ident == "frame").unwrap_or(false)
}

/// Generate the crate access for the crate using 2018 syntax.
///
/// If `frame` is in scope, it will use `frame::deps::<def_crate>`. Else, it will try and find
/// `<def_crate>` directly.
/// for `frame-support` output will for example be `frame_support`.
pub fn generate_crate_access_2018(def_crate: &str) -> Result<syn::Path, Error> {
juangirini marked this conversation as resolved.
Show resolved Hide resolved
if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") {
let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_"));
let path = syn::parse_str::<syn::Path>(&path)?;
return Ok(path)
}

let indent = match crate_name(def_crate) {
juangirini marked this conversation as resolved.
Show resolved Hide resolved
Ok(FoundCrate::Itself) => {
let name = def_crate.to_string().replace("-", "_");
Expand All @@ -79,17 +66,6 @@ pub fn generate_crate_access_2018(def_crate: &str) -> Result<syn::Path, Error> {
pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream {
let mod_name = generate_hidden_includes_mod_name(unique_id);

if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") {
let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_"));
let path = syn::parse_str::<syn::Path>(&path).expect("is a valid path; qed");
return quote::quote!(
#[doc(hidden)]
mod #mod_name {
pub use #path as hidden_include;
}
)
}

match crate_name(def_crate) {
Ok(FoundCrate::Itself) => quote!(),
Ok(FoundCrate::Name(name)) => {
Expand Down
7 changes: 0 additions & 7 deletions substrate/primitives/api/proc-macro/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ use syn::{

/// Generates the access to the `sc_client` crate.
pub fn generate_crate_access() -> TokenStream {
if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") {
// TODO: add test to make sure `frame` always contains `frame::deps::sp_api`.
// TODO: handle error.
let path = format!("{}::deps::{}", name, "sp_api");
let path = syn::parse_str::<syn::Path>(&path).unwrap();
return path.into_token_stream()
}
match crate_name("sp-api") {
Ok(FoundCrate::Itself) => quote!(sp_api),
Ok(FoundCrate::Name(renamed_name)) => {
Expand Down