-
Notifications
You must be signed in to change notification settings - Fork 4
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
New export_tokens path strategy #8
Conversation
* breaks reading tokens from private modules
would love your thoughts on this if you have any @thiolliere |
I see now that it is limiting the features of The main advantage of this PR implementation IMO is that path feels more natural and there is no conflict if 2 pallets declare the same reexport: But if we don't want that we can fix the issue paritytech/substrate#14287 by requiring in attribute the correct path which should points to the item at the crate root, and search for #[derive_impl(bar::frame_system::TestDefaultConfig as frame_system::DefaultConfig)] instead of #[derive_impl(bar::frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] and then we search for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes implementation is good to me 👍
let Some(last_seg) = item_path.segments.last() else { unreachable!("must have at least one segment") }; | ||
let mut leading_segs = item_path | ||
.segments | ||
.iter() | ||
.cloned() | ||
.map(|seg| seg.ident) | ||
.collect::<Vec<_>>()[0..item_path.segments.len() - 1] | ||
.to_vec(); | ||
let last_seg = export_tokens_macro_ident(&last_seg.ident); | ||
leading_segs.push(last_seg); | ||
parse_quote!(#(#leading_segs)::*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this is slightly cleaner as we don't loose the path leading colon, what do you think?
let Some(last_seg) = item_path.segments.last() else { unreachable!("must have at least one segment") }; | |
let mut leading_segs = item_path | |
.segments | |
.iter() | |
.cloned() | |
.map(|seg| seg.ident) | |
.collect::<Vec<_>>()[0..item_path.segments.len() - 1] | |
.to_vec(); | |
let last_seg = export_tokens_macro_ident(&last_seg.ident); | |
leading_segs.push(last_seg); | |
parse_quote!(#(#leading_segs)::*) | |
let mut macro_path = item_path.clone(); | |
let Some(syn::punctuated::Pair::End(last_seg)) = macro_path.segments.pop() | |
else { unreachable!("Path must have a last segment") }; | |
let last_seg = export_tokens_macro_ident(&last_seg.ident); | |
macro_path.segments.push(last_seg.into()); | |
macro_path |
Thinking again, we could do 2 attribute macros: |
Yes, am working on something like the 2 attribute approach you mentioned |
Yeah upon further thought and investigation I think it is worth it to do a breaking change and drop this (accessing private items) feature for now. No one I have spoken to is using this, and to be fair, if someone has enough control over the code to add |
This fulfills item 2 from #3
With this new strategy, we can now properly access
#[export_tokens]
declarations as real items within the modules in which they are defined, instead of faking it and accessing them from the #[macro_export] created at the crate root.This is a breaking change since it is no longer possible (at least with how the macros are written currently) to do two things that used to be possible:
#[export_tokens]
declarations that are inside of things like functions that are not accessible at the module level#[export_tokens]
declarations that are in private modulesI think this is largely OK if we have to drop support for this, but I would still like to brainstorm some possible workarounds so we can still make these work, possibly with some additional opt-in macro argument.