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

Allow for remapping type parameters in type substitutions #735

Merged
merged 7 commits into from
Jan 19, 2023

Conversation

Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Dec 1, 2022

Closes #666

For now, this moves type substitution annotations from the use statements outside, to the subxt macro + separates some substitution logic. Opening as a draft for now to get feedback; next thing to work on is to implement the generic wrangling/reordering mentioned in #666.

|SubstituteType { ty, with }| {
(
ty,
with.try_into()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be quite cryptic, but I didn't want to import the AbsoluteTypePath newtype wrapper that I introduced for the validation purpose (rather than it being a more well-rounded/useful type on its own), to name it directly here.

@Xanewok Xanewok marked this pull request as ready for review January 11, 2023 15:18
@Xanewok Xanewok changed the title Don't piggyback on use statements for type substitutions Allow for remapping type parameters in type substitutions Jan 11, 2023
@Xanewok
Copy link
Contributor Author

Xanewok commented Jan 11, 2023

Squashed and force-pushed now after #760 landed.

Implements variant specified in #666 (comment) (so uses new syntax as well). This now includes the ability to strip generics altogether for a source type or taking any combination of parameters from the source type.

This lacks the ability to specify concrete types becase we'd need to plug into type resolution as part of the substitution but since this PR refactored type substitution and made it more self-contained and introduced the new mapping feature, I figured we could do that in a follow-up PR.

@@ -115,13 +131,14 @@ pub fn generate_runtime_api_from_bytes(
item_mod: syn::ItemMod,
bytes: &[u8],
derives: DerivesRegistry,
type_substitutes: TypeSubstitutes,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super small nit: missing
/// * `type_substitutes` - Provide custom type substitutes.
on the doc.

Tho, I'm wondering if we should extend this documentation style to our repo, or just remove those # Arguments in the future. I guess the easiest would be later since we already have some comprehensive docs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good spot!

I added the extra param for now, though I'd note that these comments aren't exposed publically anywhere and so in general I'd be inclined to keep them simple as they are only for us devs who work on it anyway :)

@jsdw jsdw merged commit 977f2a3 into master Jan 19, 2023
@jsdw jsdw deleted the igor-type-substitutes branch January 19, 2023 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow substitute types to take on 0, 1 or all of the generic params from the types they stand in for
3 participants