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

Increase syn dependency lower bound to 2.0.0 #3682

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

mulkieran
Copy link
Member

@mulkieran mulkieran commented Sep 4, 2024

Closes #3650

@mulkieran mulkieran self-assigned this Sep 4, 2024
@mulkieran
Copy link
Member Author

stratisd_proc_macros compiles...but panics.

@mulkieran
Copy link
Member Author

Now panicking in a better place...

@mulkieran
Copy link
Member Author

compiles

@mulkieran mulkieran force-pushed the syn-2.0 branch 2 times, most recently from cba8b49 to d9a5d3e Compare September 4, 2024 19:54
@mulkieran mulkieran marked this pull request as ready for review September 4, 2024 19:58
@mulkieran
Copy link
Member Author

If it passes, it should be good.

.filter(|(_, a)| a.path().is_ident("pool_mutating_action"))
.map(|(i, a)| {
if let Meta::List(MetaList { ref tokens, .. }) = a.meta {
if let TokenTree::Literal(litstr) = tokens.clone().into_iter().next().expect("stratisd code always supplies string literal argument to pool_mutating_actions") {
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be further destructured using this enum. It will allow you to avoid converting to a String and then trimming the quotation marks, instead just getting the String value.

Copy link
Member Author

Choose a reason for hiding this comment

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

litstr type is TokenTree::Literal, which is a struct with private fields and a rather awkward set of methods in syn2. I think that syn2 probably expects that the normal way to encode that argument value is without the '"' in the first place, as a plain Ident, but I don't want to hit every spot where the pool_mutating_action annotation is used to change that, so I left it alone.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. I think changing this to use an ident would be better after looking at the types. Would you be willing to do that? I think it would generally be better from the standpoint of upgrading to the new API. I'll also look into the recommended way of doing this because I have some other crates I maintain that need updates.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would, but I'ld like to postpone that until we start the next release. I'll file an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Okay sounds good!

stratisd_proc_macros/src/lib.rs Outdated Show resolved Hide resolved
@mulkieran
Copy link
Member Author

@jbaublitz Ok, it is ready again.

@jbaublitz jbaublitz self-requested a review September 9, 2024 21:54
Copy link
Member

@jbaublitz jbaublitz 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 retracting my approval just to suggest one more possible avenue. Does parse_nested_meta do what we want here? Maybe not. I'll look into it more when I get back, but it looks promising.

@mulkieran
Copy link
Member Author

@jbaublitz The last commit tightens it up a bit. It can be tightened up even further by specifying parse_args with Ident type, but that requires changing all the uses every where to actually be Idents, not strings.

@jbaublitz
Copy link
Member

Would you mind holding this until I get back? I want to investigate further.

@mulkieran
Copy link
Member Author

@jbaublitz Yeah, that's fine.

@jbaublitz
Copy link
Member

jbaublitz commented Sep 17, 2024

@mulkieran I found a better way to do it:

            if let Ok(level) = a.parse_args::<LitStr>() {
                let err_str = level.value();
                (i, level.parse::<Ident>().expect(format!("Could not parse value {err_str} for rejection level as an Ident").as_str()))
            } else {
                panic!("pool_mutating_action attribute must be in form #[pool_mutating_action(\"REJECTION LEVEL\")]")
            }

This requires no changes to the way we currently provide the rejection level.

Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/stratis-storage-stratisd-3682
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@mulkieran
Copy link
Member Author

@mulkieran I found a better way to do it:

            if let Ok(level) = a.parse_args::<LitStr>() {
                let err_str = level.value();
                (i, level.parse::<Ident>().expect(format!("Could not parse value {err_str} for rejection level as an Ident").as_str()))
            } else {
                panic!("pool_mutating_action attribute must be in form #[pool_mutating_action(\"REJECTION LEVEL\")]")
            }

This requires no changes to the way we currently provide the rejection level.

Yeah. That's a better way to parse. But the expect is still rejected, so I'll stick with panic.

@jbaublitz
Copy link
Member

What's rejecting it?

@mulkieran
Copy link
Member Author

mulkieran commented Sep 17, 2024

It's a correct clippy lint: https://rust-lang.github.io/rust-clippy/master/index.html#/expect_fun_call . With an expect, the error message is eagerly evaluated. With the panic, it is not.

Panic always if no argument for pool_mutating_actions.
Panic if more than one of the designated attribute found.

Signed-off-by: mulhern <amulhern@redhat.com>
@mulkieran
Copy link
Member Author

squashed.

@mulkieran mulkieran merged commit fa60d1f into stratis-storage:master Sep 18, 2024
50 checks passed
@mulkieran mulkieran deleted the syn-2.0 branch September 18, 2024 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update to syn 2 in stratisd-proc-macros
2 participants